Download recipe/cli.py from ZipLime/fomc-events: direct link, hf CLI and curl.
- Browser
- Download file 3.17 kB
-
https://huggingface.co/datasets/ZipLime/fomc-events/resolve/main/recipe/cli.py
- Command line
-
hf download hf://datasets/ZipLime/fomc-events/recipe/cli.py
-
curl -L -o cli.py https://huggingface.co/datasets/ZipLime/fomc-events/resolve/main/recipe/cli.py
3.17 kB
| """Command line for the FOMC events recipe.""" | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| import logging | |
| from pathlib import Path | |
| from .config import Settings | |
| def main(argv: list[str] | None = None) -> int: | |
| parser = argparse.ArgumentParser(prog="fomc-events", description=__doc__) | |
| sub = parser.add_subparsers(dest="command", required=True) | |
| build = sub.add_parser("build", help="discover, fetch, parse, project, verify") | |
| build.add_argument( | |
| "--limit", type=int, default=None, help="read only the newest N meetings, for development" | |
| ) | |
| build.add_argument( | |
| "--rebuild", | |
| action="store_true", | |
| help="re-fetch the calendar pages and re-read every document rather than using the cache", | |
| ) | |
| sub.add_parser("verify", help="run the quality gate and write the manifest") | |
| publish = sub.add_parser("publish", help="mirror the built tree to Hugging Face") | |
| publish.add_argument("--repo", default=None) | |
| args = parser.parse_args(argv) | |
| logging.basicConfig( | |
| level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s | %(message)s" | |
| ) | |
| settings = Settings.from_env() | |
| data_dir = Path(settings.data_dir) | |
| if args.command == "build": | |
| from .manifest import build_manifest | |
| from .pipeline import run_build | |
| from .quality import validate | |
| result = run_build(settings=settings, limit=args.limit, rebuild=args.rebuild) | |
| report = validate(data_dir) | |
| report.write(data_dir.resolve().parent / "quality_report.json") | |
| build_manifest(data_dir=data_dir, row_counts=result.counts, quality_ok=report.ok) | |
| print( | |
| json.dumps( | |
| { | |
| "rows": result.counts, | |
| "quarantined": len(result.quarantined), | |
| "quality_ok": report.ok, | |
| "errors": report.errors, | |
| "warnings": report.warnings, | |
| }, | |
| indent=2, | |
| ) | |
| ) | |
| return 0 if report.ok else 1 | |
| if args.command == "verify": | |
| from .manifest import build_manifest | |
| from .quality import validate | |
| from .store import config_row_counts | |
| report = validate(data_dir) | |
| report.write(data_dir.resolve().parent / "quality_report.json") | |
| build_manifest( | |
| data_dir=data_dir, row_counts=config_row_counts(data_dir), quality_ok=report.ok | |
| ) | |
| print(json.dumps(report.as_dict(), indent=2, default=str)) | |
| return 0 if report.ok else 1 | |
| if args.command == "publish": | |
| from .publish import hf_token, publish_to_hf | |
| from .quality import validate | |
| report = validate(data_dir) | |
| if not report.ok: | |
| print(json.dumps({"quality_ok": False, "errors": report.errors}, indent=2)) | |
| return 1 | |
| commit = publish_to_hf( | |
| project_root=data_dir.resolve().parent, | |
| repo_id=args.repo or settings.hf_repo, | |
| token=hf_token(), | |
| ) | |
| print(json.dumps({"commit": commit}, indent=2)) | |
| return 0 | |
| return 1 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |