Warn, but don't error, when encountering tilde .dist-info directories (#5520)

## Summary

Closes https://github.com/astral-sh/uv/issues/3668.
This commit is contained in:
Charlie Marsh 2024-07-28 15:13:06 -04:00 committed by GitHub
parent b0c841ee3b
commit 83412837e5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 24 additions and 6 deletions

View file

@ -3,11 +3,11 @@ use std::path::{Path, PathBuf};
use std::str::FromStr;
use anyhow::{anyhow, Context, Result};
use distribution_filename::EggInfoFilename;
use fs_err as fs;
use tracing::warn;
use url::Url;
use distribution_filename::EggInfoFilename;
use pep440_rs::Version;
use pypi_types::DirectUrl;
use uv_fs::Simplified;

View file

@ -12,9 +12,11 @@ use distribution_types::{
};
use pep440_rs::{Version, VersionSpecifiers};
use pypi_types::{Requirement, VerbatimParsedUrl};
use uv_fs::Simplified;
use uv_normalize::PackageName;
use uv_python::{Interpreter, PythonEnvironment};
use uv_types::InstalledPackagesProvider;
use uv_warnings::warn_user;
use crate::satisfies::RequirementSatisfaction;
@ -82,10 +84,26 @@ impl SitePackages {
// Index all installed packages by name.
for path in site_packages {
let Some(dist_info) = InstalledDist::try_from_path(&path)
.with_context(|| format!("Failed to read metadata: from {}", path.display()))?
else {
continue;
let dist_info = match InstalledDist::try_from_path(&path) {
Ok(Some(dist_info)) => dist_info,
Ok(None) => continue,
Err(_)
if path.file_name().is_some_and(|name| {
name.to_str().is_some_and(|name| name.starts_with('~'))
}) =>
{
warn_user!(
"Ignoring dangling temporary directory: `{}`",
path.simplified_display().cyan()
);
continue;
}
Err(err) => {
return Err(err).context(format!(
"Failed to read metadata from: `{}`",
path.simplified_display()
));
}
};
let idx = distributions.len();

View file

@ -531,7 +531,7 @@ Version: 0.1-bulbasaur
----- stdout -----
----- stderr -----
error: Failed to read metadata: from [SITE_PACKAGES]/paramiko.egg-link
error: Failed to read metadata from: `[SITE_PACKAGES]/paramiko.egg-link`
Caused by: after parsing '0.1-b', found 'ulbasaur', which is not part of a valid version
"###
);