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 propagating top-level options to sub-resolutions #1607

Merged
merged 1 commit into from
Feb 17, 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
16 changes: 8 additions & 8 deletions crates/uv/src/commands/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,6 @@ pub(crate) async fn pip_compile(
// Track in-flight downloads, builds, etc., across resolutions.
let in_flight = InFlight::default();

let options = OptionsBuilder::new()
.resolution_mode(resolution_mode)
.prerelease_mode(prerelease_mode)
.dependency_mode(dependency_mode)
.exclude_newer(exclude_newer)
.build();

let build_dispatch = BuildDispatch::new(
&client,
&cache,
Expand All @@ -230,7 +223,7 @@ pub(crate) async fn pip_compile(
no_build,
&NoBinary::None,
)
.with_options(options);
.with_options(OptionsBuilder::new().exclude_newer(exclude_newer).build());

// Build the editables and add their requirements
let editable_metadata = if editables.is_empty() {
Expand Down Expand Up @@ -286,6 +279,13 @@ pub(crate) async fn pip_compile(
editable_metadata,
);

let options = OptionsBuilder::new()
.resolution_mode(resolution_mode)
.prerelease_mode(prerelease_mode)
.dependency_mode(dependency_mode)
.exclude_newer(exclude_newer)
.build();

// Resolve the dependencies.
let resolver = Resolver::new(
manifest,
Expand Down
17 changes: 9 additions & 8 deletions crates/uv/src/commands/pip_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,6 @@ pub(crate) async fn pip_install(
// Track in-flight downloads, builds, etc., across resolutions.
let in_flight = InFlight::default();

let options = OptionsBuilder::new()
.resolution_mode(resolution_mode)
.prerelease_mode(prerelease_mode)
.dependency_mode(dependency_mode)
.exclude_newer(exclude_newer)
.build();

let resolve_dispatch = BuildDispatch::new(
&client,
&cache,
Expand All @@ -183,7 +176,7 @@ pub(crate) async fn pip_install(
no_build,
no_binary,
)
.with_options(options);
.with_options(OptionsBuilder::new().exclude_newer(exclude_newer).build());

// Build all editable distributions. The editables are shared between resolution and
// installation, and should live for the duration of the command. If an editable is already
Expand All @@ -205,6 +198,13 @@ pub(crate) async fn pip_install(
.await?
};

let options = OptionsBuilder::new()
.resolution_mode(resolution_mode)
.prerelease_mode(prerelease_mode)
.dependency_mode(dependency_mode)
.exclude_newer(exclude_newer)
.build();

// Resolve the requirements.
let resolution = match resolve(
requirements,
Expand Down Expand Up @@ -258,6 +258,7 @@ pub(crate) async fn pip_install(
no_build,
no_binary,
)
.with_options(OptionsBuilder::new().exclude_newer(exclude_newer).build())
};

// Sync the environment.
Expand Down
3 changes: 1 addition & 2 deletions crates/uv/src/commands/venv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ async fn venv_impl(
let in_flight = InFlight::default();

// Prep the build context.
let options = OptionsBuilder::new().exclude_newer(exclude_newer).build();
let build_dispatch = BuildDispatch::new(
&client,
cache,
Expand All @@ -158,7 +157,7 @@ async fn venv_impl(
&NoBuild::All,
&NoBinary::None,
)
.with_options(options);
.with_options(OptionsBuilder::new().exclude_newer(exclude_newer).build());

// Resolve the seed packages.
let resolution = build_dispatch
Expand Down
32 changes: 32 additions & 0 deletions crates/uv/tests/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,38 @@ fn compile_python_37() -> Result<()> {
Ok(())
}

/// Resolve a source distribution with `--resolution=lowest-direct`, to ensure that the build
/// requirements aren't resolved at their lowest compatible version.
#[test]
fn compile_sdist_resolution_lowest() -> Result<()> {
let context = TestContext::new("3.12");
let requirements_in = context.temp_dir.child("requirements.in");
requirements_in.write_str("anyio @ https://files.pythonhosted.org/packages/2d/b8/7333d87d5f03247215d86a86362fd3e324111788c6cdd8d2e6196a6ba833/anyio-4.2.0.tar.gz")?;

uv_snapshot!(context.compile()
.arg("requirements.in")
.arg("--resolution=lowest-direct")
.arg("--python-version")
.arg("3.12"), @r###"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv v[VERSION] via the following command:
# uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --resolution=lowest-direct --python-version 3.12
anyio @ https://files.pythonhosted.org/packages/2d/b8/7333d87d5f03247215d86a86362fd3e324111788c6cdd8d2e6196a6ba833/anyio-4.2.0.tar.gz
idna==3.4
# via anyio
sniffio==1.3.0
# via anyio
----- stderr -----
Resolved 3 packages in [TIME]
"###
);

Ok(())
}

/// Resolve a specific version of Black against an invalid Python version.
#[test]
fn compile_python_invalid_version() -> Result<()> {
Expand Down
29 changes: 29 additions & 0 deletions crates/uv/tests/pip_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,3 +1129,32 @@ fn install_pinned_polars_invalid_metadata() {

context.assert_command("import polars").success();
}

/// Install a source distribution with `--resolution=lowest-direct`, to ensure that the build
/// requirements aren't resolved at their lowest compatible version.
#[test]
fn install_sdist_resolution_lowest() -> Result<()> {
let context = TestContext::new("3.12");
let requirements_in = context.temp_dir.child("requirements.in");
requirements_in.write_str("anyio @ https://files.pythonhosted.org/packages/2d/b8/7333d87d5f03247215d86a86362fd3e324111788c6cdd8d2e6196a6ba833/anyio-4.2.0.tar.gz")?;

uv_snapshot!(command(&context)
.arg("-r")
.arg("requirements.in")
.arg("--resolution=lowest-direct"), @r###"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
Resolved 3 packages in [TIME]
Downloaded 3 packages in [TIME]
Installed 3 packages in [TIME]
+ anyio==4.2.0 (from https://files.pythonhosted.org/packages/2d/b8/7333d87d5f03247215d86a86362fd3e324111788c6cdd8d2e6196a6ba833/anyio-4.2.0.tar.gz)
+ idna==3.4
+ sniffio==1.3.0
"###
);

Ok(())
}