From 9aa26143ad4b16b78267af2f357bb174d11c9fe9 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Thu, 5 Nov 2026 12:08:54 +0100 Subject: [PATCH] fix: name the old Python the bootstrap found --- install.sh | 21 +++++++++++++++++++-- tests/test_install.py | 12 ++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 0c4263e04..0384b82f8 100755 --- a/install.sh +++ b/install.sh @@ -127,10 +127,18 @@ fi find_python() { PYTHON="" PYTHON_LACKING="" + PYTHON_OLD="" for command_name in python3 python; do command -v "$command_name" >/dev/null 2>&1 || continue - "$command_name" -c 'import sys; raise SystemExit(sys.version_info < (3, 8))' \ - 2>/dev/null || continue + if ! "$command_name" -c 'import sys; raise SystemExit(sys.version_info < (3, 8))' \ + 2>/dev/null; then + found_version=$("$command_name" -c \ + 'import sys; print("%d.%d.%d" % tuple(sys.version_info[:3]))' 2>/dev/null) + if [ -n "$found_version" ]; then + PYTHON_OLD=${PYTHON_OLD:-"$command_name here is $found_version"} + fi + continue + fi if "$command_name" -c 'import ssl, unicodedata, zlib' 2>/dev/null; then PYTHON=$command_name return 0 @@ -184,6 +192,15 @@ if [ -z "$PYTHON" ] && [ -n "$PYTHON_LACKING" ]; then echo " (ssl, unicodedata or zlib). Run it with a full Python 3.8 or newer." >&2 exit 1 fi +if [ -z "$PYTHON" ] && [ -n "$PYTHON_OLD" ]; then + # Debian Buster ships 3.7: apt answers that python3 is already the newest + # version, and the same advice looped. + echo "Error: Python 3.8 or newer is required, and $PYTHON_OLD." >&2 + echo " Install a newer one: from this system's packages if they offer one, by" >&2 + echo " updating the system, or from https://www.python.org/downloads/." >&2 + echo " Then run this command again." >&2 + exit 1 +fi if [ -z "$PYTHON" ]; then echo "Error: Python 3.8 or newer is required." >&2 if [ -n "$install_command" ]; then diff --git a/tests/test_install.py b/tests/test_install.py index 16c784f2c..651cb6023 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -2628,6 +2628,18 @@ class ABootstrapPythonCanDoHttps(unittest.TestCase): self.assertEqual(proc.returncode, 0, proc.stderr) self.assertIn("installer ran", proc.stdout) + def test_an_old_python_is_named_with_its_version(self): + """Debian Buster's python3 3.7 got "Install it with: sudo apt install + python3", which apt answers with "already the newest version".""" + root, fake_bin = self._bin() + (fake_bin / "python3").write_text( + '#!/bin/sh\ncase "$2" in *print*) echo 3.7.3 ;; esac\nexit 1\n') + proc = self._run(root, fake_bin) + self.assertEqual(proc.returncode, 1) + self.assertIn("Python 3.8 or newer is required, and python3 here is 3.7.3.", + proc.stderr) + self.assertNotIn("Install it with: sudo apt", proc.stderr) + def test_the_missing_module_is_named(self): root, fake_bin = self._bin() proc = self._run(root, fake_bin)