diff --git a/scripts/ensure_min_python_is_tested.py b/scripts/ensure_min_python_is_tested.py index 279e839b8..67f5bb312 100644 --- a/scripts/ensure_min_python_is_tested.py +++ b/scripts/ensure_min_python_is_tested.py @@ -1,6 +1,8 @@ -#!/usr/bin/env python -# requires that a YAML implementation is available in order to extract github -# workflows data +# this script can only be called via +# tox -e check-min-python-is-tested +# +# no other usages are supported +import os import pathlib import subprocess import sys @@ -17,8 +19,18 @@ YAML = ruamel.yaml.YAML(typ="safe") REPO_ROOT = pathlib.Path(__file__).parent.parent +try: + VENV_CACHE_DIR = os.environ["VENV_CACHE_DIR"] +except KeyError: + raise RuntimeError( + "Cannot run ensure_min_python_is_tested.py without explicitly " + "setting VENV_CACHE dir. " + "Please ensure that you are invoking it with " + "'tox r -e check-min-python-is-tested'." + ) + proc = subprocess.run( - ["python", "scripts/get_python_requires.py"], + ["python", "scripts/get_python_requires.py", "--venv-cache-dir", VENV_CACHE_DIR], check=True, capture_output=True, cwd=REPO_ROOT, diff --git a/scripts/get_python_requires.py b/scripts/get_python_requires.py index df9709387..bdb615557 100644 --- a/scripts/get_python_requires.py +++ b/scripts/get_python_requires.py @@ -33,19 +33,26 @@ help="How to output the python_requires data. " "The default ('lower-bound') mode will print only the lower bound version number.", ) +parser.add_argument( + "--venv-cache-dir", + default=None, + help="A directory in which the 'build' virtualenv will be kept for reuse.", +) args = parser.parse_args() -if platform.system() == "Windows": - win_cache_dir = os.getenv("LOCALAPPDATA", os.getenv("APPDATA")) - assert win_cache_dir, "cannot find APPDATA dir, cannot cache, abort!" - cache_dir = pathlib.Path(win_cache_dir) +if args.venv_cache_dir: + VENV_CACHE_DIR = pathlib.Path(args.venv_cache_dir) else: - cache_dir = pathlib.Path.home() / ".cache" - -VENV_CACHE_DIR = cache_dir / "get_python_requires" + if platform.system() == "Windows": + win_cache_dir = os.getenv("LOCALAPPDATA", os.getenv("APPDATA")) + assert win_cache_dir, "cannot find APPDATA dir, cannot cache, abort!" + cache_dir = pathlib.Path(win_cache_dir) + else: + cache_dir = pathlib.Path.home() / ".cache" + VENV_CACHE_DIR = cache_dir / "get_python_requires" VENV_CACHE_DIR.mkdir(exist_ok=True) -BUILD_VENV = VENV_CACHE_DIR / "venv-build" +BUILD_VENV = VENV_CACHE_DIR / "get-python-requires-build" BUILD_PYTHON = str(BUILD_VENV / "bin" / "python") if BUILD_VENV.exists(): if args.verbose: diff --git a/tox.ini b/tox.ini index a534188e3..6502782d9 100644 --- a/tox.ini +++ b/tox.ini @@ -105,6 +105,8 @@ description = Check the Requires-Python metadata against CI config skip_install = true deps = ruamel.yaml<0.18 commands = python scripts/ensure_min_python_is_tested.py +setenv = + VENV_CACHE_DIR={envdir} [testenv:prepare-release] skip_install = true