Skip to content

The agent that grows with you

fix(update): resolve the project venv as venv or .venv

Brooklyn Nicholson7a94b1fbf771
diff --git a/hermes_cli/_install_repair.py b/hermes_cli/_install_repair.py
index 9a4953bfc79..76e78adb985 100644
--- a/hermes_cli/_install_repair.py
+++ b/hermes_cli/_install_repair.py
@@ -92,7 +92,9 @@ def _resolve_install_target(root: Path) -> tuple[list[str], dict | None]:
"""
uv_bin = _er._find_uv_binary()
if uv_bin:
- env = {**os.environ, "VIRTUAL_ENV": str(root / "venv")}
+ from hermes_constants import project_venv_dir
+
+ env = {**os.environ, "VIRTUAL_ENV": str(project_venv_dir(root) or root / "venv")}
if _is_termux_env(env):
env.pop("PYTHONPATH", None)
env.pop("PYTHONHOME", None)
@@ -102,13 +104,14 @@ def _resolve_install_target(root: Path) -> tuple[list[str], dict | None]:
def _venv_scripts_dir(root: Path) -> Path | None:
"""Project venv Scripts/bin dir, when present. stdlib-only."""
- venv_dir = root / "venv"
- if not venv_dir.is_dir():
- return None
- # hermes_constants is stdlib-only, so the canonical layout helper is safe
+ # hermes_constants is stdlib-only, so the canonical layout helpers are safe
# to use from this corrupted-venv repair path (#76105: never open-code
# the Scripts/bin split).
- from hermes_constants import venv_bin_dir
+ from hermes_constants import project_venv_dir, venv_bin_dir
+
+ venv_dir = project_venv_dir(root)
+ if venv_dir is None:
+ return None
scripts = venv_bin_dir(venv_dir, windows=_is_windows())
return scripts if scripts.is_dir() else None
diff --git a/hermes_cli/main.py b/hermes_cli/main.py
index 7432f1f018c..cb456a03859 100644
--- a/hermes_cli/main.py
+++ b/hermes_cli/main.py
@@ -8785,7 +8785,10 @@ def _default_venv_install_target() -> tuple[list[str], dict[str, str] | None]:
except Exception:
uv_bin = None
if uv_bin:
- env = {**os.environ, "VIRTUAL_ENV": str(PROJECT_ROOT / "venv")}
+ from hermes_constants import project_venv_dir
+
+ venv_dir = project_venv_dir(PROJECT_ROOT) or PROJECT_ROOT / "venv"
+ env = {**os.environ, "VIRTUAL_ENV": str(venv_dir)}
if _is_termux_env(env):
env.pop("PYTHONPATH", None)
env.pop("PYTHONHOME", None)
@@ -8838,10 +8841,11 @@ def _is_windows() -> bool:
def _venv_scripts_dir() -> Path | None:
"""Return the venv Scripts directory if we're running inside the project venv."""
- venv_dir = PROJECT_ROOT / "venv"
- if not venv_dir.is_dir():
+ from hermes_constants import project_venv_dir, venv_bin_dir
+
+ venv_dir = project_venv_dir(PROJECT_ROOT)
+ if venv_dir is None:
return None
- from hermes_constants import venv_bin_dir
scripts = venv_bin_dir(venv_dir, windows=_is_windows())
return scripts if scripts.is_dir() else None
diff --git a/hermes_constants.py b/hermes_constants.py
index 13602e20d6d..e7af1883970 100644
--- a/hermes_constants.py
+++ b/hermes_constants.py
@@ -1610,6 +1610,22 @@ def venv_bin_dir(venv_dir, *, windows: bool | None = None) -> Path:
return Path(venv_dir) / ("Scripts" if windows else "bin")
+def project_venv_dir(project_root) -> Path | None:
+ """The project's venv directory, ``venv`` or ``.venv``, when one exists.
+
+ ``uv venv`` defaults to ``.venv`` while our installers create ``venv``, so
+ both layouts are in the wild. Call sites that only knew about ``venv``
+ silently no-oped on a ``.venv`` install — that is how the Windows
+ shim-lock preflight skipped itself entirely (#79542). ``venv`` wins when
+ both exist, matching what the installers write.
+ """
+ for name in ("venv", ".venv"):
+ candidate = Path(project_root) / name
+ if candidate.is_dir():
+ return candidate
+ return None
+
+
def venv_python_path(venv_dir, *, windows: bool | None = None) -> Path:
"""Path to the Python interpreter inside *venv_dir* (may not exist)."""
if windows is None: