Debian Codegraph @

tests/unit_tests/test_packaging.py

raw
1 """The hsql metapackage ships with Harlequin, so its version tracks Harlequin's.
2
3 `hsql` is a distribution that contains nothing but a dependency on `harlequin`
4 and the `hsql` console script Harlequin provides. One release goes out per
5 Harlequin release, carrying the same version number and pinning that release
6 exactly -- so `pip install hsql==2.9.0` and `pip install harlequin==2.9.0`
7 install the same two commands, and the number means one thing.
8
9 That is three values in two files that have to agree. `release.yml` sets all
10 three; this is what notices when something else didn't, on the release PR
11 rather than after the upload, since PyPI does not take a version back.
12 """
13
14 from __future__ import annotations
15
16 import sys
17 from pathlib import Path
18 from typing import Any, cast
19
20 if sys.version_info >= (3, 11):
21 import tomllib
22 else:
23 import tomli as tomllib
24
25 REPO_ROOT = Path(__file__).resolve().parents[2]
26 HARLEQUIN_PYPROJECT = REPO_ROOT / "pyproject.toml"
27 HSQL_PYPROJECT = REPO_ROOT / "packaging" / "hsql" / "pyproject.toml"
28
29 # what the release workflow runs, and what to run by hand after editing either
30 # version. --frozen because the pin names a release that does not exist yet.
31 FIX = (
32 "uv version --project packaging/hsql --frozen VERSION && "
33 "uv add --project packaging/hsql --frozen harlequin==VERSION"
34 )
35
36
37 def _project(path: Path) -> dict[str, Any]:
38 with path.open("rb") as f:
39 return cast("dict[str, Any]", tomllib.load(f)["project"])
40
41
42 def test_hsql_metapackage_tracks_harlequin_version() -> None:
43 harlequin = _project(HARLEQUIN_PYPROJECT)
44 hsql = _project(HSQL_PYPROJECT)
45 fix = FIX.replace("VERSION", harlequin["version"])
46
47 assert hsql["version"] == harlequin["version"], (
48 f"the hsql metapackage's version must match Harlequin's: {fix}"
49 )
50
51 (dependency,) = hsql["dependencies"]
52 assert dependency == f"harlequin=={harlequin['version']}", (
53 f"the hsql metapackage must pin this release of Harlequin exactly: {fix}"
54 )
55
56
57 def test_hsql_metapackage_declares_harlequins_console_script() -> None:
58 """Both distributions must name the same entry point.
59
60 Two distributions providing one script name is fine only while the scripts
61 are byte-identical -- point this at anything else and whichever installs
62 second silently wins.
63 """
64 harlequin = _project(HARLEQUIN_PYPROJECT)
65 hsql = _project(HSQL_PYPROJECT)
66
67 assert hsql["scripts"] == {"hsql": harlequin["scripts"]["hsql"]}