Skip to content

Commit

Permalink
Avoid propagating top-level options to sub-resolutions
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Feb 17, 2024
1 parent ee2e7bb commit 18156f8
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 18 deletions.
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

0 comments on commit 18156f8

Please sign in to comment.