Drop Python version range enforcement from PythonVersion::from_str#7264
Merged
Drop Python version range enforcement from PythonVersion::from_str#7264
PythonVersion::from_str#7264Conversation
Member
Author
|
@konstin looking to add this validation somewhere but not sure where it belongs It looks like this error variant is never used? uv/crates/uv-python/src/interpreter.rs Lines 560 to 561 in 4f23491 We probably need to check this during version requests too? For future reference, explicit validation looks like this diff --git a/crates/uv-python/src/python_version.rs b/crates/uv-python/src/python_version.rs
index 6c4a99487..db83bb4ac 100644
--- a/crates/uv-python/src/python_version.rs
+++ b/crates/uv-python/src/python_version.rs
@@ -165,6 +165,18 @@ impl PythonVersion {
Self::from_str(format!("{}.{}", self.major(), self.minor()).as_str())
.expect("dropping a patch should always be valid")
}
+
+ /// Returns an error if the Python version is not supported.
+ pub fn check_supported(&self) -> Result<(), String> {
+ if version.version < Version::new([3, 7]) {
+ return Err(format!("Python version `{s}` must be >= 3.7"));
+ }
+ if version.version >= Version::new([4, 0]) {
+ return Err(format!("Python version `{s}` must be < 4.0"));
+ }
+
+ Ok(())
+ }
}
#[cfg(test)] |
Member
|
We should be filtering out too old interpreters at |
konstin
approved these changes
Sep 10, 2024
Member
Author
|
Ah okay so it's constructed by the deserializer. Lgtm then. |
This was referenced Sep 10, 2024
zanieb
added a commit
that referenced
this pull request
Sep 10, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This caused some problems earlier, as it prevented us from listing Python versions <3.7 which seems weird (see #7131 (comment))
I'm worried that without this the changes to installation key parsing in #7263 would otherwise be too restrictive.
I think if we want to enforce these ranges, we should do so separately from the parse step.