Search in both purelib and platlib for site-packages population (#2537)

## Summary

In reality, there's no such thing as the `site-packages` directory for a
given virtualenv. Rather, Python defines both `purelib` and `platlib`,
where the former is for pure-Python packages and the latter is for
packages that contain native code. These are almost always set to the
same thing... but they don't _have_ to be, and in fact of Fedora they
are not.

This PR changes the `site_packages` method to return an iterator of
directories.

Closes https://github.com/astral-sh/uv/issues/2527.
This commit is contained in:
Charlie Marsh
2024-03-18 20:06:16 -07:00
committed by GitHub
parent 142b2de191
commit ba14f69676
4 changed files with 67 additions and 51 deletions
@@ -88,9 +88,18 @@ impl PythonEnvironment {
self.interpreter.sys_executable()
}
/// Returns the path to the `site-packages` directory inside a virtual environment.
pub fn site_packages(&self) -> &Path {
self.interpreter.purelib()
/// Returns an iterator over the `site-packages` directories inside a virtual environment.
///
/// In most cases, `purelib` and `platlib` will be the same, and so the iterator will contain
/// a single element; however, in some distributions, they may be different.
pub fn site_packages(&self) -> impl Iterator<Item = &Path> {
std::iter::once(self.interpreter.purelib()).chain(
if self.interpreter.purelib() == self.interpreter.platlib() {
None
} else {
Some(self.interpreter.platlib())
},
)
}
/// Returns the path to the `bin` directory inside a virtual environment.