epythet.validation.parse¶
Level 0.5: parse each docstring’s docutils doctree and run the ledger’s detectors.
This is the load-bearing level of epythet validate: the research measured
that a strict sphinx-build -W -n is silent on 12 of 21 artifact classes,
while the doctree of the docstring, parsed in isolation, exposes 20 of them at
about a thousand docstrings per second and without a build.
Two things make a naive implementation fail and are handled here:
plain docutils knows nothing of
:func:,.. versionadded::and the rest of Sphinx’s vocabulary, so stub roles and directives are registered first (otherwise nearly every correct Sphinx docstring is flagged);with
sphinx.ext.napoleonenabled fleet-wide, Google sections are rewritten before docutils sees them, so the same transform is applied here (napoleon=True) and rules can opt out viaapplies_to.napoleon.
file_insertion_enabled and raw_enabled are off so that a docstring can
never make the validator read a file or inject raw HTML.
Module Attributes
Directives whose real implementation takes at most one argument. |
Functions
|
Run one parse-level rule over one parsed docstring; returns the evidence list. |
|
One finding per (docstring, rule) that fired, carrying the first hit and the count. |
Register stub Sphinx roles and directives with docutils (idempotent). |
|
|
Rewrite Google/NumPy sections into RST fields the way |
|
Parse one docstring (after the optional napoleon transform). |
|
Parse RST text into a doctree, returning it with the docutils messages. |
|
Level 0.5 over a stream of docstrings. |
Whether |
Classes
|
One docstring, its (possibly napoleon-transformed) text, doctree and messages. |
- epythet.validation.parse.ONE_ARGUMENT_DIRECTIVES = frozenset({'code', 'code-block', 'literalinclude', 'math', 'sourcecode'})¶
Directives whose real implementation takes at most one argument.
- class epythet.validation.parse.ParsedDocstring(docstring, text, tree, messages, _paragraphs=None, _literals=None)[source]¶
Bases:
objectOne docstring, its (possibly napoleon-transformed) text, doctree and messages.
- epythet.validation.parse.evaluate_rule(rule, parsed)[source]¶
Run one parse-level rule over one parsed docstring; returns the evidence list.
- epythet.validation.parse.findings_for(parsed, rules, *, level=0.5)[source]¶
One finding per (docstring, rule) that fired, carrying the first hit and the count.
A rule whose detector declares
only_if_no_other_hits: true(the catch-all DR032) is evaluated last and reported only when nothing more specific fired on the same docstring, so a docutils message never appears twice under two rule ids.
- epythet.validation.parse.install_stubs()[source]¶
Register stub Sphinx roles and directives with docutils (idempotent).
- Return type:
- epythet.validation.parse.napoleon_transform(text)[source]¶
Rewrite Google/NumPy sections into RST fields the way
sphinx.ext.napoleondoes.Returns
textunchanged when Sphinx is not importable; the caller records a note in that case.- Return type:
- epythet.validation.parse.parse_docstring(docstring, *, napoleon=True)[source]¶
Parse one docstring (after the optional napoleon transform).
- Return type:
- epythet.validation.parse.parse_rst(text)[source]¶
Parse RST text into a doctree, returning it with the docutils messages.