|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +"""#2062: the setuptools floor is one that ships ``pcapkit/py.typed``. |
| 3 | +
|
| 4 | +Nothing declares ``py.typed``: :file:`MANIFEST.in` includes ``*.py`` alone, and |
| 5 | +:file:`pyproject.toml` has no ``package-data`` entry for ``pcapkit``. setuptools |
| 6 | +69.0.0 is the first release that packages it regardless (pypa/setuptools#3136, |
| 7 | +in that release's ``NEWS.rst``), measured: a wheel built with 68.2.2 leaves it |
| 8 | +out, and one built with 69.0.0 has it. Pinned here: |
| 9 | +
|
| 10 | +* ``[build-system] requires`` floors setuptools at 69.0.0 or later; |
| 11 | +* every setuptools pin in :file:`conda/pypcapkit/meta.yaml` matches that floor. |
| 12 | +
|
| 13 | +These read the declarations, not a built wheel: they catch the floor being |
| 14 | +lowered again, not a later setuptools release dropping the behaviour. |
| 15 | +
|
| 16 | +""" |
| 17 | + |
| 18 | +from __future__ import annotations |
| 19 | + |
| 20 | +import pathlib |
| 21 | +import re |
| 22 | +import unittest |
| 23 | + |
| 24 | +try: |
| 25 | + import tomllib |
| 26 | +except ImportError: # pragma: no cover |
| 27 | + tomllib = None # type: ignore[assignment] |
| 28 | + |
| 29 | +#: Test tier (#1958): reads pyproject.toml and the conda recipe, the same on every leg. |
| 30 | +__tier__ = 'LATEST' |
| 31 | + |
| 32 | +ROOT = pathlib.Path(__file__).resolve().parents[2] |
| 33 | + |
| 34 | +#: The first setuptools that packages ``py.typed`` without being told to (#2062). |
| 35 | +FIRST_WITH_PY_TYPED = (69, 0, 0) |
| 36 | + |
| 37 | +#: A ``setuptools>=X.Y.Z`` requirement, as either file spells it. |
| 38 | +FLOOR = re.compile(r'^\s*(?:-\s*)?setuptools\s*>=\s*(\d+)\.(\d+)\.(\d+)\s*$') |
| 39 | + |
| 40 | + |
| 41 | +def floors(lines: 'list[str]') -> 'list[tuple[int, int, int]]': |
| 42 | + """Every ``setuptools>=`` floor in ``lines``.""" |
| 43 | + return [tuple(int(part) for part in match.groups()) # type: ignore[misc] |
| 44 | + for match in map(FLOOR.match, lines) if match] |
| 45 | + |
| 46 | + |
| 47 | +class SetuptoolsFloorTests(unittest.TestCase): |
| 48 | + """The build floor packages ``py.typed``, and conda agrees with it.""" |
| 49 | + |
| 50 | + def setUp(self) -> None: |
| 51 | + if tomllib is None: # pragma: no cover |
| 52 | + self.skipTest('tomllib needs Python 3.11') |
| 53 | + pyproject = tomllib.loads((ROOT / 'pyproject.toml').read_text(encoding='utf-8')) |
| 54 | + requires = pyproject['build-system']['requires'] |
| 55 | + self.assertEqual([text for text in requires if text.startswith('setuptools')], |
| 56 | + [text for text in requires if FLOOR.match(text)], |
| 57 | + 'every setuptools requirement should be a plain ">=" floor') |
| 58 | + self.floors = floors(requires) |
| 59 | + |
| 60 | + def test_build_floor_ships_py_typed(self) -> None: |
| 61 | + self.assertEqual(len(self.floors), 1, self.floors) |
| 62 | + self.assertGreaterEqual(self.floors[0], FIRST_WITH_PY_TYPED, |
| 63 | + 'setuptools older than 69.0.0 builds wheels without pcapkit/py.typed') |
| 64 | + |
| 65 | + def test_conda_pins_match_the_build_floor(self) -> None: |
| 66 | + lines = (ROOT / 'conda' / 'pypcapkit' / 'meta.yaml').read_text(encoding='utf-8').splitlines() |
| 67 | + pins = floors(lines) |
| 68 | + self.assertTrue(pins, 'the conda recipe pins no setuptools floor') |
| 69 | + self.assertEqual(set(pins), set(self.floors)) |
| 70 | + |
| 71 | + def test_py_typed_exists(self) -> None: |
| 72 | + self.assertTrue((ROOT / 'pcapkit' / 'py.typed').is_file()) |
| 73 | + |
| 74 | + |
| 75 | +if __name__ == '__main__': |
| 76 | + unittest.main() |
0 commit comments