Skip to content

Commit 0fe844c

Browse files
committed
Check-in updated tests
1 parent e404dc9 commit 0fe844c

File tree

8 files changed

+864
-131
lines changed

8 files changed

+864
-131
lines changed

crates/pep440-rs/src/version_specifier.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,10 @@ impl Serialize for VersionSpecifier {
341341

342342
impl VersionSpecifier {
343343
/// Create a new version specifier from an operator and a version.
344+
///
345+
/// Warning: This function is not recommended for general use. It is intended for use in
346+
/// situations where the operator and version are known to be valid. For general use, prefer
347+
/// [`VersionSpecifier::from_pattern`].
344348
pub fn new(operator: Operator, version: Version) -> Self {
345349
Self { operator, version }
346350
}

crates/uv-resolver/src/error.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ pub enum ResolveError {
5252
#[error("There are conflicting URLs for package `{0}`:\n- {1}\n- {2}")]
5353
ConflictingUrlsTransitive(PackageName, String, String),
5454

55-
#[error("There are conflicting local versions requested for package `{0}`: {1} vs. {2}")]
56-
ConflictingLocal(PackageName, String, String),
57-
5855
#[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.")]
5956
DisallowedUrl(PackageName, String),
6057

crates/uv-resolver/src/resolver/locals.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,25 @@ impl Locals {
4242
.filter(|requirement| requirement.evaluate_markers(markers, &[])),
4343
)
4444
{
45-
if let Some(version) = to_local(requirement.version_or_url.as_ref()) {
46-
required.insert(requirement.name.clone(), version.clone());
45+
if let Some(VersionOrUrl::VersionSpecifier(specifiers)) =
46+
requirement.version_or_url.as_ref()
47+
{
48+
for specifier in specifiers.iter() {
49+
if let Some(version) = to_local(specifier) {
50+
required.insert(requirement.name.clone(), version.clone());
51+
}
52+
}
4753
}
4854
}
4955

5056
Self { required }
5157
}
5258

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

58-
5964
/// Given a specifier that may include the version _without_ a local segment, return a specifier
6065
/// that includes the local segment from the expected version.
6166
pub(crate) fn map(local: &Version, specifier: &VersionSpecifier) -> VersionSpecifier {
@@ -120,7 +125,6 @@ impl Locals {
120125
}
121126
}
122127

123-
124128
/// Returns `true` if a provided version is compatible with the expected local version.
125129
///
126130
/// The versions are compatible if they are the same including their local segment, or the
@@ -146,17 +150,10 @@ fn is_compatible(expected: &Version, provided: &Version) -> bool {
146150
}
147151
}
148152

149-
/// If a [`VersionOrUrl`] is an exact version with a local segment, return the local version.
150-
fn to_local(version_or_url: Option<&VersionOrUrl>) -> Option<&Version> {
151-
let Some(VersionOrUrl::VersionSpecifier(specifier)) = version_or_url else {
152-
return None;
153-
};
154-
155-
let [specifier] = &**specifier else {
156-
return None;
157-
};
158-
159-
if *specifier.operator() != pep440_rs::Operator::Equal {
153+
/// If a [`VersionSpecifier`] represents exact equality against a local version, return the local
154+
/// version.
155+
fn to_local(specifier: &VersionSpecifier) -> Option<&Version> {
156+
if !matches!(specifier.operator(), Operator::Equal | Operator::ExactEqual) {
160157
return None;
161158
};
162159

crates/uv/tests/pip_compile.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,22 +1501,11 @@ fn disallowed_transitive_url_dependency() -> Result<()> {
15011501
.arg("requirements.in")
15021502
.env("HATCHLING", hatchling_path.as_os_str()), @r###"
15031503
success: false
1504-
exit_code: 1
1504+
exit_code: 2
15051505
----- stdout -----
15061506
15071507
----- stderr -----
1508-
× No solution found when resolving dependencies:
1509-
╰─▶ Because only hatchling-editable==0.1.0 is available and
1510-
hatchling-editable==0.1.0 is unusable because its dependencies are
1511-
unusable because package `iniconfig` attempted to resolve via URL:
1512-
git+https://github.com/pytest-dev/iniconfig@9cae43103df70bac6fde7b9f35ad11a9f1be0cb4.
1513-
URL dependencies must be expressed as direct
1514-
requirements or constraints. Consider adding `iniconfig @
1515-
git+https://github.com/pytest-dev/iniconfig@9cae43103df70bac6fde7b9f35ad11a9f1be0cb4`
1516-
to your dependencies or constraints file., we can conclude that all
1517-
versions of hatchling-editable cannot be used.
1518-
And because you require hatchling-editable, we can conclude that the
1519-
requirements are unsatisfiable.
1508+
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.
15201509
"###
15211510
);
15221511

crates/uv/tests/pip_compile_scenarios.rs

Lines changed: 96 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,18 @@ fn incompatible_python_compatible_override() -> Result<()> {
7676

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

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

117127
let output = uv_snapshot!(filters, command(&context, python_versions)
118128
.arg("--python-version=3.9")
119-
, @r###"<snapshot>
120-
"###
129+
, @r###"
130+
success: false
131+
exit_code: 1
132+
----- stdout -----
133+
134+
----- stderr -----
135+
warning: The requested Python version 3.9 is not available; 3.11.7 will be used to build dependencies instead.
136+
× No solution found when resolving dependencies:
137+
╰─▶ 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.
138+
And because you require albatross==1.0.0, we can conclude that the requirements are unsatisfiable.
139+
"###
121140
);
122141

123142
output.assert().failure();
@@ -165,8 +184,17 @@ fn incompatible_python_compatible_override_unavailable_no_wheels() -> Result<()>
165184
// dependencies.
166185
let output = uv_snapshot!(filters, command(&context, python_versions)
167186
.arg("--python-version=3.11")
168-
, @r###"<snapshot>
169-
"###
187+
, @r###"
188+
success: false
189+
exit_code: 1
190+
----- stdout -----
191+
192+
----- stderr -----
193+
warning: The requested Python version 3.11 is not available; 3.9.18 will be used to build dependencies instead.
194+
× No solution found when resolving dependencies:
195+
╰─▶ 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.
196+
And because you require albatross==1.0.0, we can conclude that the requirements are unsatisfiable.
197+
"###
170198
);
171199

172200
output.assert().failure();
@@ -215,8 +243,17 @@ fn incompatible_python_compatible_override_available_no_wheels() -> Result<()> {
215243
// used to build the source distributions.
216244
let output = uv_snapshot!(filters, command(&context, python_versions)
217245
.arg("--python-version=3.11")
218-
, @r###"<snapshot>
219-
"###
246+
, @r###"
247+
success: true
248+
exit_code: 0
249+
----- stdout -----
250+
# This file was autogenerated by uv via the following command:
251+
# uv pip compile requirements.in --cache-dir [CACHE_DIR] --python-version=3.11
252+
albatross==1.0.0
253+
254+
----- stderr -----
255+
Resolved 1 package in [TIME]
256+
"###
220257
);
221258

222259
output.assert().success().stdout(predicate::str::contains(
@@ -266,8 +303,17 @@ fn incompatible_python_compatible_override_no_compatible_wheels() -> Result<()>
266303
// determine its dependencies.
267304
let output = uv_snapshot!(filters, command(&context, python_versions)
268305
.arg("--python-version=3.11")
269-
, @r###"<snapshot>
270-
"###
306+
, @r###"
307+
success: false
308+
exit_code: 1
309+
----- stdout -----
310+
311+
----- stderr -----
312+
warning: The requested Python version 3.11 is not available; 3.9.18 will be used to build dependencies instead.
313+
× No solution found when resolving dependencies:
314+
╰─▶ 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.
315+
And because you require albatross==1.0.0, we can conclude that the requirements are unsatisfiable.
316+
"###
271317
);
272318

273319
output.assert().failure();
@@ -319,8 +365,24 @@ fn incompatible_python_compatible_override_other_wheel() -> Result<()> {
319365
// available, but is not compatible with the target version and cannot be used.
320366
let output = uv_snapshot!(filters, command(&context, python_versions)
321367
.arg("--python-version=3.11")
322-
, @r###"<snapshot>
323-
"###
368+
, @r###"
369+
success: false
370+
exit_code: 1
371+
----- stdout -----
372+
373+
----- stderr -----
374+
warning: The requested Python version 3.11 is not available; 3.9.18 will be used to build dependencies instead.
375+
× No solution found when resolving dependencies:
376+
╰─▶ 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.
377+
And because only the following versions of albatross are available:
378+
albatross==1.0.0
379+
albatross==2.0.0
380+
we can conclude that albatross<2.0.0 cannot be used. (1)
381+
382+
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.
383+
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.
384+
And because you require albatross, we can conclude that the requirements are unsatisfiable.
385+
"###
324386
);
325387

326388
output.assert().failure();
@@ -359,8 +421,16 @@ fn python_patch_override_no_patch() -> Result<()> {
359421
// requirement is treated as 3.8.0.
360422
let output = uv_snapshot!(filters, command(&context, python_versions)
361423
.arg("--python-version=3.8")
362-
, @r###"<snapshot>
363-
"###
424+
, @r###"
425+
success: false
426+
exit_code: 1
427+
----- stdout -----
428+
429+
----- stderr -----
430+
× No solution found when resolving dependencies:
431+
╰─▶ 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.
432+
And because you require albatross==1.0.0, we can conclude that the requirements are unsatisfiable.
433+
"###
364434
);
365435

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

398468
let output = uv_snapshot!(filters, command(&context, python_versions)
399469
.arg("--python-version=3.8.0")
400-
, @r###"<snapshot>
401-
"###
470+
, @r###"
471+
success: true
472+
exit_code: 0
473+
----- stdout -----
474+
# This file was autogenerated by uv via the following command:
475+
# uv pip compile requirements.in --cache-dir [CACHE_DIR] --python-version=3.8.0
476+
albatross==1.0.0
477+
478+
----- stderr -----
479+
warning: The requested Python version 3.8.0 is not available; 3.8.18 will be used to build dependencies instead.
480+
Resolved 1 package in [TIME]
481+
"###
402482
);
403483

404484
output.assert().success().stdout(predicate::str::contains(

0 commit comments

Comments
 (0)