diff --git a/scripts/generate_pack.py b/scripts/generate_pack.py index 4039b1655..ec84947a7 100644 --- a/scripts/generate_pack.py +++ b/scripts/generate_pack.py @@ -12,6 +12,13 @@ and 3-tier storage (embedded/external/user_provided). from __future__ import annotations +import sys + +# The README's first command. Under 3.8 it stopped on a SyntaxError that read +# like a damaged file. The build needs 3.9, as pipeline.py says. +if sys.version_info < (3, 9): + sys.exit(f"generate_pack.py needs Python 3.9 or newer, this is {sys.version.split()[0]}") + from collections.abc import Callable, Iterable, Iterator from artifacts import _build_timestamp, set_plain_mode @@ -23,7 +30,6 @@ import json import os import re import shutil -import sys import tempfile import zipfile from pathlib import Path @@ -5079,10 +5085,8 @@ def inject_manifest(zip_path: str, manifest: dict) -> None: with zipfile.ZipFile(scratch, "a", zipfile.ZIP_DEFLATED) as zf: _write_generated_member(zf, "manifest.json", manifest_json) else: - with ( - zipfile.ZipFile(zip_path, "r") as src, - zipfile.ZipFile(scratch, "w", zipfile.ZIP_DEFLATED) as dst, - ): + with zipfile.ZipFile(zip_path, "r") as src, \ + zipfile.ZipFile(scratch, "w", zipfile.ZIP_DEFLATED) as dst: for item in src.infolist(): if item.filename == "manifest.json": continue diff --git a/scripts/pipeline.py b/scripts/pipeline.py index 798f6b861..1ee445c71 100644 --- a/scripts/pipeline.py +++ b/scripts/pipeline.py @@ -57,8 +57,8 @@ import tempfile import time from pathlib import Path -# generate_pack's parenthesized context managers do not compile before -# CPython 3.9, which builds the same database, manifests and packs as 3.12. +# The build scripts need CPython 3.9, which builds the same database, +# manifests and packs as 3.12. # On an older interpreter the run got through the first steps and failed in # the packs, so it stops before step 0. A test compiles every script under # this floor. diff --git a/tests/test_audit_regressions.py b/tests/test_audit_regressions.py index 267e4b28c..d22888989 100644 --- a/tests/test_audit_regressions.py +++ b/tests/test_audit_regressions.py @@ -118,6 +118,24 @@ class ReadmeRegressions(unittest.TestCase): self.assertEqual(proc.returncode, 1) self.assertIn("needs Python 3.9", proc.stderr) + def test_the_readme_build_command_names_the_floor(self): + """The README's first command is generate_pack.py. Under 3.8 it + stopped on a raw SyntaxError at a parenthesized `with`.""" + import shutil # noqa: PLC0415 + + python38 = shutil.which("python3.8") + if python38 is None: + if os.environ.get("CI"): + self.fail("CI must provide python3.8") + self.skipTest("no python3.8 on PATH") + proc = subprocess.run( + [python38, "-I", "scripts/generate_pack.py", "--help"], + cwd=ROOT, capture_output=True, text=True, timeout=60, check=False, + ) + self.assertEqual(proc.returncode, 1) + self.assertNotIn("SyntaxError", proc.stderr) + self.assertIn("generate_pack.py needs Python 3.9", proc.stderr) + def test_the_floor_interpreter_imports_every_script(self): """Every module under scripts/ is loaded by a real interpreter of the floor version, as the installer's 3.8 floor is proven by running it.