-
-
Notifications
You must be signed in to change notification settings - Fork 26
fix(scripts): restore missing scripts/env/select_venv.py (#41) #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Uptrend-john
wants to merge
1
commit into
sgeraldes:main
Choose a base branch
from
Uptrend-john:fix/missing-select-venv
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() | ||
|
|
||
|
|
||
| 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()) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add WSL + legacy
.venvfallback to match documented selector behavior.venv_dir_name()currently routes all non-Windows/non-macOS platforms to.venv.nix. The documented contract indocs/development/VENV.mdexpects WSL detection and a legacy.venvfallback, so this can select the wrong env for WSL users and ignore existing legacy environments.Suggested patch
🤖 Prompt for AI Agents