Skip to content

Commit

Permalink
Wait for distribution metadata with --no-deps
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Feb 21, 2024
1 parent 88a0c13 commit e92a1e3
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
19 changes: 19 additions & 0 deletions crates/uv-resolver/src/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,25 @@ impl<'a, Provider: ResolverProvider> Resolver<'a, Provider> {
PubGrubPackage::Package(package_name, extra, url) => {
// If we're excluding transitive dependencies, short-circuit.
if self.dependency_mode.is_direct() {
// If an extra is provided, wait for the metadata to be available, since it's
// still required for reporting diagnostics.
if extra.is_some() {
// Determine the distribution to lookup.
let dist = match url {
Some(url) => PubGrubDistribution::from_url(package_name, url),
None => PubGrubDistribution::from_registry(package_name, version),
};
let package_id = dist.package_id();

// Wait for the metadata to be available.
self.index
.distributions
.wait(&package_id)
.instrument(info_span!("distributions_wait", %package_id))
.await
.ok_or(ResolveError::Unregistered)?;
}

return Ok(Dependencies::Available(DependencyConstraints::default()));
}

Expand Down
53 changes: 53 additions & 0 deletions crates/uv/tests/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3859,3 +3859,56 @@ fn unsupported_scheme() -> Result<()> {

Ok(())
}


/// Resolve a package with `--no-deps`, including a valid extra.
#[test]
fn no_deps_valid_extra() -> Result<()> {
let context = TestContext::new("3.12");
let requirements_in = context.temp_dir.child("requirements.in");
requirements_in.write_str("flask[dotenv]")?;

uv_snapshot!(context.compile()
.arg("requirements.in")
.arg("--no-deps"), @r###"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --no-deps
flask==3.0.0
----- stderr -----
Resolved 1 package in [TIME]
"###
);

Ok(())
}


/// Resolve a package with `--no-deps`, including an invalid extra.
#[test]
fn no_deps_invalid_extra() -> Result<()> {
let context = TestContext::new("3.12");
let requirements_in = context.temp_dir.child("requirements.in");
requirements_in.write_str("flask[empty]")?;

uv_snapshot!(context.compile()
.arg("requirements.in")
.arg("--no-deps"), @r###"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --no-deps
flask==3.0.0
----- stderr -----
Resolved 1 package in [TIME]
warning: The package `flask==3.0.0` does not have an extra named `empty`.
"###
);

Ok(())
}

0 comments on commit e92a1e3

Please sign in to comment.