From 95f31f22669e18bc4b40c4bdd6f90884ed248edf Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Mon, 6 May 2024 02:12:36 -0700 Subject: [PATCH] Better error for unsupported Python version (#3398) 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. --- .../python/get_interpreter_info.py | 22 ++++++++++++++++++- crates/uv-interpreter/src/find_python.rs | 2 +- crates/uv-interpreter/src/interpreter.rs | 4 ++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/crates/uv-interpreter/python/get_interpreter_info.py b/crates/uv-interpreter/python/get_interpreter_info.py index 3d7283f57..0cc0a3fc0 100644 --- a/crates/uv-interpreter/python/get_interpreter_info.py +++ b/crates/uv-interpreter/python/get_interpreter_info.py @@ -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"): @@ -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 diff --git a/crates/uv-interpreter/src/find_python.rs b/crates/uv-interpreter/src/find_python.rs index 7b0cb7c27..fd986874e 100644 --- a/crates/uv-interpreter/src/find_python.rs +++ b/crates/uv-interpreter/src/find_python.rs @@ -152,7 +152,7 @@ fn find_python( Ok(interpreter) => interpreter, Err( err @ Error::QueryScript { - err: InterpreterInfoError::UnsupportedPythonVersion, + err: InterpreterInfoError::UnsupportedPythonVersion { .. }, .. }, ) => { diff --git a/crates/uv-interpreter/src/interpreter.rs b/crates/uv-interpreter/src/interpreter.rs index 03b487e3e..43b57f6cd 100644 --- a/crates/uv-interpreter/src/interpreter.rs +++ b/crates/uv-interpreter/src/interpreter.rs @@ -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)]