Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ jobs:
- name: Smoke-test Odoo launcher
run: |
version="${{ matrix.odoo_version }}"
major="${version%%.*}"
if [[ "$version" == "master" ]]; then
# master tracks a moving target (e.g. 19.3); read the real major from release.py
major=$(python3 -c "exec(open('$HOME/code/odoo/odoo/master/odoo/release.py').read()); print(version_info[0])")
else
major="${version%%.*}"
fi
odoo-v${major} --workers=2 --stop-after-init

test-oca:
Expand Down Expand Up @@ -245,7 +250,7 @@ jobs:

- name: Create Odoo virtual environment
run: |
addons_path=$(odoo-addons-path --addons-dir "~/code/oca/${{ matrix.odoo_version }}/*")
addons_path=$(odoo-addons-path ~/code/odoo/odoo/${{ matrix.odoo_version }} --addons-dir "~/code/oca/${{ matrix.odoo_version }}/*")
odoo-venv create --verbose ${{ matrix.odoo_version }} \
--preset ci \
--odoo-dir ~/code/odoo/odoo/${{ matrix.odoo_version }} \
Expand Down
7 changes: 5 additions & 2 deletions odoo_venv/assets/launcher.sh.template
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Usage:
# 1. Edit variables below (e.g., DATABASE="mydb", DEV_MODE="all")
# 2. Run: odoo-v{version}
# 3. Script activates venv and builds command: odoo -d mydb --dev all
# 3. Script activates venv and builds command: python $VENV_DIR/bin/odoo -d mydb --dev all

set -uo pipefail

Expand Down Expand Up @@ -79,7 +79,10 @@ add_arg() { [[ -n "$$2" ]] && CMD+=("$$1" "$$2"); }
add_flag() { [[ "$$2" == "true" ]] && CMD+=("$$1"); }

build_command() {
CMD=("odoo")
# Use 'python bin/odoo' instead of 'bin/odoo' directly to bypass broken shebang.
# uv pip install -e writes a temporary build path as the shebang in bin/odoo,
# which breaks after installation. Running it through python ignores the shebang.
CMD=("python" "$$VENV_DIR/bin/odoo")

# Database
add_arg "-d" "$$DATABASE"
Expand Down
10 changes: 7 additions & 3 deletions odoo_venv/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def create(
)

if create_launcher_flag:
create_launcher(odoo_version, venv_dir_path, force=True)
create_launcher(odoo_version, venv_dir_path, odoo_dir=odoo_dir_path, force=True)


def _is_uv_venv(venv_dir: Path) -> bool:
Expand Down Expand Up @@ -705,10 +705,14 @@ def compare(

@app.command()
def create_odoo_launcher(
odoo_version: Annotated[str, typer.Argument(help="Odoo version, e.g: 19.0")],
odoo_version: Annotated[str, typer.Argument(help="Odoo version, e.g: 19.0 or master")],
venv_dir: Annotated[str, typer.Option(help="Path to the virtual environment.")],
odoo_dir: Annotated[
str | None, typer.Option(help="Path to Odoo source (required for non-numeric versions like 'master').")
] = None,
force: Annotated[bool, typer.Option(help="Overwrite existing launcher script.")] = False,
):
"""Generate a launcher script in ~/.local/bin/ for the Odoo environment"""
venv_dir_path = Path(venv_dir).expanduser().resolve()
create_launcher(odoo_version, venv_dir_path, force=force)
odoo_dir_path = Path(odoo_dir).expanduser().resolve() if odoo_dir else None
create_launcher(odoo_version, venv_dir_path, odoo_dir=odoo_dir_path, force=force)
36 changes: 32 additions & 4 deletions odoo_venv/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,47 @@
from string import Template

import typer
from odoo_addons_path import get_odoo_version

LAUNCHER_DIR = Path("~/.local/bin").expanduser()
TEMPLATE_PATH = Path(__file__).parent / "assets" / "launcher.sh.template"


def create_launcher(odoo_version: str, venv_dir: str | Path, force: bool = False) -> Path:
def _resolve_major_version(odoo_version: str, odoo_dir: Path | None) -> str:
"""Resolve the major version number from the Odoo version string.

When odoo_version is non-numeric (e.g. "master"), detect the real
version from the Odoo source via ``get_odoo_version``.
"""
major = odoo_version.split(".")[0]
if major.isdigit():
return major

# Non-numeric branch name (e.g. "master") — detect from source
if odoo_dir is not None:
detected = get_odoo_version(addons_path="", odoo_dir=odoo_dir)
if detected:
return detected.split(".")[0]

typer.secho(
f"Cannot determine major version from '{odoo_version}'. "
"Pass --odoo-dir so the version can be read from odoo/release.py.",
fg=typer.colors.RED,
err=True,
)
sys.exit(1)


def create_launcher(
odoo_version: str, venv_dir: str | Path, *, odoo_dir: Path | None = None, force: bool = False
) -> Path:
"""
Generate a bash launcher script that auto-activates the venv and runs Odoo.

Args:
odoo_version: Odoo version string (e.g., "19.0")
odoo_version: Odoo version string (e.g., "19.0" or "master")
venv_dir: Path to the virtual environment
odoo_dir: Path to Odoo source (needed to resolve non-numeric versions like "master")
force: Overwrite existing launcher if True

Returns:
Expand All @@ -26,8 +55,7 @@ def create_launcher(odoo_version: str, venv_dir: str | Path, force: bool = False
Raises:
SystemExit: If file exists and force=False, or on write errors
"""
# Extract major version for script name
major_version = odoo_version.split(".")[0]
major_version = _resolve_major_version(odoo_version, odoo_dir)
script_name = f"odoo-v{major_version}"
output_path = LAUNCHER_DIR / script_name

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies = [
"typing_extensions",
"tomli",
"packaging>=25.0",
"odoo-addons-path>=1.1.0",
"odoo-addons-path>=1.2.0",
]

[dependency-groups]
Expand Down
10 changes: 5 additions & 5 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading