-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ty] Search PYTHONPATH to find modules #20441
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
Merged
Merged
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -277,14 +277,41 @@ impl Options { | |
| roots | ||
| }; | ||
|
|
||
| let settings = SearchPathSettings { | ||
| extra_paths: environment | ||
| // collect the existing site packages | ||
| let mut extra_paths: Vec<SystemPathBuf> = Vec::new(); | ||
|
|
||
| // read all the paths off the PYTHONPATH environment variable, check | ||
| // they exist as a directory, and add them to the vec of extra_paths | ||
| // as they should be checked before site-packages just like python | ||
| // interpreter does | ||
| if let Ok(python_path) = system.env_var("PYTHONPATH") { | ||
| for path in python_path.split(':') { | ||
| let possible_path = SystemPath::absolute(path, system.current_directory()); | ||
|
|
||
| if system.is_directory(&possible_path) { | ||
| tracing::debug!( | ||
| "Adding `{possible_path}` from the `PYTHONPATH` environment variable to `extra_paths`" | ||
| ); | ||
| extra_paths.push(possible_path); | ||
carljm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } else { | ||
| tracing::debug!( | ||
| "Skipping `{possible_path}` listed in `PYTHONPATH` because the path doesn't exist or isn't a directory" | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| extra_paths.extend( | ||
| environment | ||
| .extra_paths | ||
| .as_deref() | ||
| .unwrap_or_default() | ||
| .iter() | ||
| .map(|path| path.absolute(project_root, system)) | ||
| .collect(), | ||
| .map(|path| path.absolute(project_root, system)), | ||
| ); | ||
|
|
||
| let settings = SearchPathSettings { | ||
|
Member
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. @AlexWaygood any thoughts on whether we should move this logic into
Member
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. No strong opinion really! |
||
| extra_paths, | ||
| src_roots, | ||
| custom_typeshed: environment | ||
| .typeshed | ||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.