Skip to content
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

Avoid reading stale .egg-info from mutable sources #6714

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions crates/distribution-types/src/buildable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ impl BuildableSource<'_> {
Self::Url(url) => url.is_editable(),
}
}

/// Return true if the source refers to a local source tree (i.e., a directory).
pub fn is_source_tree(&self) -> bool {
match self {
Self::Dist(dist) => matches!(dist, SourceDist::Directory(_)),
Self::Url(url) => matches!(url, SourceUrl::Directory(_)),
}
}
}

impl std::fmt::Display for BuildableSource<'_> {
Expand Down Expand Up @@ -94,6 +102,11 @@ impl<'a> SourceUrl<'a> {
Self::Directory(DirectorySourceUrl { editable: true, .. })
)
}

/// Return true if the source refers to a local file or directory.
pub fn is_local(&self) -> bool {
matches!(self, Self::Path(_) | Self::Directory(_))
}
}

impl std::fmt::Display for SourceUrl<'_> {
Expand Down
6 changes: 6 additions & 0 deletions crates/uv-distribution/src/source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1529,6 +1529,12 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
Err(err) => return Err(err),
}

// If the source distribution is a source tree, avoid reading `PKG-INFO` or `egg-info`,
// since they could be out-of-date.
if source.is_source_tree() {
return Ok(None);
}

// Attempt to read static metadata from the `PKG-INFO` file.
match read_pkg_info(source_root, subdirectory).await {
Ok(metadata) => {
Expand Down
69 changes: 69 additions & 0 deletions crates/uv/tests/pip_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6386,3 +6386,72 @@ fn switch_platform() -> Result<()> {

Ok(())
}

/// See: <https:/astral-sh/uv/pull/6714>
#[test]
fn stale_egg_info() -> Result<()> {
let context = TestContext::new("3.12");

// Create a project with dynamic metadata (version).
let pyproject_toml = context.temp_dir.child("pyproject.toml");
pyproject_toml.write_str(indoc! {r#"
[project]
name = "project"
dynamic = ["version"]

dependencies = ["iniconfig"]
"#
})?;

uv_snapshot!(context.filters(), context.pip_install()
.arg("-e")
.arg("."), @r###"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
Resolved 2 packages in [TIME]
Prepared 2 packages in [TIME]
Installed 2 packages in [TIME]
+ iniconfig==2.0.0
+ project==0.0.0 (from file://[TEMP_DIR]/)
"###
);

// Ensure that `.egg-info` exists.
let egg_info = context.temp_dir.child("project.egg-info");
egg_info.assert(predicates::path::is_dir());

// Change the metadata.
pyproject_toml.write_str(indoc! {r#"
[project]
name = "project"
dynamic = ["version"]

dependencies = ["anyio"]
"#
})?;

// Reinstall. Ensure that the metadata is updated.
uv_snapshot!(context.filters(), context.pip_install()
.arg("-e")
.arg("."), @r###"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
Resolved 4 packages in [TIME]
Prepared 4 packages in [TIME]
Uninstalled 1 package in [TIME]
Installed 4 packages in [TIME]
+ anyio==4.3.0
+ idna==3.6
~ project==0.0.0 (from file://[TEMP_DIR]/)
+ sniffio==1.3.1
"###
);

Ok(())
}
Loading