[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.
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.
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.
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.cfgfile 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-packagesdirectories that we'd need to consider as search paths -- currently we only contemplate the0or1possibilities. As such, it makes sense for thesite_packagesfield onProgramto be aVecrather 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-packagesdirectories onsys.pathat runtime, any editable installs provided via.pthfiles in the firstsite-packagesdirectory will take precedence over the secondsite-packagesdirectory when it comes to module resolution.Test plan
cargo test