|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import re |
| 4 | +import tomllib |
| 5 | +from pathlib import Path |
| 6 | + |
| 7 | +ROOT = Path(__file__).resolve().parents[1] |
| 8 | +SETUPTOOLS_FLOOR = (83, 0, 0) |
| 9 | + |
| 10 | + |
| 11 | +def _version_tuple(value: str) -> tuple[int, ...]: |
| 12 | + return tuple(int(part) for part in value.split(".")) |
| 13 | + |
| 14 | + |
| 15 | +def test_setuptools_security_floor_is_declared_at_each_dependabot_boundary() -> None: |
| 16 | + project = tomllib.loads((ROOT / "pyproject.toml").read_text(encoding="utf-8")) |
| 17 | + build_requirements = project["build-system"]["requires"] |
| 18 | + root_match = next( |
| 19 | + re.fullmatch(r"setuptools==([0-9]+(?:\.[0-9]+)*)", requirement) |
| 20 | + for requirement in build_requirements |
| 21 | + if requirement.startswith("setuptools") |
| 22 | + ) |
| 23 | + assert root_match is not None |
| 24 | + |
| 25 | + docs_requirements = (ROOT / "docs" / "requirements-docs.txt").read_text( |
| 26 | + encoding="utf-8" |
| 27 | + ) |
| 28 | + docs_match = re.search( |
| 29 | + r"^setuptools>=([0-9]+(?:\.[0-9]+)*),<([0-9]+)$", |
| 30 | + docs_requirements, |
| 31 | + flags=re.MULTILINE, |
| 32 | + ) |
| 33 | + assert docs_match is not None |
| 34 | + |
| 35 | + root_version = _version_tuple(root_match.group(1)) |
| 36 | + docs_floor = _version_tuple(docs_match.group(1)) |
| 37 | + assert root_version >= SETUPTOOLS_FLOOR |
| 38 | + assert docs_floor == root_version |
| 39 | + assert int(docs_match.group(2)) == root_version[0] + 1 |
0 commit comments