AnthropicallyHuggingFaces's picture
Add CLI entrypoint
7444982 verified
Raw History Blame Contribute Delete
1.68 kB
"""
cli.py — Headless ingestion, for scheduled Hub Jobs.
Usage:
python cli.py --python-file src.py --module utils --repo OWNER/NAME
python cli.py --github owner repo path --repo OWNER/NAME
"""
from __future__ import annotations
import argparse
import sys
from ingest import ingest_python_source, ingest_github_file
from pipeline import run, DEFAULT_DATASET_ID
def main() -> int:
p = argparse.ArgumentParser(description="Ingest functions/skills into a HF dataset.")
p.add_argument("--python-file", help="Path to a local Python file")
p.add_argument("--module", default="cli", help="Category/module label")
p.add_argument("--github", nargs=3, metavar=("OWNER", "REPO", "PATH"),
help="Extract from a raw GitHub file")
p.add_argument("--ref", default="main")
p.add_argument("--repo", default=DEFAULT_DATASET_ID, help="Target dataset repo")
p.add_argument("--private", action="store_true")
args = p.parse_args()
records = []
if args.python_file:
with open(args.python_file, "r", encoding="utf-8") as fh:
records += ingest_python_source(fh.read(), module=args.module,
source_url=args.python_file)
if args.github:
owner, repo, path = args.github
records += ingest_github_file(owner, repo, path, args.ref)
if not records:
print("No records produced. Provide --python-file or --github.", file=sys.stderr)
return 1
result = run(records, repo_id=args.repo, private=args.private)
print(f"Deployed {result['rows']} rows -> {result['url']}")
return 0
if __name__ == "__main__":
raise SystemExit(main())