Files
soleprint/soleprint/atlas2/docgen/cli/check.py

51 lines
1.6 KiB
Python

"""
python3 -m docgen check docgen's own suite
python3 -m docgen check <book-dir> that book's own level
python3 -m docgen check <book-dir> --only generated|custom
Two of docgen's three test levels, told apart by what they assert *about*. The
third, the machine, is `make doctor`, and never fails.
"""
import argparse
import json
import subprocess
import sys
from pathlib import Path
from .common import PROG, Abort
HERE = Path(__file__).resolve().parent.parent
def main(argv) -> int:
p = argparse.ArgumentParser(prog=f"{PROG} check")
p.add_argument("book", type=Path, nargs="?",
help="A book directory (holding book.json). Omit for docgen's own suite.")
p.add_argument("--only", choices=("generated", "custom"),
help="With a book: run one half rather than both.")
args = p.parse_args(argv)
if args.book is None:
if args.only:
raise Abort("--only applies to a book")
# A subprocess rather than an import: the suite is a script that runs at
# import time and exits, and it has to see a clean interpreter to test
# what a fresh one would do.
return subprocess.call([sys.executable, str(HERE / "selftest.py")])
from ..book.checks import Loaded, Report, custom, generated
try:
book = Loaded(args.book)
except (FileNotFoundError, json.JSONDecodeError) as e:
raise Abort(str(e)) from None
print(f"{book.dir}{book.data.get('slug', '?')}")
r = Report()
if args.only != "custom":
generated(book, r)
if args.only != "generated":
custom(book, r)
return r.total()