Skip to content

Commit

Permalink
Trim injected python_version marker to (major, minor)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Mar 12, 2024
1 parent 28bf493 commit 0163267
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions crates/uv-interpreter/src/python_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ impl FromStr for PythonVersion {
if version.epoch() != 0 {
return Err(format!("Python version {s} has a non-zero epoch"));
}
if version.is_post() {
return Err(format!("Python version {s} is a post-release"));
}
if version.is_pre() {
return Err(format!("Python version {s} is a pre-release"));
}
if version.version < Version::new([3, 7]) {
return Err(format!("Python version {s} must be >= 3.7"));
}
Expand Down Expand Up @@ -62,11 +68,26 @@ impl PythonVersion {
markers.implementation_version = self.0.clone();
}

// Ex) Given `"3.12.0"`, `major == 3`, `minor == 12`, `patch == 0`.
let major = self.release().get(0).copied().unwrap_or(0);
let minor = self.release().get(1).copied().unwrap_or(0);
let patch = self.release().get(2).copied().unwrap_or(0);

// Ex) `python_full_version == "3.12.0"`
markers.python_full_version = self.0.clone();
markers.python_full_version = StringVersion {
string: format!("{major}.{minor}.{patch}"),
version: Version::new([
self.release()[0],
self.release()[1],
self.release().get(2).copied().unwrap_or(0),
]),
};

// Ex) `python_version == "3.12"`
markers.python_version = self.0;
markers.python_version = StringVersion {
string: format!("{major}.{minor}"),
version: Version::new([major, minor]),
};

markers
}
Expand Down

0 comments on commit 0163267

Please sign in to comment.