md2star.doctor module
md2star doctor, environment diagnostics.
Two layers, separated on purpose:
Pure logic (
run_checks): walks the dependency list, callsshutil.which/subprocess.run/ filesystem probes, returns a structuredReportdataclass. No printing, nosys.exit, no colour, easy to unit-test viamonkeypatch.CLI renderer (
main): formats aReportfor a terminal, prints to stdout, and picks an exit code. Exits0unless a core dependency (Python interpreter,md2starpackage,pandoc) is broken; optional missing pieces produceWARNING/INFOlines but do not fail the command.
The output is deliberately scannable: one line per check, status in a
fixed-width column on the left, resolved path / version on the right.
A “Result” footer summarises which conversion targets actually work in
this environment so a returning user can see at a glance whether they
need to install anything before reaching for md2docx.
- class md2star.doctor.Check(name, status, detail='', section='Core')[source]
Bases:
objectOne row in the doctor’s report.
- class md2star.doctor.Report(checks=<factory>)[source]
Bases:
objectStructured doctor output. The CLI prints it; tests assert on it.
- add(name, status, detail='', section='Core')[source]
Append one
Checkrow to the report.- Parameters:
- Return type:
None
- feature_status(fmt)[source]
Return
OK/PARTIAL/UNAVAILABLEfor a conversion target.docx— needs pandoc.pptx— needs pandoc.pdf— needs pandoc + soffice.mermaid— needs node + (mermaid-cli or npx).
- get(name)[source]
Return the first check matching name, or
Noneif absent.- Parameters:
name (str) – The
Check.nameto look up.- Returns:
The matching row, or
Nonewhen no check carries that name.- Return type:
Check | None
- md2star.doctor.render(report)[source]
Format report as a human-readable multi-section string.
This is the one place the report is translated, and deliberately so: the section names double as dictionary keys and the statuses are tokens a script greps, so both stay English in the data and in
--json. Only what a person reads goes through the catalogue — and a detail already composed with a version and a path matches no entry, so it passes through untouched while the fixed prose (“Needed for md2pdf…”) does not.
- md2star.doctor.run(*, as_json=False)[source]
Run every check and print the result. Returns the process exit code.
The
md2star doctorcommand’s whole body. It used to own an argparse parser for its one flag; since 3.10.0 click parses that flag (there is one command line in this package) and hands the decision here as a bool.- Parameters:
as_json (bool, optional) – Emit the machine-readable payload instead of the human-readable table. The JSON deliberately stays English: section names double as keys and the statuses are tokens a script greps.
- Returns:
1when a Core check is broken,0otherwise — so CI can gate on md2star being usable while tolerating missing optional tools.- Return type:
- md2star.doctor.run_checks(which=None)[source]
Walk every check and return a
Report.which defaults to
shutil.which(); tests inject a fake to simulate “pandoc missing” / “soffice present” combinations without touching the real PATH.