Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/refresh-release-bundle.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added `policyengine.provenance.refresh_release_bundle`. Given a country and optional new model/data versions, the helper fetches the updated PyPI wheel metadata + HF dataset sha256, rewrites `data/release_manifests/{country}.json` and the matching extra pin in `pyproject.toml`, and (optionally) regenerates the bundle's TRACE TRO sidecar. A thin `scripts/refresh_release_bundle.py` wrapper exposes the library function as a CLI for release engineers. Unit-tested offline via mocked PyPI/HF responses.
79 changes: 79 additions & 0 deletions scripts/refresh_release_bundle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
"""CLI wrapper around :func:`policyengine.provenance.refresh_release_bundle`.

Usage::

python scripts/refresh_release_bundle.py --country us \\
--model-version 1.653.3 --data-version 1.83.4

Fetches PyPI wheel metadata and streams the HF dataset to compute its
sha256, then writes updated ``data/release_manifests/{country}.json``,
bumps the matching pin in ``pyproject.toml`` (unless
``--no-pyproject``), and regenerates the bundle's TRACE TRO sidecar
(unless ``--no-tro``).

Private HF datasets require ``HUGGING_FACE_TOKEN`` in the env.

After running:

- commit the changed manifest / TRO / pyproject.toml,
- manually rerun
``PE_UPDATE_SNAPSHOTS=1 pytest tests/test_household_calculator_snapshot.py``
to rebaseline expected household outputs — those numbers will
almost certainly drift when the data version bumps, and the drift
deserves human review before being committed.
"""

from __future__ import annotations

import argparse
import sys

from policyengine.provenance.bundle import (
refresh_release_bundle,
regenerate_trace_tro,
)


def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--country", required=True, choices=("us", "uk"))
parser.add_argument(
"--model-version",
help="New policyengine-{country} version (e.g. 1.653.3)",
)
parser.add_argument(
"--data-version",
help="New policyengine-{country}-data version (e.g. 1.83.4)",
)
parser.add_argument(
"--no-pyproject",
action="store_true",
help="Do not bump the country extra in pyproject.toml",
)
parser.add_argument(
"--no-tro",
action="store_true",
help="Skip TRACE TRO regeneration",
)
args = parser.parse_args(argv)

if args.model_version is None and args.data_version is None:
parser.error("Pass at least --model-version or --data-version")

result = refresh_release_bundle(
country=args.country,
model_version=args.model_version,
data_version=args.data_version,
update_pyproject=not args.no_pyproject,
)
print(result.summary())

if not args.no_tro:
tro_path = regenerate_trace_tro(args.country)
print(f" TRO regenerated: {tro_path}")

return 0


if __name__ == "__main__":
sys.exit(main())
3 changes: 3 additions & 0 deletions src/policyengine/provenance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
)
"""

from .bundle import RefreshResult as RefreshResult
from .bundle import refresh_release_bundle as refresh_release_bundle
from .bundle import regenerate_trace_tro as regenerate_trace_tro
from .manifest import (
CertifiedDataArtifact as CertifiedDataArtifact,
)
Expand Down
Loading
Loading