GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — PteraSoftware/scripts/check_pinned_versions.py at main · camUrban/PteraSoftware Expand file tree/ Copy pathcheck_pinned_versions.pyMore file actions 65 lines (54 loc) · 2.29 KB / Copy pathcheck_pinned_versions.pyFile metadata and controls65 lines (54 loc) · 2.29 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 """Verify that the environment holds the versions pinned in requirements_dev.txt. The mypy hook runs with language: system, so pre-commit executes whatever tool versions the active virtual environment holds instead of managing pinned copies itself. This hook closes that gap: it reads every exact pin (==) from requirements_dev.txt, compares each against the version installed in the running environment, and fails with a reinstall hint when any package is missing or has drifted from its pin. """ import re import sys from importlib import metadata from pathlib import Path PIN_PATTERN = re.compile(r"^\s*([A-Za-z0-9][A-Za-z0-9._-]*)\s*==\s*([^\s;#]+)") def read_pins(path: Path) -> dict[str, str]: """Returns the exact version pins from a requirements file. :param path: The path to the requirements file to read. :return: A dict mapping each exactly pinned (==) package name to its pinned version. Packages with range constraints are not included. """ pins: dict[str, str] = {} for line in path.read_text().splitlines(): match = PIN_PATTERN.match(line) if match: pins[match.group(1)] = match.group(2) return pins def main() -> int: """Checks each pinned package's installed version and prints any mismatches. :return: An int representing the exit code, which is 0 if every pinned package is installed at its pinned version and 1 otherwise. """ requirements_path = Path("requirements_dev.txt") problems: list[str] = [] for name, pinned in read_pins(requirements_path).items(): try: installed = metadata.version(name) except metadata.PackageNotFoundError: problems.append( f"{requirements_path} pins {name} == {pinned}, but it is not" " installed in the active environment." ) continue if installed != pinned: problems.append( f"{requirements_path} pins {name} == {pinned}, but the active" f" environment has {installed}." ) if problems: for problem in problems: print(problem) print() print("Re-run: pip install -r requirements.txt -r requirements_dev.txt") return 1 return 0 if __name__ == "__main__": sys.exit(main()) |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |