venvlauncher by youknowone · Pull Request #6527 · RustPython/RustPython
📝 Walkthrough
Walkthrough
Adds a new Windows-focused Rust venv launcher crate that discovers a virtualenv via pyvenv.cfg, selects python/pythonw, sets PYVENV_LAUNCHER, re-execs Python, and updates VM path resolution to be launcher-aware preserving the real base executable.
Changes
| Cohort / File(s) | Summary |
|---|---|
Spell Check Dictionary .cspell.dict/cpython.txt |
Added tokens: pythonw, venvlauncher, venvlaunchert, venvw, venvwlauncher, venvwlaunchert. |
Venvlauncher Manifest crates/venvlauncher/Cargo.toml |
New Cargo manifest with package metadata, four binary targets (venvlauncher, venvwlauncher, venvlaunchert, venvwlaunchert), Windows-specific dependency features, and workspace lint settings. |
Venvlauncher Build Script crates/venvlauncher/build.rs |
New build script that detects venvw-named binaries and adds linker args to set the Windows GUI subsystem and mainCRTStartup entry point to suppress console windows. |
Venvlauncher Implementation crates/venvlauncher/src/main.rs |
New Windows-only launcher: derives target exe from its name, locates pyvenv.cfg (walks from Scripts/), parses home= (handles spaces/comments), validates Python executable under discovered home, sets __PYVENV_LAUNCHER__, and execs Python with original args; includes Windows-gated tests for read_home. |
VM Path Resolution crates/vm/src/getpath.rs |
Launcher-aware path logic: introduces real_executable, sets paths.executable to the launcher when __PYVENV_LAUNCHER__ is present, preserves base_executable as the real Python, and computes exe_dir from the launcher parent; subsequent venv/prefix calculations unchanged. |
CI Workflow .github/workflows/ci.yaml |
Centralized workspace exclusion flags via WORKSPACE_EXCLUDES and replaced duplicated per-command excludes with the env variable. |
Sequence Diagram
sequenceDiagram
autonumber
actor User
participant Launcher as venvlauncher (exe)
participant VenvCfg as pyvenv.cfg
participant Python as python.exe / pythonw.exe
participant VM as RustPython VM
User->>Launcher: start with args
Launcher->>Launcher: inspect exe name -> choose target (pythonw/python)
Launcher->>VenvCfg: locate pyvenv.cfg (walk from Scripts/)
VenvCfg-->>Launcher: return home path (home=...)
Launcher->>Launcher: validate Python exists under home
Launcher->>Launcher: set __PYVENV_LAUNCHER__ env
Launcher->>Python: exec target Python with original args
Python->>VM: VM startup reads __PYVENV_LAUNCHER__
Note over VM: VM sets sys.executable=launcher\nand sys._base_executable=real python
VM-->>User: exit code propagated
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related PRs
- Upgrade venv to v3.13.11 #6459: Related launcher-aware venv handling and PYVENV_LAUNCHER integration in the runtime.
Suggested reviewers
- coolreader18
Poem
🐰 I hop from Scripts to cfg-lined den,
I sniff the home and find the den again.
I set the mark, then nudge Python on,
Silent windows, a quiet dawn.
Hoppity launch — rust and carrot song! 🥕
Pre-merge checks and finishing touches
❌ Failed checks (1 inconclusive)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Title check | ❓ Inconclusive | The title 'venvlauncher' is too generic and vague; it only names a component without conveying what changes or improvements are being made. | Provide a more descriptive title that explains the main change, such as 'Implement Windows venv launcher with pyvenv.cfg parsing' or 'Add venvlauncher binary targets and launcher-aware path detection'. |
✅ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
✨ Finishing touches
- 📝 Generate docstrings
🧪 Generate unit tests (beta)
- Create PR with unit tests
- Post copyable unit tests in a comment
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.
Comment @coderabbitai help to get the list of available commands and usage tips.