Skip to content

Commit

Permalink
Check-in updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Mar 14, 2024
1 parent e404dc9 commit b4625f3
Show file tree
Hide file tree
Showing 7 changed files with 859 additions and 132 deletions.
3 changes: 0 additions & 3 deletions crates/uv-resolver/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ pub enum ResolveError {
#[error("There are conflicting URLs for package `{0}`:\n- {1}\n- {2}")]
ConflictingUrlsTransitive(PackageName, String, String),

#[error("There are conflicting local versions requested for package `{0}`: {1} vs. {2}")]
ConflictingLocal(PackageName, String, String),

#[error("Package `{0}` attempted to resolve via URL: {1}. URL dependencies must be expressed as direct requirements or constraints. Consider adding `{0} @ {1}` to your dependencies or constraints file.")]
DisallowedUrl(PackageName, String),

Expand Down
29 changes: 12 additions & 17 deletions crates/uv-resolver/src/resolver/locals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,23 @@ impl Locals {
.filter(|requirement| requirement.evaluate_markers(markers, &[])),
)
{
if let Some(version) = to_local(requirement.version_or_url.as_ref()) {
required.insert(requirement.name.clone(), version.clone());
if let Some(VersionOrUrl::VersionSpecifier(specifiers)) = requirement.version_or_url.as_ref() {
for specifier in specifiers.iter() {
if let Some(version) = to_local(specifier) {
required.insert(requirement.name.clone(), version.clone());
}
}
}
}
};

Self { required }
}

/// Return the [`VerbatimUrl`] associated with the given package name, if any.
/// Return the local [`Version`] to which a package is pinned, if any.
pub(crate) fn get(&self, package: &PackageName) -> Option<&Version> {
self.required.get(package)
}


/// Given a specifier that may include the version _without_ a local segment, return a specifier
/// that includes the local segment from the expected version.
pub(crate) fn map(local: &Version, specifier: &VersionSpecifier) -> VersionSpecifier {
Expand Down Expand Up @@ -120,7 +123,6 @@ impl Locals {
}
}


/// Returns `true` if a provided version is compatible with the expected local version.
///
/// The versions are compatible if they are the same including their local segment, or the
Expand All @@ -146,17 +148,10 @@ fn is_compatible(expected: &Version, provided: &Version) -> bool {
}
}

/// If a [`VersionOrUrl`] is an exact version with a local segment, return the local version.
fn to_local(version_or_url: Option<&VersionOrUrl>) -> Option<&Version> {
let Some(VersionOrUrl::VersionSpecifier(specifier)) = version_or_url else {
return None;
};

let [specifier] = &**specifier else {
return None;
};

if *specifier.operator() != pep440_rs::Operator::Equal {
/// If a [`VersionSpecifier`] represents exact equality against a local version, return the local
/// version.
fn to_local(specifier: &VersionSpecifier) -> Option<&Version> {
if !matches!(specifier.operator(), Operator::Equal | Operator::ExactEqual) {
return None;
};

Expand Down
15 changes: 2 additions & 13 deletions crates/uv/tests/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1501,22 +1501,11 @@ fn disallowed_transitive_url_dependency() -> Result<()> {
.arg("requirements.in")
.env("HATCHLING", hatchling_path.as_os_str()), @r###"
success: false
exit_code: 1
exit_code: 2
----- stdout -----
----- stderr -----
× No solution found when resolving dependencies:
╰─▶ Because only hatchling-editable==0.1.0 is available and
hatchling-editable==0.1.0 is unusable because its dependencies are
unusable because package `iniconfig` attempted to resolve via URL:
git+https://github.com/pytest-dev/iniconfig@9cae43103df70bac6fde7b9f35ad11a9f1be0cb4.
URL dependencies must be expressed as direct
requirements or constraints. Consider adding `iniconfig @
git+https://github.com/pytest-dev/iniconfig@9cae43103df70bac6fde7b9f35ad11a9f1be0cb4`
to your dependencies or constraints file., we can conclude that all
versions of hatchling-editable cannot be used.
And because you require hatchling-editable, we can conclude that the
requirements are unsatisfiable.
error: Package `iniconfig` attempted to resolve via URL: git+https://github.com/pytest-dev/iniconfig@9cae43103df70bac6fde7b9f35ad11a9f1be0cb4. URL dependencies must be expressed as direct requirements or constraints. Consider adding `iniconfig @ git+https://github.com/pytest-dev/iniconfig@9cae43103df70bac6fde7b9f35ad11a9f1be0cb4` to your dependencies or constraints file.
"###
);

Expand Down
112 changes: 96 additions & 16 deletions crates/uv/tests/pip_compile_scenarios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,18 @@ fn incompatible_python_compatible_override() -> Result<()> {

let output = uv_snapshot!(filters, command(&context, python_versions)
.arg("--python-version=3.11")
, @r###"<snapshot>
"###
, @r###"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile requirements.in --cache-dir [CACHE_DIR] --python-version=3.11
albatross==1.0.0
----- stderr -----
warning: The requested Python version 3.11 is not available; 3.9.18 will be used to build dependencies instead.
Resolved 1 package in [TIME]
"###
);

output.assert().success().stdout(predicate::str::contains(
Expand Down Expand Up @@ -116,8 +126,17 @@ fn compatible_python_incompatible_override() -> Result<()> {

let output = uv_snapshot!(filters, command(&context, python_versions)
.arg("--python-version=3.9")
, @r###"<snapshot>
"###
, @r###"
success: false
exit_code: 1
----- stdout -----
----- stderr -----
warning: The requested Python version 3.9 is not available; 3.11.7 will be used to build dependencies instead.
× No solution found when resolving dependencies:
╰─▶ Because the requested Python version (3.9) does not satisfy Python>=3.10 and albatross==1.0.0 depends on Python>=3.10, we can conclude that albatross==1.0.0 cannot be used.
And because you require albatross==1.0.0, we can conclude that the requirements are unsatisfiable.
"###
);

output.assert().failure();
Expand Down Expand Up @@ -165,8 +184,17 @@ fn incompatible_python_compatible_override_unavailable_no_wheels() -> Result<()>
// dependencies.
let output = uv_snapshot!(filters, command(&context, python_versions)
.arg("--python-version=3.11")
, @r###"<snapshot>
"###
, @r###"
success: false
exit_code: 1
----- stdout -----
----- stderr -----
warning: The requested Python version 3.11 is not available; 3.9.18 will be used to build dependencies instead.
× No solution found when resolving dependencies:
╰─▶ Because the current Python version (3.9.18) does not satisfy Python>=3.10 and albatross==1.0.0 depends on Python>=3.10, we can conclude that albatross==1.0.0 cannot be used.
And because you require albatross==1.0.0, we can conclude that the requirements are unsatisfiable.
"###
);

output.assert().failure();
Expand Down Expand Up @@ -215,8 +243,17 @@ fn incompatible_python_compatible_override_available_no_wheels() -> Result<()> {
// used to build the source distributions.
let output = uv_snapshot!(filters, command(&context, python_versions)
.arg("--python-version=3.11")
, @r###"<snapshot>
"###
, @r###"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile requirements.in --cache-dir [CACHE_DIR] --python-version=3.11
albatross==1.0.0
----- stderr -----
Resolved 1 package in [TIME]
"###
);

output.assert().success().stdout(predicate::str::contains(
Expand Down Expand Up @@ -266,8 +303,17 @@ fn incompatible_python_compatible_override_no_compatible_wheels() -> Result<()>
// determine its dependencies.
let output = uv_snapshot!(filters, command(&context, python_versions)
.arg("--python-version=3.11")
, @r###"<snapshot>
"###
, @r###"
success: false
exit_code: 1
----- stdout -----
----- stderr -----
warning: The requested Python version 3.11 is not available; 3.9.18 will be used to build dependencies instead.
× No solution found when resolving dependencies:
╰─▶ Because the current Python version (3.9.18) does not satisfy Python>=3.10 and albatross==1.0.0 depends on Python>=3.10, we can conclude that albatross==1.0.0 cannot be used.
And because you require albatross==1.0.0, we can conclude that the requirements are unsatisfiable.
"###
);

output.assert().failure();
Expand Down Expand Up @@ -319,8 +365,24 @@ fn incompatible_python_compatible_override_other_wheel() -> Result<()> {
// available, but is not compatible with the target version and cannot be used.
let output = uv_snapshot!(filters, command(&context, python_versions)
.arg("--python-version=3.11")
, @r###"<snapshot>
"###
, @r###"
success: false
exit_code: 1
----- stdout -----
----- stderr -----
warning: The requested Python version 3.11 is not available; 3.9.18 will be used to build dependencies instead.
× No solution found when resolving dependencies:
╰─▶ Because the current Python version (3.9.18) does not satisfy Python>=3.10 and albatross==1.0.0 depends on Python>=3.10, we can conclude that albatross==1.0.0 cannot be used.
And because only the following versions of albatross are available:
albatross==1.0.0
albatross==2.0.0
we can conclude that albatross<2.0.0 cannot be used. (1)
Because the requested Python version (3.11) does not satisfy Python>=3.12 and albatross==2.0.0 depends on Python>=3.12, we can conclude that albatross==2.0.0 cannot be used.
And because we know from (1) that albatross<2.0.0 cannot be used, we can conclude that all versions of albatross cannot be used.
And because you require albatross, we can conclude that the requirements are unsatisfiable.
"###
);

output.assert().failure();
Expand Down Expand Up @@ -359,8 +421,16 @@ fn python_patch_override_no_patch() -> Result<()> {
// requirement is treated as 3.8.0.
let output = uv_snapshot!(filters, command(&context, python_versions)
.arg("--python-version=3.8")
, @r###"<snapshot>
"###
, @r###"
success: false
exit_code: 1
----- stdout -----
----- stderr -----
× No solution found when resolving dependencies:
╰─▶ Because the requested Python version (3.8) does not satisfy Python>=3.8.4 and albatross==1.0.0 depends on Python>=3.8.4, we can conclude that albatross==1.0.0 cannot be used.
And because you require albatross==1.0.0, we can conclude that the requirements are unsatisfiable.
"###
);

output.assert().failure();
Expand Down Expand Up @@ -397,8 +467,18 @@ fn python_patch_override_patch_compatible() -> Result<()> {

let output = uv_snapshot!(filters, command(&context, python_versions)
.arg("--python-version=3.8.0")
, @r###"<snapshot>
"###
, @r###"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile requirements.in --cache-dir [CACHE_DIR] --python-version=3.8.0
albatross==1.0.0
----- stderr -----
warning: The requested Python version 3.8.0 is not available; 3.8.18 will be used to build dependencies instead.
Resolved 1 package in [TIME]
"###
);

output.assert().success().stdout(predicate::str::contains(
Expand Down
Loading

0 comments on commit b4625f3

Please sign in to comment.