-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[red-knot] Allow multiple site-packages
search paths
#12609
Conversation
|
site-packages
search-path setting a vector of pathssite-packages
search paths; enable easier mocking in tests
7a4763c
to
ce7e9f7
Compare
site-packages
search paths; enable easier mocking in testssite-packages
search paths
Okay, I'll wait with reviewing then |
d18ad7b
to
30dff54
Compare
30dff54
to
be8e3ff
Compare
I added a test and updated the PR description. Ready for re-review! |
site_packages_dir, | ||
FileRootKind::LibrarySearchPath, | ||
); | ||
dynamic_paths |
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.
I do think that moving site packages constructing into the dynamic modules query will make it harder for validation but whatever. Let's ignore this for now
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.
Yeah, @carljm was wondering if all this lazy .pth
-file iteration was a bit too fancy -- we should maybe just collect all search paths eagerly. Definitely open to that; I have no idea how much lazy iteration through .pth
files actually saves us.
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.
I can't imagine lazy iteration of .pth
files saves us anything at all in any realistic scenario. It would require that there is a site-packages path, with editables installed into it, that the project never actually imports anything from; all imports are first-party. So yeah, I'd favor simplifying by just collecting all search paths eagerly.
be8e3ff
to
802a0c6
Compare
Summary
If a virtual environment's
pyvenv.cfg
file contains the lineinclude-system-site-packages = true
, anything installed in the system Python installation's site-packages directory will be accessible when the virtual environment is activated, as well as anything inside the virtual environment's site-packages directory. That means that we could have 0, 1, or manysite-packages
directories that we'd need to consider as search paths -- currently we only contemplate the0
or1
possibilities. As such, it makes sense for thesite_packages
field onProgram
to be aVec
rather than anOption
. This is the first commit of this PR.The second commit of the PR updates some of the logic in the resolver to reflect the fact that if there are two
site-packages
directories onsys.path
at runtime, any editable installs provided via.pth
files in the firstsite-packages
directory will take precedence over the secondsite-packages
directory when it comes to module resolution.Test plan
cargo test