-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Update --python to accept paths to executables in environments
#17954
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -247,6 +247,33 @@ impl SearchPaths { | |
| .and_then(|env| env.site_packages_directories(system))? | ||
| } | ||
|
|
||
| PythonPath::Resolve(target, origin) => { | ||
| tracing::debug!("Resolving {origin}: {target}"); | ||
|
|
||
| let root = system | ||
| // If given a file, assume it's a Python executable, e.g., `.venv/bin/python3`, | ||
| // and search for a virtual environment in the root directory. Ideally, we'd | ||
| // invoke the target to determine `sys.prefix` here, but that's more complicated | ||
| // and may be deferred to uv. | ||
| .is_file(target) | ||
| .then(|| target.as_path()) | ||
| .take_if(|target| { | ||
| // Avoid using the target if it doesn't look like a Python executable, e.g., | ||
| // to deny cases like `.venv/bin/foo` | ||
| target | ||
| .file_name() | ||
| .is_some_and(|name| name.starts_with("python")) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could be more strict here, and require |
||
| }) | ||
| .and_then(SystemPath::parent) | ||
| .and_then(SystemPath::parent) | ||
| // If not a file, use the path as given and allow let `PythonEnvironment::new` | ||
| // handle the error. | ||
| .unwrap_or(target); | ||
|
|
||
| PythonEnvironment::new(root, *origin, system) | ||
| .and_then(|venv| venv.site_packages_directories(system))? | ||
| } | ||
|
|
||
| PythonPath::Discover(root) => { | ||
| tracing::debug!("Discovering virtual environment in `{root}`"); | ||
| let virtual_env_path = discover_venv_in(db.system(), root); | ||
|
|
||
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.
Should we also test if the file has the executable bit set (
path_metadatainstead ofis_file)Uh oh!
There was an error while loading. Please reload this page.
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.
Seems reasonable, but is a little more painful cross-platform for little gain since we're just going to fail downstream anyway if we can't find site-packages
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.
Let me know if you think it's worth pursuing regardless.