Skip to content

fix(scripts): restore missing scripts/env/select_venv.py (#41)#50

Open
Uptrend-john wants to merge 1 commit into
sgeraldes:mainfrom
Uptrend-john:fix/missing-select-venv
Open

fix(scripts): restore missing scripts/env/select_venv.py (#41)#50
Uptrend-john wants to merge 1 commit into
sgeraldes:mainfrom
Uptrend-john:fix/missing-select-venv

Conversation

@Uptrend-john
Copy link
Copy Markdown

@Uptrend-john Uptrend-john commented May 28, 2026

Summary

  • Restores the missing scripts/env/select_venv.py referenced by setup-windows.bat and setup-unix.sh. Without it, fresh-clone setup fails in step 2/4 with No such file or directory and cannot create the venv. Fixes macOS setup: missing scripts/env/select_venv.py and toast notification crash on Python 3.13 #41.
  • Adds a !scripts/env/ negation to .gitignore so the new source directory is not masked by the existing ENV/ venv-ignore pattern on case-insensitive filesystems (Windows, default macOS).

Behavior

Contract inferred from how setup-windows.bat calls the script:

  • --print — resolve the platform-appropriate venv path (.venv.win / .venv.mac / .venv.nix at repo root) and print it if it exists.
  • --ensure — create the venv at that path if missing.
  • --ensure --print — do both.

Implementation uses the stdlib venv module (with_pip=True), no third-party deps. Symlinks are enabled on non-Windows platforms.

Test plan

  • On a fresh Windows clone with Python 3.12: py -3.12 scripts\env\select_venv.py --ensure --print creates .venv.win and prints its absolute path.
  • Re-running with --print only (after creation) prints the path without recreating.
  • setup-windows.bat's desktop-app install path (pip install -e "apps/desktop[dev]") completes successfully into that venv.
  • macOS / Linux smoke test from a maintainer with setup-unix.sh (path logic is symmetric but I haven't run it).

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Chores
    • Updated version control exclusions to ignore environment configuration files.
    • Added automated virtual environment management to support cross-platform development setup with platform-specific Python configurations.

Review Change Stack

setup-windows.bat and setup-unix.sh both invoke
scripts/env/select_venv.py to resolve the per-platform venv path,
but the file was missing from the repo. Setup failed in step 2/4
with "No such file or directory" and could not create the venv.

The script's intended contract (inferred from how the setup
scripts call it):
- --print resolves the platform-appropriate venv path
  (.venv.win / .venv.mac / .venv.nix at repo root) and prints
  it if it exists.
- --ensure creates the venv at that path if missing.
- --ensure --print does both.

Also adds a !scripts/env/ negation to .gitignore so the source
directory is not masked by the broader ENV/ venv-ignore rule on
case-insensitive filesystems (Windows, default macOS).
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

📝 Walkthrough

Walkthrough

This pull request adds a cross-platform virtual environment selection script (scripts/env/select_venv.py) and updates the gitignore to allow the script directory to be tracked. The script detects the platform, resolves the repository root, computes platform-specific venv paths, and supports optional venv creation with --ensure and path output with --print CLI flags.

Changes

Virtual Environment Platform Management

Layer / File(s) Summary
Venv selection and platform management
scripts/env/select_venv.py, .gitignore
Script detects sys.platform, resolves repo root from script location, computes platform-specific venv directories and Python executable paths (Scripts/python.exe on Windows; bin/python elsewhere), and implements three CLI behaviors: --print outputs existing venv path, --ensure creates venv with pip if missing, and --ensure --print creates if missing then outputs path. Venv creation failures are reported to stderr with exit code 1; success exits 0. Gitignore updated to allow scripts/env/ to be tracked.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A script hops across platforms with care,
Windows, macOS, Linux—it's there!
Venv paths computed with clever precision,
Setup now smooth, with no more collision,
The rabbit says "build it once, venv anywhere!" ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: restoring the missing scripts/env/select_venv.py file and references the linked issue #41.
Description check ✅ Passed The PR description comprehensively covers the changes made, behavior implemented, test status, and reasoning. It aligns well with the provided template's key sections despite not following the exact checklist format.
Linked Issues check ✅ Passed The PR successfully addresses the primary objective of restoring scripts/env/select_venv.py to fix setup failures. The .gitignore negation prevents masking on case-insensitive filesystems. The toast notification crash (secondary objective) is not addressed, but is marked as a separate pending task.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing issue #41: restoring the missing select_venv.py script and updating .gitignore to prevent directory masking. No extraneous changes detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with 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.

Inline comments:
In `@scripts/env/select_venv.py`:
- Around line 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().
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f819abd4-5737-41ef-abf5-77eafa7a1fe3

📥 Commits

Reviewing files that changed from the base of the PR and between 89cb03a and a02999b.

📒 Files selected for processing (2)
  • .gitignore
  • scripts/env/select_venv.py

Comment on lines +20 to +33
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()
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().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macOS setup: missing scripts/env/select_venv.py and toast notification crash on Python 3.13

1 participant