Skip to content

Commit

Permalink
Better error for unsupported Python version (#3398)
Browse files Browse the repository at this point in the history
Fixes #3371

It seems like uv doesn't proactively enforce 3.8+ and in most cases just
issues a warning. This PR keeps that property, only adding the new check
when it is known to fail. I checked the imports in this file and the
other ones seem fine.
  • Loading branch information
hauntsaninja committed May 6, 2024
1 parent 9de49c8 commit 95f31f2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
22 changes: 21 additions & 1 deletion crates/uv-interpreter/python/get_interpreter_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ def format_full_version(info):


if sys.version_info[0] < 3:
print(json.dumps({"result": "error", "kind": "unsupported_python_version"}))
print(
json.dumps(
{
"result": "error",
"kind": "unsupported_python_version",
"python_version": format_full_version(sys.version_info),
}
)
)
sys.exit(0)

if hasattr(sys, "implementation"):
Expand Down Expand Up @@ -435,6 +443,18 @@ def get_operating_system_and_architecture():
architecture = version_arch

if operating_system == "linux":
if sys.version_info < (3, 7):
print(
json.dumps(
{
"result": "error",
"kind": "unsupported_python_version",
"python_version": format_full_version(sys.version_info),
}
)
)
sys.exit(0)

# noinspection PyProtectedMember
from .packaging._manylinux import _get_glibc_version

Expand Down
2 changes: 1 addition & 1 deletion crates/uv-interpreter/src/find_python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ fn find_python(
Ok(interpreter) => interpreter,
Err(
err @ Error::QueryScript {
err: InterpreterInfoError::UnsupportedPythonVersion,
err: InterpreterInfoError::UnsupportedPythonVersion { .. },
..
},
) => {
Expand Down
4 changes: 2 additions & 2 deletions crates/uv-interpreter/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ pub enum InterpreterInfoError {
LibcNotFound,
#[error("Unknown operation system: `{operating_system}`")]
UnknownOperatingSystem { operating_system: String },
#[error("Python 2 is not supported. Please use Python 3.8 or newer.")]
UnsupportedPythonVersion,
#[error("Python {python_version} is not supported. Please use Python 3.8 or newer.")]
UnsupportedPythonVersion { python_version: String },
}

#[derive(Debug, Deserialize, Serialize, Clone)]
Expand Down

0 comments on commit 95f31f2

Please sign in to comment.