boilerdaq_docs.docstrings
#
Helpers for parsing and rendering docstrings in Sphinx.
References#
Copyright 2023 Digital Biology, Inc., SPDX-License-Identifier: Apache-2.0, sphinx-extensions2/sphinx-autodoc2#33
Module Contents#
Classes#
Hybrid docstring. Use NumpyDoc style, but allow Markdown instead of rST. |
Functions#
Render a single NumpyDoc “See Also” reference. |
|
Render the full “See Also” section from parsed output of NumpyDoc. |
|
Render any other section. |
|
Render a single NumpyDoc Parameter as Markdown. |
|
Convert parsed parameters into final markdown we want to render. |
|
Warn for docstring errors. |
|
Convert a hybrid NumpyDoc/MyST docstring to pure Markdown. |
|
Replace “Output Files” section name with “Other Parameters”, as a parsing hack. |
Data#
Regular expression to check if the “Other Parameters” section has been used. |
|
Regular expression to extract the “Output Files” section title in rST format. |
|
API#
- boilerdaq_docs.docstrings._PARAMETERS_SECTIONS: Final[tuple[str, ...]]#
(‘Parameters’, ‘Returns’, ‘Yields’, ‘Receives’, ‘Other Parameters’, ‘Raises’, ‘Warns’, ‘Attributes’)
- boilerdaq_docs.docstrings._REGULAR_SECTIONS: Final[tuple[str, ...]]#
(‘Warnings’, ‘Notes’, ‘References’, ‘Examples’)
- boilerdaq_docs.docstrings._OTHER_PARAMETERS#
‘compile(…)’
Regular expression to check if the “Other Parameters” section has been used.
We cannot allow users to include “Other Parameters” section, because we hijack it to easily render our “Output Files” section without having to patch the NumpyDoc parser.
Matches text that looks like:
Other Parameters ----------------
- boilerdaq_docs.docstrings._OUTPUT_SECTION_TITLE#
‘compile(…)’
Regular expression to extract the “Output Files” section title in rST format.
We use this to pretend the “Output Files” section title is actually “Other Parameters” before passing it to the NumpyDoc parser.
Matches text that looks like:
{before} {padding}Other Parameters ---------------- {after}
- boilerdaq_docs.docstrings.render_see_also(
- see_also: boilerdaq_docs.types.SingleSeeAlso,
Render a single NumpyDoc “See Also” reference.
- boilerdaq_docs.docstrings.render_see_also_section(
- section: boilerdaq_docs.types.SeeAlsoSection,
Render the full “See Also” section from parsed output of NumpyDoc.
- boilerdaq_docs.docstrings.render_regular_section(
- section: boilerdaq_docs.types.RegularSection,
Render any other section.
- boilerdaq_docs.docstrings.render_parameter(
- parameter: numpydoc.docscrape.Parameter,
Render a single NumpyDoc Parameter as Markdown.
- boilerdaq_docs.docstrings.render_parameter_section(
- section: list[numpydoc.docscrape.Parameter],
Convert parsed parameters into final markdown we want to render.
- boilerdaq_docs.docstrings.report_errors_in_docstring(
- doc: str,
- document: docutils.nodes.document,
Warn for docstring errors.
- boilerdaq_docs.docstrings.to_pure_markdown( ) str #
Convert a hybrid NumpyDoc/MyST docstring to pure Markdown.
- boilerdaq_docs.docstrings.replace_output_files_title( ) str #
Replace “Output Files” section name with “Other Parameters”, as a parsing hack.
As a side effect, this means we cannot allow users to use the “Other Parameters” section.
Parameters#
doc (str): The docstring to cleanup.
source (str): A string describing the source file, if available. Otherwise ‘[UNKNOWN]’ will be printed.
Returns#
str (A docstring ready to hand to
numpydoc.docscrape.NumpyDocString
.)
- class boilerdaq_docs.docstrings.MystNumpyDocHybridParser#
Bases:
myst_parser.parsers.sphinx_.MystParser
Hybrid docstring. Use NumpyDoc style, but allow Markdown instead of rST.
- boilerdaq_docs.docstrings.Parser#
None