Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
.venv/
venv/
ENV/
!scripts/env/
apps/desktop/.venv/
apps/web/node_modules/
apps/audio-insights/node_modules/
Expand Down
72 changes: 72 additions & 0 deletions scripts/env/select_venv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env python3
"""
Resolve / create the per-platform virtual environment for hidock-next.
Restores the missing scripts/env/select_venv.py that setup-windows.bat and
setup-unix.sh expect (issue #41).

Contract:
--print Print the absolute venv path if it exists; otherwise no output.
--ensure Create the venv at the platform-appropriate path if missing.
--ensure --print Create (if missing) and print the absolute path.
"""

import argparse
import os
import sys
import venv
from pathlib import Path


def venv_dir_name() -> str:
if sys.platform.startswith("win"):
return ".venv.win"
if sys.platform == "darwin":
return ".venv.mac"
return ".venv.nix"


def repo_root() -> Path:
return Path(__file__).resolve().parent.parent.parent


def venv_path() -> Path:
return repo_root() / venv_dir_name()
Comment on lines +20 to +33
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add WSL + legacy .venv fallback to match documented selector behavior.

venv_dir_name() currently routes all non-Windows/non-macOS platforms to .venv.nix. The documented contract in docs/development/VENV.md expects WSL detection and a legacy .venv fallback, so this can select the wrong env for WSL users and ignore existing legacy environments.

Suggested patch
+import platform
 import argparse
 import os
 import sys
 import venv
 from pathlib import Path
@@
-def venv_dir_name() -> str:
+def venv_dir_name() -> str:
+    # Prefer legacy env when present
+    legacy = repo_root() / ".venv"
+    if legacy.exists():
+        return ".venv"
+
+    # WSL detection
+    if "microsoft" in platform.uname().release.lower():
+        return ".venv.wsl"
+
     if sys.platform.startswith("win"):
         return ".venv.win"
     if sys.platform == "darwin":
         return ".venv.mac"
     return ".venv.nix"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/env/select_venv.py` around lines 20 - 33, venv_dir_name() currently
maps non-win/non-mac to ".venv.nix" and misses WSL plus legacy ".venv" fallback;
update venv_dir_name() so it first detects WSL (e.g., sys.platform == "linux"
combined with presence of environment variable "WSL_DISTRO_NAME" or
"/proc/version" containing "microsoft"/"Microsoft") and return ".venv.wsl" for
WSL, then check for an existing legacy repo_root()/".venv" and return ".venv" if
that path exists, otherwise fall back to ".venv.nix"; keep repo_root() and
venv_path() usage intact so venv_path() uses the updated venv_dir_name().



def venv_python(path: Path) -> Path:
if sys.platform.startswith("win"):
return path / "Scripts" / "python.exe"
return path / "bin" / "python"


def ensure(path: Path) -> None:
if venv_python(path).exists():
return
path.mkdir(parents=True, exist_ok=True)
builder = venv.EnvBuilder(with_pip=True, clear=False, upgrade=False, symlinks=(os.name != "nt"))
builder.create(str(path))


def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("--ensure", action="store_true")
parser.add_argument("--print", dest="do_print", action="store_true")
args = parser.parse_args()

path = venv_path()

if args.ensure:
try:
ensure(path)
except Exception as exc:
print(f"ERROR: failed to create venv at {path}: {exc}", file=sys.stderr)
return 1

if args.do_print and venv_python(path).exists():
print(str(path))

return 0


if __name__ == "__main__":
raise SystemExit(main())