Skip to content

Conversation

@youknowone
Copy link
Member

@youknowone youknowone commented Dec 20, 2025

Summary by CodeRabbit

  • New Features
    • Virtual environment configuration detection added for improved executable path resolution
    • Environment variable support for cross-platform executable path configuration

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 20, 2025

Walkthrough

The change adds virtual environment detection support to the _base_executable function by introducing __PYVENV_LAUNCHER__ environment variable checking and a new private function get_venv_base_executable() that detects the base executable by parsing pyvenv.cfg files with platform-specific path resolution.

Changes

Cohort / File(s) Summary
Virtual Environment Support
crates/vm/src/stdlib/sys.rs
Added get_venv_base_executable() private function to detect base executable from pyvenv.cfg; modified _base_executable() to check __PYVENV_LAUNCHER__ environment variable and fallback to venv detection with cross-platform path handling for wasm32 and non-wasm32 targets.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Logic for reading and parsing pyvenv.cfg configuration files requires careful validation
  • Platform-specific path handling across wasm32 and non-wasm32 targets should be tested
  • Edge cases for __PYVENV_LAUNCHER__ environment variable precedence and fallback paths warrant attention

Poem

🐰 A venv within a venv, how quite the treat,
Environment variables make it complete,
Config files parsed with rabbit-like care,
Base executables found everywhere! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Upgrade venv to v3.13.11' is too vague and doesn't accurately describe the actual changes made to the codebase. The PR modifies sys.rs to add venv base executable detection via pyvenv.cfg parsing and PYVENV_LAUNCHER handling. Consider a more specific title like 'Add venv base executable detection from pyvenv.cfg' to better reflect the technical changes.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

❤️ Share

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

@youknowone youknowone marked this pull request as ready for review December 20, 2025 03:15
@youknowone youknowone merged commit 46c61a6 into RustPython:main Dec 20, 2025
12 of 13 checks passed
@youknowone youknowone deleted the venv branch December 20, 2025 03:17
Copy link
Contributor

@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: 0

🧹 Nitpick comments (1)
crates/vm/src/stdlib/sys.rs (1)

212-214: Consider edge case: config lines with empty values.

The parsing uses split_once('=') which correctly handles the first =, but doesn't validate that the value after trimming is non-empty. While this might work fine (an empty home path would fail later checks), explicitly handling this edge case would make the code more robust.

🔎 Suggested enhancement for edge case handling
 for line in content.lines() {
     if let Some((key, value)) = line.split_once('=') {
         let key = key.trim().to_lowercase();
         let value = value.trim();
+        
+        if value.is_empty() {
+            continue;
+        }
 
         if key == "home" {
📜 Review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ab1105a and 6a34c90.

⛔ Files ignored due to path filters (8)
  • Lib/test/test_venv.py is excluded by !Lib/**
  • Lib/venv/__init__.py is excluded by !Lib/**
  • Lib/venv/__main__.py is excluded by !Lib/**
  • Lib/venv/scripts/common/Activate.ps1 is excluded by !Lib/**
  • Lib/venv/scripts/common/activate is excluded by !Lib/**
  • Lib/venv/scripts/common/activate.fish is excluded by !Lib/**
  • Lib/venv/scripts/nt/activate.bat is excluded by !Lib/**
  • Lib/venv/scripts/posix/activate.csh is excluded by !Lib/**
📒 Files selected for processing (1)
  • crates/vm/src/stdlib/sys.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.rs: Follow the default rustfmt code style by running cargo fmt to format Rust code
Always run clippy to lint Rust code (cargo clippy) before completing tasks and fix any warnings or lints introduced by changes
Follow Rust best practices for error handling and memory management
Use the macro system (pyclass, pymodule, pyfunction, etc.) when implementing Python functionality in Rust

Files:

  • crates/vm/src/stdlib/sys.rs
🔇 Additional comments (3)
crates/vm/src/stdlib/sys.rs (3)

167-178: LGTM! Clear priority order for executable detection.

The logic correctly prioritizes __PYVENV_LAUNCHER__ environment variable first, then venv detection via config file, and finally falls back to the existing executable detection. This is a sensible implementation.


189-189: No action required—which::which() API usage is correct and compatible with which crate v8.0.0.


218-222: Verify symlink resolution logic against Python's getpath.py implementation.

The current code resolves symlinks independently and returns immediately if a different path is found, using the parsed home directory value only as a fallback if symlink resolution doesn't produce a different path. This means the home value parsed from pyvenv.cfg is potentially ignored when symlink resolution succeeds.

Clarify whether this matches Python's getpath.py behavior (lines 373-377 and 381):

  1. If Python's getpath.py also returns the resolved symlink path without applying the home value, the current logic is correct.
  2. If Python applies the home directory value regardless of symlink resolution, this is a logic error that should use the home value instead.

@coderabbitai coderabbitai bot mentioned this pull request Dec 25, 2025
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.

1 participant