Skip to content

Commit

Permalink
REdo requires python
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Sep 2, 2024
1 parent 7e6df8f commit 87f8e6a
Show file tree
Hide file tree
Showing 28 changed files with 498 additions and 303 deletions.
2 changes: 1 addition & 1 deletion crates/bench/benches/uv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ mod resolver {
let python_requirement = if universal {
PythonRequirement::from_requires_python(
interpreter,
&RequiresPython::greater_than_equal_version(&Version::new([3, 11])),
RequiresPython::greater_than_equal_version(&Version::new([3, 11])),
)
} else {
PythonRequirement::from_interpreter(interpreter)
Expand Down
36 changes: 22 additions & 14 deletions crates/uv-resolver/src/lock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub struct Lock {
/// The list of supported environments specified by the user.
supported_environments: Vec<MarkerTree>,
/// The range of supported Python versions.
requires_python: Option<RequiresPython>,
requires_python: RequiresPython,
/// We discard the lockfile if these options don't match.
options: ResolverOptions,
/// The actual locked version and their metadata.
Expand Down Expand Up @@ -186,7 +186,7 @@ impl Lock {
fn new(
version: u32,
mut packages: Vec<Package>,
requires_python: Option<RequiresPython>,
requires_python: RequiresPython,
options: ResolverOptions,
manifest: ResolverManifest,
supported_environments: Vec<MarkerTree>,
Expand Down Expand Up @@ -241,11 +241,9 @@ impl Lock {

// Remove wheels that don't match `requires-python` and can't be selected for
// installation.
if let Some(requires_python) = &requires_python {
package
.wheels
.retain(|wheel| requires_python.matches_wheel_tag(&wheel.filename));
}
package
.wheels
.retain(|wheel| requires_python.matches_wheel_tag(&wheel.filename));
}
packages.sort_by(|dist1, dist2| dist1.id.cmp(&dist2.id));

Expand Down Expand Up @@ -390,8 +388,8 @@ impl Lock {
}

/// Returns the supported Python version range for the lockfile, if present.
pub fn requires_python(&self) -> Option<&RequiresPython> {
self.requires_python.as_ref()
pub fn requires_python(&self) -> &RequiresPython {
&self.requires_python
}

/// Returns the resolution mode used to generate this lock.
Expand Down Expand Up @@ -527,9 +525,7 @@ impl Lock {
let mut doc = toml_edit::DocumentMut::new();
doc.insert("version", value(i64::from(self.version)));

if let Some(ref requires_python) = self.requires_python {
doc.insert("requires-python", value(requires_python.to_string()));
}
doc.insert("requires-python", value(self.requires_python.to_string()));

if !self.fork_markers.is_empty() {
let fork_markers = each_element_on_its_line_array(
Expand Down Expand Up @@ -1158,8 +1154,7 @@ impl ResolverManifest {
#[serde(rename_all = "kebab-case")]
struct LockWire {
version: u32,
#[serde(default)]
requires_python: Option<RequiresPython>,
requires_python: RequiresPython,
/// If this lockfile was built from a forking resolution with non-identical forks, store the
/// forks in the lockfile so we can recreate them in subsequent resolutions.
#[serde(rename = "resolution-markers", default)]
Expand Down Expand Up @@ -3685,6 +3680,7 @@ mod tests {
fn missing_dependency_source_unambiguous() {
let data = r#"
version = 1
requires-python = ">=3.12"
[[package]]
name = "a"
Expand All @@ -3710,6 +3706,7 @@ version = "0.1.0"
fn missing_dependency_version_unambiguous() {
let data = r#"
version = 1
requires-python = ">=3.12"
[[package]]
name = "a"
Expand All @@ -3735,6 +3732,7 @@ source = { registry = "https://pypi.org/simple" }
fn missing_dependency_source_version_unambiguous() {
let data = r#"
version = 1
requires-python = ">=3.12"
[[package]]
name = "a"
Expand All @@ -3759,6 +3757,7 @@ name = "a"
fn missing_dependency_source_ambiguous() {
let data = r#"
version = 1
requires-python = ">=3.12"
[[package]]
name = "a"
Expand Down Expand Up @@ -3790,6 +3789,7 @@ version = "0.1.0"
fn missing_dependency_version_ambiguous() {
let data = r#"
version = 1
requires-python = ">=3.12"
[[package]]
name = "a"
Expand Down Expand Up @@ -3821,6 +3821,7 @@ source = { registry = "https://pypi.org/simple" }
fn missing_dependency_source_version_ambiguous() {
let data = r#"
version = 1
requires-python = ">=3.12"
[[package]]
name = "a"
Expand Down Expand Up @@ -3851,6 +3852,7 @@ name = "a"
fn hash_optional_missing() {
let data = r#"
version = 1
requires-python = ">=3.12"
[[package]]
name = "anyio"
Expand All @@ -3866,6 +3868,7 @@ wheels = [{ url = "https://files.pythonhosted.org/packages/14/fd/2f20c40b45e4fb4
fn hash_optional_present() {
let data = r#"
version = 1
requires-python = ">=3.12"
[[package]]
name = "anyio"
Expand All @@ -3881,6 +3884,7 @@ wheels = [{ url = "https://files.pythonhosted.org/packages/14/fd/2f20c40b45e4fb4
fn hash_required_present() {
let data = r#"
version = 1
requires-python = ">=3.12"
[[package]]
name = "anyio"
Expand All @@ -3896,6 +3900,7 @@ wheels = [{ url = "file:///foo/bar/anyio-4.3.0-py3-none-any.whl", hash = "sha256
fn source_direct_no_subdir() {
let data = r#"
version = 1
requires-python = ">=3.12"
[[package]]
name = "anyio"
Expand All @@ -3910,6 +3915,7 @@ source = { url = "https://burntsushi.net" }
fn source_direct_has_subdir() {
let data = r#"
version = 1
requires-python = ">=3.12"
[[package]]
name = "anyio"
Expand All @@ -3924,6 +3930,7 @@ source = { url = "https://burntsushi.net", subdirectory = "wat/foo/bar" }
fn source_directory() {
let data = r#"
version = 1
requires-python = ">=3.12"
[[package]]
name = "anyio"
Expand All @@ -3938,6 +3945,7 @@ source = { directory = "path/to/dir" }
fn source_editable() {
let data = r#"
version = 1
requires-python = ">=3.12"
[[package]]
name = "anyio"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,26 @@ Ok(
version: 1,
fork_markers: [],
supported_environments: [],
requires_python: None,
requires_python: RequiresPython {
specifiers: VersionSpecifiers(
[
VersionSpecifier {
operator: GreaterThanEqual,
version: "3.12",
},
],
),
range: RequiresPythonRange(
RequiresPythonBound(
Included(
"3.12",
),
),
RequiresPythonBound(
Unbounded,
),
),
},
options: ResolverOptions {
resolution_mode: Highest,
prerelease_mode: IfNecessaryOrExplicit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,26 @@ Ok(
version: 1,
fork_markers: [],
supported_environments: [],
requires_python: None,
requires_python: RequiresPython {
specifiers: VersionSpecifiers(
[
VersionSpecifier {
operator: GreaterThanEqual,
version: "3.12",
},
],
),
range: RequiresPythonRange(
RequiresPythonBound(
Included(
"3.12",
),
),
RequiresPythonBound(
Unbounded,
),
),
},
options: ResolverOptions {
resolution_mode: Highest,
prerelease_mode: IfNecessaryOrExplicit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,26 @@ Ok(
version: 1,
fork_markers: [],
supported_environments: [],
requires_python: None,
requires_python: RequiresPython {
specifiers: VersionSpecifiers(
[
VersionSpecifier {
operator: GreaterThanEqual,
version: "3.12",
},
],
),
range: RequiresPythonRange(
RequiresPythonBound(
Included(
"3.12",
),
),
RequiresPythonBound(
Unbounded,
),
),
},
options: ResolverOptions {
resolution_mode: Highest,
prerelease_mode: IfNecessaryOrExplicit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,26 @@ Ok(
version: 1,
fork_markers: [],
supported_environments: [],
requires_python: None,
requires_python: RequiresPython {
specifiers: VersionSpecifiers(
[
VersionSpecifier {
operator: GreaterThanEqual,
version: "3.12",
},
],
),
range: RequiresPythonRange(
RequiresPythonBound(
Included(
"3.12",
),
),
RequiresPythonBound(
Unbounded,
),
),
},
options: ResolverOptions {
resolution_mode: Highest,
prerelease_mode: IfNecessaryOrExplicit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,26 @@ Ok(
version: 1,
fork_markers: [],
supported_environments: [],
requires_python: None,
requires_python: RequiresPython {
specifiers: VersionSpecifiers(
[
VersionSpecifier {
operator: GreaterThanEqual,
version: "3.12",
},
],
),
range: RequiresPythonRange(
RequiresPythonBound(
Included(
"3.12",
),
),
RequiresPythonBound(
Unbounded,
),
),
},
options: ResolverOptions {
resolution_mode: Highest,
prerelease_mode: IfNecessaryOrExplicit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,26 @@ Ok(
version: 1,
fork_markers: [],
supported_environments: [],
requires_python: None,
requires_python: RequiresPython {
specifiers: VersionSpecifiers(
[
VersionSpecifier {
operator: GreaterThanEqual,
version: "3.12",
},
],
),
range: RequiresPythonRange(
RequiresPythonBound(
Included(
"3.12",
),
),
RequiresPythonBound(
Unbounded,
),
),
},
options: ResolverOptions {
resolution_mode: Highest,
prerelease_mode: IfNecessaryOrExplicit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,26 @@ Ok(
version: 1,
fork_markers: [],
supported_environments: [],
requires_python: None,
requires_python: RequiresPython {
specifiers: VersionSpecifiers(
[
VersionSpecifier {
operator: GreaterThanEqual,
version: "3.12",
},
],
),
range: RequiresPythonRange(
RequiresPythonBound(
Included(
"3.12",
),
),
RequiresPythonBound(
Unbounded,
),
),
},
options: ResolverOptions {
resolution_mode: Highest,
prerelease_mode: IfNecessaryOrExplicit,
Expand Down
Loading

0 comments on commit 87f8e6a

Please sign in to comment.