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
2 changes: 1 addition & 1 deletion trobz_deploy/command/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def configure( # noqa: C901
click.secho(f"\nSetting up {eff_type} environment…", fg="green")
try:
if eff_type == "odoo":
setup_odoo_venv(executor, instance_path)
setup_odoo_venv(executor, instance_path, force=force)
elif eff_type == "python":
if eff_requirements:
setup_package_venv(executor, instance_path, eff_requirements, force=force)
Expand Down
29 changes: 23 additions & 6 deletions trobz_deploy/utils/venv.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
from __future__ import annotations

from trobz_deploy.utils.executor import Executor
import click

from trobz_deploy.utils.executor import Executor, ExecutorError

def setup_odoo_venv(executor: Executor, instance_path: str) -> None:

def _venv_exists(executor: Executor, instance_path: str) -> bool:
try:
executor.run(f"test -d {instance_path}/.venv")
except ExecutorError:
return False
return True


def setup_odoo_venv(executor: Executor, instance_path: str, force: bool = False) -> None:
"""Create or update an Odoo virtual environment using ``odoo-venv``."""
if force and _venv_exists(executor, instance_path):
click.secho("Venv exists, skipping venv creation (--force).", fg="yellow")
return
executor.run(
f"odoo-venv create --project-dir {instance_path} --preset project",
cwd=instance_path,
Expand All @@ -13,8 +26,10 @@ def setup_odoo_venv(executor: Executor, instance_path: str) -> None:

def setup_python_venv(executor: Executor, instance_path: str, force: bool = False) -> None:
"""Create a venv with ``uv`` and install dependencies from requirements.txt."""
clear_flag = " --clear" if force else ""
executor.run(f"uv venv{clear_flag} .venv", cwd=instance_path)
if force and _venv_exists(executor, instance_path):
click.secho("Venv exists, skipping venv creation (--force).", fg="yellow")
else:
executor.run("uv venv .venv", cwd=instance_path)
setup_python_deps(executor, instance_path)


Expand All @@ -25,8 +40,10 @@ def setup_python_deps(executor: Executor, instance_path: str) -> None:

def setup_package_venv(executor: Executor, instance_path: str, requirements: list[str], force: bool = False) -> None:
"""Create a venv with ``uv`` and install pip packages directly."""
clear_flag = " --clear" if force else ""
executor.run(f"uv venv{clear_flag} .venv", cwd=instance_path)
if force and _venv_exists(executor, instance_path):
click.secho("Venv exists, skipping venv creation (--force).", fg="yellow")
else:
executor.run("uv venv .venv", cwd=instance_path)
executor.run(f"uv pip install {' '.join(requirements)}", cwd=instance_path)


Expand Down