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 — policyengine.py/scripts/bundle.py at main · PolicyEngine/policyengine.py Expand file tree/ Copy pathbundle.pyMore file actions 386 lines (342 loc) · 12.9 KB / Copy pathbundle.pyFile metadata and controls386 lines (342 loc) · 12.9 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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 """PolicyEngine bundle maintenance entry point. This script is the operator-facing wrapper around the lower-level bundle maintenance scripts. It keeps the main workflows discoverable for humans and AI agents while preserving the smaller implementation modules underneath. Examples: python scripts/bundle.py update-packages --us 1.730.0 --uk 2.91.0 python scripts/bundle.py certify-data --country uk --manifest-uri hf://... python scripts/bundle.py generate python scripts/bundle.py generate --include-tros python scripts/bundle.py check """ from __future__ import annotations import argparse import os import sys from pathlib import Path REPO_ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(REPO_ROOT / "scripts")) sys.path.insert(0, str(REPO_ROOT / "src")) def _certify_data(args: argparse.Namespace) -> int: from certify_data_release import main as certify_data_release_main argv = [ "--country", args.country, "--manifest-uri", args.manifest_uri, ] if args.data_producer: argv.extend(["--data-producer", args.data_producer]) if args.model_version: argv.extend(["--model-version", args.model_version]) if args.regional_manifest_uri: argv.extend(["--regional-manifest-uri", args.regional_manifest_uri]) if args.regional_artifact_prefix: argv.extend(["--regional-artifact-prefix", args.regional_artifact_prefix]) if args.regional_path_template: argv.extend(["--regional-path-template", args.regional_path_template]) if args.regional_release_kind: argv.extend(["--regional-release-kind", args.regional_release_kind]) if args.drop_regional_release: argv.append("--drop-regional-release") if args.accept_regional_model_mismatch is not None: argv.extend( ["--accept-regional-model-mismatch", args.accept_regional_model_mismatch] ) if args.regional_input_surface_evidence: argv.extend( ["--regional-input-surface-evidence", args.regional_input_surface_evidence] ) if args.no_generate: argv.append("--no-generate") if args.no_changelog: argv.append("--no-changelog") if args.skip_artifact_check: argv.append("--skip-artifact-check") if args.core_version: argv.extend(["--core-version", args.core_version]) if args.qualified_pair_id: argv.extend(["--qualified-pair-id", args.qualified_pair_id]) return certify_data_release_main(argv) def _update_packages(args: argparse.Namespace) -> int: from prepare_package_bundle_update import main as prepare_package_bundle_update_main argv: list[str] = [] for option in ("core", "us", "uk"): value = getattr(args, option) if value: argv.extend([f"--{option.replace('_', '-')}", value]) if args.changelog: argv.extend(["--changelog", args.changelog]) if args.fragment_name: argv.extend(["--fragment-name", args.fragment_name]) return prepare_package_bundle_update_main(argv) def _generate(args: argparse.Namespace) -> int: from generate_bundle_artifacts import generate result = generate(check=False) if not args.include_tros: return result return _generate_tros(strict=args.strict_tros) def _check(args: argparse.Namespace) -> int: from generate_bundle_artifacts import ( generate, load_bundle_manifest, validate_bundle_measurements, validate_dataset_overlays, ) bundle = load_bundle_manifest() validate_bundle_measurements(bundle, require_published_spm=args.published_spm) validate_dataset_overlays(bundle) result = generate(check=True) if not args.include_tros: return result return result or _check_tros(strict=args.strict_tros) def _set_spm(args: argparse.Namespace) -> int: from generate_bundle_artifacts import ( generate, load_bundle_manifest, write_bundle_manifest, ) from spm_bundle import configure_spm, published_calculator_component calculator = ( published_calculator_component(args.calculator_version) if args.calculator_version else None ) settings = { key: getattr(args, key) for key in ( "forecast_content_sha256", "scenario", "geography_kind", "geography_id", "county_vintage", "as_of", ) } write_bundle_manifest(configure_spm(load_bundle_manifest(), settings, calculator)) return generate(check=False) def _development_manifest(args: argparse.Namespace) -> int: from generate_bundle_artifacts import load_bundle_manifest from spm_bundle import write_development_manifest write_development_manifest( load_bundle_manifest(), args.country_wheel, args.calculator_wheel, args.output ) print(f"Wrote uncertified local development fixture {args.output}") return 0 def _generate_tros(*, strict: bool = False) -> int: os.environ.setdefault("POLICYENGINE_SKIP_COUNTRY_IMPORTS", "1") from generate_trace_tros import regenerate_all written, regressions = regenerate_all(strict=strict) for path in written: print(f"wrote {path}") for country_id, tro_path, reason in regressions: print( f"error: {country_id} already has {tro_path.name} but regeneration " f"failed: {reason}", file=sys.stderr, ) if regressions: return 1 if not written: print("no countries could be regenerated (all skipped)", file=sys.stderr) return 0 def _check_tros(*, strict: bool = False) -> int: os.environ.setdefault("POLICYENGINE_SKIP_COUNTRY_IMPORTS", "1") from generate_trace_tros import generated_tros changed = False for path, payload in generated_tros(strict=strict): if path.exists() and path.read_bytes() == payload: continue print( f"{path.relative_to(REPO_ROOT)} is not up to date.", file=sys.stderr, ) changed = True return 1 if changed else 0 def _parser() -> argparse.ArgumentParser: parser = argparse.ArgumentParser( description="Maintain PolicyEngine bundle metadata and derived artifacts." ) subparsers = parser.add_subparsers(dest="command", required=True) certify = subparsers.add_parser( "certify-data", help="Certify a country data release into the bundle manifest.", ) certify.add_argument("--country", required=True, choices=["us", "uk"]) certify.add_argument( "--data-producer", choices=["legacy", "populace"], help="Data-producer strategy. Defaults to the certification script default.", ) certify.add_argument( "--manifest-uri", required=True, help="hf://dataset/<repo_id>@<revision>/<path-to-release_manifest.json>", ) certify.add_argument( "--model-version", help="Model package version to certify for. Defaults to installed metadata.", ) certify.add_argument( "--regional-manifest-uri", help=( "Regional release_manifest.json URI whose dataset serves the local " "region types (US states and districts, UK constituencies and local " "authorities)." ), ) certify.add_argument( "--regional-release-kind", help=( "How to read the regional release; forwarded to " "scripts/certify_data_release.py, which lists and checks the kinds. " "Defaults to local_area." ), ) certify.add_argument( "--drop-regional-release", action="store_true", help=( "Remove the bundle's current regional routing on re-certification. " "Cannot be combined with --regional-manifest-uri." ), ) certify.add_argument( "--accept-regional-model-mismatch", metavar="REASON", help=( "UK or US: route regions to a regional release on another model " "version, recording this reviewed reason; forwarded to " "scripts/certify_data_release.py." ), ) certify.add_argument( "--regional-input-surface-evidence", help="Audited regional input-surface JSON; required for an accepted mismatch.", ) certify.add_argument( "--regional-artifact-prefix", help="Legacy per-state artifact prefix to import. Defaults to states/.", ) certify.add_argument( "--regional-path-template", help="Legacy per-state dataset path template to certify.", ) certify.add_argument( "--no-generate", action="store_true", help="Do not regenerate pyproject.toml and derived bundle metadata.", ) certify.add_argument( "--no-changelog", action="store_true", help="Do not write a Towncrier changelog fragment.", ) certify.add_argument( "--skip-artifact-check", action="store_true", help=( "Skip reachability checks for the certified dataset and any " "vendored/regional artifacts." ), ) certify.add_argument( "--core-version", help="policyengine-core version to check against core claims and pin.", ) certify.add_argument( "--qualified-pair-id", help="Admit the exact pair on automated qualification (needs --core-version).", ) certify.set_defaults(func=_certify_data) packages = subparsers.add_parser( "update-packages", help="Update package pins in the bundle manifest.", ) packages.add_argument("--core", help="Exact version for policyengine-core.") packages.add_argument("--us", help="Exact version for policyengine-us.") packages.add_argument("--uk", help="Exact version for policyengine-uk.") packages.add_argument( "--changelog", default="Update the certified PolicyEngine bundle pins.", help="Patch changelog text to include with the bundle update.", ) packages.add_argument( "--fragment-name", default="bundle-update.fixed.md", help="Changelog fragment filename under changelog.d/.", ) packages.set_defaults(func=_update_packages) spm = subparsers.add_parser( "set-spm", help="Stage SPM defaults and optional verified PyPI calculator pin." ) spm.add_argument("--forecast-content-sha256", required=True) spm.add_argument("--scenario", required=True) spm.add_argument( "--geography-kind", choices=["county", "metro", "national"], default="county" ) spm.add_argument("--geography-id") spm.add_argument("--county-vintage", default="2020") spm.add_argument("--as-of") spm.add_argument( "--calculator-version", help="Verify actual published wheel bytes before adding the runtime dependency.", ) spm.set_defaults(func=_set_spm) development = subparsers.add_parser( "development-manifest", help="Write an uncertified fixture using actual local wheel metadata.", ) development.add_argument("--country-wheel", required=True, type=Path) development.add_argument("--calculator-wheel", required=True, type=Path) development.add_argument("--output", required=True, type=Path) development.set_defaults(func=_development_manifest) generate = subparsers.add_parser( "generate", help="Regenerate derived bundle artifacts.", ) generate.add_argument( "--include-tros", action="store_true", help=( "Also regenerate TRACE TRO sidecars. Private data releases require " "HUGGING_FACE_TOKEN or HF_TOKEN." ), ) generate.set_defaults(func=_generate) check = subparsers.add_parser( "check", help="Check derived bundle metadata.", ) check.add_argument( "--published-spm", action="store_true", help="Check SPM measurement pins include a published hashed calculator; does not certify country/data compatibility or release readiness.", ) check.add_argument( "--include-tros", action="store_true", help=( "Also check TRACE TRO sidecars. Private data releases require " "HUGGING_FACE_TOKEN or HF_TOKEN." ), ) check.set_defaults(func=_check) for command in (generate, check): command.add_argument( "--strict-tros", action="store_true", help="Require full authenticated manifests matching reviewed TRO source pins; requires --include-tros.", ) return parser def main(argv: list[str] | None = None) -> int: parser = _parser() args = parser.parse_args(argv) if getattr(args, "strict_tros", False) and not args.include_tros: parser.error("--strict-tros requires --include-tros") try: return args.func(args) except ValueError as exc: parser.error(str(exc)) if __name__ == "__main__": raise SystemExit(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. |