File size: 3,174 Bytes
2743961
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""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())