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.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.