diff --git a/crates/uv-dispatch/src/lib.rs b/crates/uv-dispatch/src/lib.rs index 083a874161642..de6821ca157a9 100644 --- a/crates/uv-dispatch/src/lib.rs +++ b/crates/uv-dispatch/src/lib.rs @@ -182,8 +182,7 @@ impl<'a> BuildContext for BuildDispatch<'a> { let tags = self.interpreter.tags()?; // Determine the set of installed packages. - let site_packages = - SitePackages::from_executable(venv).context("Failed to list installed packages")?; + let site_packages = SitePackages::from_executable(venv)?; let Plan { local, diff --git a/crates/uv-installer/src/site_packages.rs b/crates/uv-installer/src/site_packages.rs index 9de913278bb00..ceb430e95e4b9 100644 --- a/crates/uv-installer/src/site_packages.rs +++ b/crates/uv-installer/src/site_packages.rs @@ -42,8 +42,22 @@ impl<'a> SitePackages<'a> { let mut by_name = FxHashMap::default(); let mut by_url = FxHashMap::default(); + // Read the site-packages directory. + let site_packages = match fs::read_dir(venv.site_packages()) { + Ok(site_packages) => site_packages, + Err(err) if err.kind() == std::io::ErrorKind::NotFound => { + return Ok(Self { + venv, + distributions, + by_name, + by_url, + }); + } + Err(err) => return Err(err).context("Failed to read site-packages directory"), + }; + // Index all installed packages by name. - for entry in fs::read_dir(venv.site_packages())? { + for entry in site_packages { let entry = entry?; if entry.file_type()?.is_dir() { let path = entry.path(); diff --git a/crates/uv/src/commands/pip_install.rs b/crates/uv/src/commands/pip_install.rs index 5e32509841312..f98442c0b76cc 100644 --- a/crates/uv/src/commands/pip_install.rs +++ b/crates/uv/src/commands/pip_install.rs @@ -143,8 +143,7 @@ pub(crate) async fn pip_install( let _lock = venv.lock()?; // Determine the set of installed packages. - let site_packages = - SitePackages::from_executable(&venv).context("Failed to list installed packages")?; + let site_packages = SitePackages::from_executable(&venv)?; // If the requirements are already satisfied, we're done. Ideally, the resolver would be fast // enough to let us remove this check. But right now, for large environments, it's an order of diff --git a/crates/uv/src/commands/pip_sync.rs b/crates/uv/src/commands/pip_sync.rs index abe755e39266f..f073f6478cbdd 100644 --- a/crates/uv/src/commands/pip_sync.rs +++ b/crates/uv/src/commands/pip_sync.rs @@ -157,8 +157,7 @@ pub(crate) async fn pip_sync( ); // Determine the set of installed packages. - let site_packages = - SitePackages::from_executable(&venv).context("Failed to list installed packages")?; + let site_packages = SitePackages::from_executable(&venv)?; // Resolve any editables. let resolved_editables = resolve_editables(