command.py¶
clew/wiki/command.py
`clew wiki` — the documentation subcommand.
_ears_notes
list[str] clew.wiki.command._ears_notes(Path repo, Path db, Path|None config_path)
The EARS notes for check , when the repository turned EARS on.
Source · 9 lines
def _ears_notes(repo: Path, db: Path, config_path: Path | None) -> list[str]:
"""@brief Read `wiki.check.ears`, then the index. @return Notes."""
from .config import load_wiki_config
from .ears import ears_notes
config, _problems = load_wiki_config(repo, config_path)
return ears_notes(db, config.ears)
Activity · 4 steps
Requirements
_markdown
int clew.wiki.command._markdown(argparse.Namespace args, Path db, Path repo, Path|None config)
Write the wiki as Markdown pages for a GitHub or Azure DevOps wiki.
Source · 21 lines
def _markdown(args: argparse.Namespace, db: Path, repo: Path, config: Path | None) -> int:
"""@brief Markdown build. @return Exit status."""
from .markdown import build_markdown
try:
out = build_markdown(
repo,
db,
Path(args.out),
args.flavor,
audience=args.audience,
config_path=config,
summary=Path(args.summary) if args.summary else None,
)
except ValueError as exc:
sys.stderr.write(f"clew wiki: refused — {exc}\n")
return 2
sys.stdout.write(f"{out}\n")
return 0
Activity · 8 steps
Requirements
_propose_modes
int clew.wiki.command._propose_modes(argparse.Namespace args, Path db, Path repo)
Print a failure-mode draft, or apply a reviewed one.
Source · 23 lines
def _propose_modes(args: argparse.Namespace, db: Path, repo: Path) -> int:
"""A REFUSED ENTRY IS NAMED AND THE RUN FAILS (2), so a review applied to a file that moved
on is never reported as done; the entries that did apply stay applied.
@brief propose-modes verb.
@return Exit status.
"""
import yaml
from .proposemodes import apply, proposals
if not args.apply:
draft = proposals(db, repo, args.files)
sys.stdout.write(yaml.safe_dump(draft, sort_keys=False, allow_unicode=True))
return 0
entries = yaml.safe_load(Path(args.apply).read_text(encoding="utf-8")) or []
written, refused = apply(repo, entries)
for line in refused:
sys.stderr.write(f"clew wiki: propose-modes refused — {line}\n")
sys.stdout.write(f"{written} marker(s) written\n")
return 2 if refused else 0
Activity · 12 steps
Requirements
_trace_run
int clew.wiki.command._trace_run(argparse.Namespace args)
Run one test traced, write its spans, print the run and its overlay.
Source · 27 lines
def _trace_run(args: argparse.Namespace) -> int:
"""THE OVERLAY NEEDS AN INDEX, the run does not: without one the spans and checkpoints are
still written and printed, and `overlay` is absent — never an empty comparison.
@brief Trace-run verb.
@return Exit status.
"""
from ..query_command import _locate
from .tracerun import overlay, trace_test
repo = Path(args.repo_root or Path.cwd()).resolve()
try:
run = trace_test(repo, args.test)
except (RuntimeError, OSError, subprocess.SubprocessError) as exc:
sys.stderr.write(f"clew wiki: trace-run refused — {exc}\n")
return 2
## 2.1 (found wiring this into CI): a fresh checkout has no `build/traces/`.
Path(args.out).parent.mkdir(parents=True, exist_ok=True)
Path(args.out).write_text(json.dumps(run["otlp"], indent=args.indent), encoding="utf-8")
report = {k: run[k] for k in ("passed", "checkpoints", "failure", "dropped")}
db, _repo = _locate(args)
if db.is_file():
report["overlay"] = overlay(expected_steps(db, repo, args.test), run["otlp"])
sys.stdout.write(json.dumps(report, indent=args.indent) + "\n")
return 0
Activity · 16 steps
Requirements
expected_steps
list[tuple[str, str]] clew.wiki.command.expected_steps(Path db, Path repo, str nodeid)
The index's expected flow for a test, as (caller, callee) pairs.
Source · 13 lines
def expected_steps(db: Path, repo: Path, nodeid: str) -> list[tuple[str, str]]:
"""@brief Expected steps. @return Pairs."""
from .flow import derive_flow
file, _, name = nodeid.partition("::")
name = name.split("::")[-1].split("[")[0]
try:
flow = derive_flow(db, repo, name, file=file, depth=2)
except ValueError:
return []
return [(s.caller, s.callee) for s in flow.steps]
Activity · 8 steps
Requirements
wiki_main
int clew.wiki.command.wiki_main(list[str] argv)
Entry point for clew wiki .
Called by main
Tested by 12 tests
test_check_refresh_brings_the_index_current_first, test_the_cli_check_exits_nonzero_on_a_problem, test_the_cli_creates_the_output_directory, test_the_cli_prints_the_flow_as_json, test_the_cli_prints_the_trace, test_the_cli_takes_an_out_of_tree_config, test_the_cli_writes_markdown_without_sphinx, test_the_cli_writes_otlp_json_and_the_overlay, test_the_command_prints_yaml_and_applies_a_reviewed_file, test_the_flow_verb_prints_svg, test_the_trace_cli_reads_imports_from_the_config, test_wiki_check_prints_ears_notes_without_failing_on_them
Calls _diff, _flow, _json, _parser, _propose_modes, _site, _trace, _trace_run, open_main, refresh_main, wiki_overlay
Source · 38 lines
def wiki_main(argv: list[str]) -> int:
"""@brief Dispatch a wiki verb. @return Exit status."""
from ..query_command import _locate
if argv[:1] == ["open"]:
from .open_command import open_main
return open_main(argv[1:])
args = _parser().parse_args(argv)
if args.verb == "diff":
return _diff(args)
if args.verb == "trace-run":
return _trace_run(args)
db, repo = _locate(args)
if getattr(args, "refresh", False):
from ..refresh_command import refresh_main
refresh_main(["--repo-root", str(repo or Path.cwd()), "--output", str(db)])
if not db.is_file():
sys.stderr.write(f"clew wiki: no index at {db} — build one with `clew --repo-root`\n")
return 1
if args.verb == "propose-modes":
return _propose_modes(args, db, repo or Path.cwd())
if args.verb in ("check", "build"):
from .config import wiki_overlay
## #73 item 5 (2.1): an organisation's wiki settings over the repository's own.
with wiki_overlay(Path(args.wiki_config) if args.wiki_config else None):
return _site(args, db, repo or Path.cwd())
try:
text = _flow(args, db, repo) if args.verb == "flow" else _json(_trace(args, db, repo), args)
except (ValueError, OSError) as exc:
sys.stderr.write(f"clew wiki: refused — {exc}\n")
return 2
sys.stdout.write(text + "\n")
return 0