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

Omit wheels from lockfile based on --exclude-newer #12299

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion crates/uv-bench/benches/uv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ mod resolver {
let concurrency = Concurrency::default();
let config_settings = ConfigSettings::default();
let exclude_newer = Some(
jiff::civil::date(2024, 8, 8)
jiff::civil::date(2024, 9, 1)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This depends on https://pypi.org/project/methodtools/0.4.7/#files, which added a wheel on August 23, 2024. So we can bump this to avoid building it from source.

.to_zoned(jiff::tz::TimeZone::UTC)
.unwrap()
.timestamp()
Expand Down
64 changes: 50 additions & 14 deletions crates/uv-distribution-types/src/prioritized_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ impl PrioritizedDist {
self.0.markers.or(implied_markers(&dist.filename));
}
}
// Track the hashes.
if !compatibility.is_excluded() {
self.0.hashes.extend(hashes);
}
// Track the highest-priority wheel.
if let Some((.., existing_compatibility)) = self.best_wheel() {
if compatibility.is_more_compatible(existing_compatibility) {
Expand All @@ -379,7 +383,6 @@ impl PrioritizedDist {
} else {
self.0.best_wheel_index = Some(self.0.wheels.len());
}
self.0.hashes.extend(hashes);
self.0.wheels.push((dist, compatibility));
}

Expand All @@ -394,6 +397,10 @@ impl PrioritizedDist {
if compatibility.is_compatible() {
self.0.markers = MarkerTree::TRUE;
}
// Track the hashes.
if !compatibility.is_excluded() {
self.0.hashes.extend(hashes);
}
// Track the highest-priority source.
if let Some((.., existing_compatibility)) = &self.0.source {
if compatibility.is_more_compatible(existing_compatibility) {
Expand All @@ -402,7 +409,6 @@ impl PrioritizedDist {
} else {
self.0.source = Some((dist, compatibility));
}
self.0.hashes.extend(hashes);
}

/// Return the highest-priority distribution for the package version, if any.
Expand Down Expand Up @@ -441,16 +447,19 @@ impl PrioritizedDist {
// wheel. We assume that all distributions have the same metadata for a given package
// version. If a compatible source distribution exists, we assume we can build it, but
// using the wheel is faster.
//
// (If the incompatible wheel should actually be ignored entirely, fall through to
// using the source distribution.)
(
Some((wheel, WheelCompatibility::Incompatible(_))),
Some((wheel, compatibility @ WheelCompatibility::Incompatible(_))),
Some((sdist, SourceDistCompatibility::Compatible(_))),
) => Some(CompatibleDist::IncompatibleWheel {
) if !compatibility.is_excluded() => Some(CompatibleDist::IncompatibleWheel {
sdist,
wheel,
prioritized: self,
}),
// Otherwise, if we have a source distribution, return it.
(None, Some((sdist, SourceDistCompatibility::Compatible(_)))) => {
(.., Some((sdist, SourceDistCompatibility::Compatible(_)))) => {
Some(CompatibleDist::SourceDist {
sdist,
prioritized: self,
Expand Down Expand Up @@ -497,24 +506,38 @@ impl PrioritizedDist {
/// a built distribution with the best wheel in this prioritized dist.
pub fn built_dist(&self) -> Option<RegistryBuiltDist> {
let best_wheel_index = self.0.best_wheel_index?;
let wheels = self
.0
.wheels
.iter()
.map(|(wheel, _)| wheel.clone())
.collect();

// Remove any excluded wheels from the list of wheels, and adjust the wheel index to be
// relative to the filtered list.
let mut adjusted_wheels = Vec::with_capacity(self.0.wheels.len());
let mut adjusted_best_index = 0;
for (i, (wheel, compatibility)) in self.0.wheels.iter().enumerate() {
if compatibility.is_excluded() {
continue;
}
if i == best_wheel_index {
adjusted_best_index = adjusted_wheels.len();
}
adjusted_wheels.push(wheel.clone());
}

let sdist = self.0.source.as_ref().map(|(sdist, _)| sdist.clone());
Some(RegistryBuiltDist {
wheels,
best_wheel_index,
wheels: adjusted_wheels,
best_wheel_index: adjusted_best_index,
sdist,
})
}

/// If this prioritized dist has an sdist, then this creates a source
/// distribution.
pub fn source_dist(&self) -> Option<RegistrySourceDist> {
let mut sdist = self.0.source.as_ref().map(|(sdist, _)| sdist.clone())?;
let mut sdist = self
.0
.source
.as_ref()
.filter(|(_, compatibility)| !compatibility.is_excluded())
.map(|(sdist, _)| sdist.clone())?;
assert!(
sdist.wheels.is_empty(),
"source distribution should not have any wheels yet"
Expand Down Expand Up @@ -623,6 +646,11 @@ impl WheelCompatibility {
matches!(self, Self::Compatible(_, _, _))
}

/// Return `true` if the distribution is excluded.
pub fn is_excluded(&self) -> bool {
matches!(self, Self::Incompatible(IncompatibleWheel::ExcludeNewer(_)))
}
Comment on lines +650 to +652
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to not consider all Incompatible() instances "excluded"?


/// Return `true` if the current compatibility is more compatible than another.
///
/// Compatible wheels are always higher more compatible than incompatible wheels.
Expand Down Expand Up @@ -650,6 +678,14 @@ impl SourceDistCompatibility {
matches!(self, Self::Compatible(_))
}

/// Return `true` if the distribution is excluded.
pub fn is_excluded(&self) -> bool {
matches!(
self,
Self::Incompatible(IncompatibleSource::ExcludeNewer(_))
)
}

/// Return the higher priority compatibility.
///
/// Compatible source distributions are always higher priority than incompatible source distributions.
Expand Down
92 changes: 90 additions & 2 deletions crates/uv/tests/it/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26082,8 +26082,6 @@ fn lock_pytorch_local_preference() -> Result<()> {
{ name = "torch", version = "2.6.0+cpu", source = { registry = "https://astral-sh.github.io/pytorch-mirror/whl/cpu" }, marker = "sys_platform != 'darwin'" },
]
wheels = [
{ url = "https://files.pythonhosted.org/packages/52/5b/76ca113a853b19c7b1da761f8a72cb6429b3bd0bf932537d8df4657f47c3/torchvision-0.21.0-1-cp312-cp312-manylinux_2_28_aarch64.whl", hash = "sha256:ffa2a16499508fe6798323e455f312c7c55f2a88901c9a7c0fb1efa86cf7e327", size = 2329878 },
{ url = "https://files.pythonhosted.org/packages/4e/fe/5e193353706dab96fe73ae100d5a633ff635ce310e0d92f3bc2958d075b1/torchvision-0.21.0-1-cp313-cp313-manylinux_2_28_aarch64.whl", hash = "sha256:7e9e9afa150e40cd2a8f0701c43cb82a8d724f512896455c0918b987f94b84a4", size = 2280711 },
{ url = "https://files.pythonhosted.org/packages/6e/1b/28f527b22d5e8800184d0bc847f801ae92c7573a8c15979d92b7091c0751/torchvision-0.21.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:97a5814a93c793aaf0179cfc7f916024f4b63218929aee977b645633d074a49f", size = 1784140 },
{ url = "https://files.pythonhosted.org/packages/36/63/0722e153fd27d64d5b0af45b5c8cb0e80b35a68cf0130303bc9a8bb095c7/torchvision-0.21.0-cp312-cp312-manylinux1_x86_64.whl", hash = "sha256:b578bcad8a4083b40d34f689b19ca9f7c63e511758d806510ea03c29ac568f7b", size = 7238673 },
{ url = "https://files.pythonhosted.org/packages/bb/ea/03541ed901cdc30b934f897060d09bbf7a98466a08ad1680320f9ce0cbe0/torchvision-0.21.0-cp312-cp312-manylinux_2_28_aarch64.whl", hash = "sha256:5083a5b1fec2351bf5ea9900a741d54086db75baec4b1d21e39451e00977f1b1", size = 14701186 },
Expand Down Expand Up @@ -26455,3 +26453,93 @@ fn lock_invalid_fork_markers() -> Result<()> {

Ok(())
}

#[test]
fn lock_omit_wheels_exclude_newer() -> Result<()> {
let context = TestContext::new("3.12").with_exclude_newer("2024-08-01T00:00:00Z");

let pyproject_toml = context.temp_dir.child("pyproject.toml");
pyproject_toml.write_str(
r#"
[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["pillow-avif-plugin"]
"#,
)?;

uv_snapshot!(context.filters(), context.lock(), @r"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
Resolved 2 packages in [TIME]
");

let lock = context.read("uv.lock");

insta::with_settings!({
filters => context.filters(),
}, {
assert_snapshot!(
lock, @r#"
version = 1
revision = 1
requires-python = ">=3.12"

[options]
exclude-newer = "2024-08-01T00:00:00Z"

[[package]]
name = "pillow-avif-plugin"
version = "1.4.6"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/2d/eb/9c097e058c9d5bb7cd39b32730397d645856a81360b4e49cafe16ec1f358/pillow-avif-plugin-1.4.6.tar.gz", hash = "sha256:855cf50d03f6fc16e1fd5e364b3cea0b79f4bf90d39ff2123969735d851e08ba", size = 19632 }
wheels = [
{ url = "https://files.pythonhosted.org/packages/b2/f7/460c854c3f4a9802aabd0a25b4814a7e5902c776a6501498a4078bf2a0d3/pillow_avif_plugin-1.4.6-cp312-cp312-macosx_10_10_x86_64.whl", hash = "sha256:e2087daa49881421a5e703fcff80aa2cbcb5a455cf73114ed5f0ea2a697794c8", size = 7980980 },
{ url = "https://files.pythonhosted.org/packages/f5/11/2f0fa7d135f91a8e34d9040b18a899d185776a642f5773ca33d45b0996ba/pillow_avif_plugin-1.4.6-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:5bacc0802516f054f98d9f218ada17b2e8a756e35cb71e7401bb8422848fe796", size = 5743257 },
{ url = "https://files.pythonhosted.org/packages/24/b6/5a2fda66a192c0a372bcd7968c5914ccc6dcd48cd57b2f6cccba4587e209/pillow_avif_plugin-1.4.6-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e74e53951228c3e6ff5141121bd2876e8aecdb27d5f12d01cc519258e0073d8b", size = 6431301 },
{ url = "https://files.pythonhosted.org/packages/ac/1d/2d6f816e15e56b053758fbd6d625fbd79b5cf22e775fce9967b83ede8c31/pillow_avif_plugin-1.4.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b37e1314500cec3457210f4c8a7583afe35751f076efa8122faa0f205403d645", size = 7984138 },
{ url = "https://files.pythonhosted.org/packages/86/36/32e9576c512fb53096ee050a112a12c6054c4e9c6ce2ec9e7e6f4d9d5d11/pillow_avif_plugin-1.4.6-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:d643db246d6c07994fbb98b5fa6c6ae8f9b19b4ed24566bc06942b7dad10ad47", size = 8123272 },
{ url = "https://files.pythonhosted.org/packages/f0/5f/0bb9ec1910a5ece813ac6324b1d0f148cf71a0e5297ab8fcfce1e48a4ebe/pillow_avif_plugin-1.4.6-cp312-cp312-win_amd64.whl", hash = "sha256:f262547edeec00ad287c8845ac6c9d7d822ef4b00d1832175c4c8fd692e34eba", size = 10564587 },
]

[[package]]
name = "project"
version = "0.1.0"
source = { virtual = "." }
dependencies = [
{ name = "pillow-avif-plugin" },
]

[package.metadata]
requires-dist = [{ name = "pillow-avif-plugin" }]
"#
);
});

// Re-run with `--locked`.
uv_snapshot!(context.filters(), context.lock().arg("--locked"), @r"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
Resolved 2 packages in [TIME]
");

// Re-run with `--offline`. We shouldn't need a network connection to validate an
// already-correct lockfile with immutable metadata.
uv_snapshot!(context.filters(), context.lock().arg("--locked").arg("--offline").arg("--no-cache"), @r"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
Resolved 2 packages in [TIME]
");

Ok(())
}
64 changes: 64 additions & 0 deletions crates/uv/tests/it/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16130,6 +16130,70 @@ fn respect_non_local_preference() -> Result<()> {
Ok(())
}

#[test]
fn omit_wheels_exclude_newer() -> Result<()> {
let context = TestContext::new("3.12").with_exclude_newer("2024-08-01T00:00:00Z");
let requirements_in = context.temp_dir.child("requirements.in");
requirements_in.write_str("pillow-avif-plugin")?;

uv_snapshot!(context
.pip_compile()
.arg("requirements.in")
.arg("--universal")
.arg("--generate-hashes"), @r"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] requirements.in --universal --generate-hashes
pillow-avif-plugin==1.4.6 \
--hash=sha256:0014a215e197c52520d3946f3704c8c0932a170cc5783f96d2385f55191dce29 \
--hash=sha256:07372b7740439cc26346d8e3995de1fd5c49a92ab307321b74b3e6305a7e0e49 \
--hash=sha256:09a7e4b00b18df55b9f34d4f031060ca46d8f5f5e0ba347dda600dcb5172e5f2 \
--hash=sha256:0e699ca8dcfee82732495e101401567184fed6ba10f17e7fb872c46415606ec7 \
--hash=sha256:2347399f2457e5efacec8fc9e446a5a90252b8723c6a47dc61e2353aa97e3e2e \
--hash=sha256:25d1dea0c496a49b17a336b271263ea76a4a0af19553565e95c4bb03281a4113 \
--hash=sha256:323804efe752cf4d15fdcf770749ba23d727f8ea94b95cfe42bec597f3b9bbbb \
--hash=sha256:334e1d39e8b3b4548db690df3735039378e96e1497fd8ba0e25a5e21561b7cf5 \
--hash=sha256:41a8c41b56a891adbcff30933009d475fdd649f2025d62ba59885975ed4379c0 \
--hash=sha256:450b34d19d88443e39b011e84b54433f7ccd6cf8774ed626e433ec3cc7d52924 \
--hash=sha256:56be2604b734caf23788922dbcc92d880d241d02b444c7a8367a65bb25b16aac \
--hash=sha256:584469ea7dedd8ca4f579917cf22f25e8ab980e1b98bbe212cbd7395f881cd42 \
--hash=sha256:5bacc0802516f054f98d9f218ada17b2e8a756e35cb71e7401bb8422848fe796 \
--hash=sha256:5c5e6575e0ca0cd292d459cf627a27a505f38a6edad6f35fd9c4bce4a2cccef3 \
--hash=sha256:5d3c1202e9e03b93ef5e385fcee917d73e23833618472e6416c0fc58b53ba8b8 \
--hash=sha256:60699d10679c8361690703b79abde4a2e7b8047540f0c58fd5da0ac672a15321 \
--hash=sha256:6556cbee2d755dc99a99a5a85c302393e58bcbbf675bc93fa9ab283904dadbfc \
--hash=sha256:6bc73ea62605c8725aba2422de1b546a5c4a6e5e73dcf66f9e22102249342d6b \
--hash=sha256:7d2e933e9b197e9a51c3fbfce389a70201fbce1b7c60172f790760217d7927f8 \
--hash=sha256:855cf50d03f6fc16e1fd5e364b3cea0b79f4bf90d39ff2123969735d851e08ba \
--hash=sha256:91537935612d8fb4b8f621a912ce0eb4e363fdf615d472b20a043a7a18efb461 \
--hash=sha256:963ce7b93340f235db5c7f16b46835c72681896052dcbf1652a01946e7b9103e \
--hash=sha256:a6f97ffc84cdce0926f86a2f4bee088e661f5f93bec9112adca281341f463479 \
--hash=sha256:b37e1314500cec3457210f4c8a7583afe35751f076efa8122faa0f205403d645 \
--hash=sha256:b4f08c341d8aed2d7762589fdd99c4d3e191d4976dab59516b522704a67a281d \
--hash=sha256:b7c2e4adcdf7341dc05f31f13d85b6c4eed0e08daafc836e7b3317df41074bab \
--hash=sha256:b95c477fc619a82a68800ff18599e2704aec6fcf9aa65898b02f0240feeb0af5 \
--hash=sha256:c1cd659136fca622a9324fa7efa56f711f2e576206754c284b80aa5504fb96e4 \
--hash=sha256:c8b9347a91acd183db302e198cf582127eb3de98ad185bf9aff773c99e415320 \
--hash=sha256:c96ee1d1b504a2efa80c9d6d3b71a9884c724dc34d6e67131a64678e09c7a81c \
--hash=sha256:ce89c26671cd0fcb7967e4be4098ae8775b93cc6376ecd523c815cb5a2146298 \
--hash=sha256:d643db246d6c07994fbb98b5fa6c6ae8f9b19b4ed24566bc06942b7dad10ad47 \
--hash=sha256:dec8a348e46266dd0bf20a6edd01b96b0a11042e8654d701444e4a5cebf7f44b \
--hash=sha256:df9a1e569543006abe0c534a3fa66ee1d72393644fd0d5bc74de57bfdb619573 \
--hash=sha256:e2087daa49881421a5e703fcff80aa2cbcb5a455cf73114ed5f0ea2a697794c8 \
--hash=sha256:e74e53951228c3e6ff5141121bd2876e8aecdb27d5f12d01cc519258e0073d8b \
--hash=sha256:f262547edeec00ad287c8845ac6c9d7d822ef4b00d1832175c4c8fd692e34eba \
--hash=sha256:fdd6ee615d948a2b68fd293f74a1a73d22e9d075f5d714b95a90ec2cb8da8de0
# via -r requirements.in

----- stderr -----
Resolved 1 package in [TIME]
");

Ok(())
}

/// See: <https://github.com/astral-sh/uv/issues/12260>
#[test]
fn compile_quotes() -> Result<()> {
Expand Down
Loading
Loading