boilerdata_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#
- boilerdata_docs.docstrings._PARAMETERS_SECTIONS: Final[tuple[str, ...]]#
(‘Parameters’, ‘Returns’, ‘Yields’, ‘Receives’, ‘Other Parameters’, ‘Raises’, ‘Warns’, ‘Attributes’)
- boilerdata_docs.docstrings._REGULAR_SECTIONS: Final[tuple[str, ...]]#
(‘Warnings’, ‘Notes’, ‘References’, ‘Examples’)
- boilerdata_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 ----------------
- boilerdata_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}
- boilerdata_docs.docstrings.render_see_also(
- see_also: boilerdata_docs.types.SingleSeeAlso,
Render a single NumpyDoc “See Also” reference.
- boilerdata_docs.docstrings.render_see_also_section(
- section: boilerdata_docs.types.SeeAlsoSection,
Render the full “See Also” section from parsed output of NumpyDoc.
- boilerdata_docs.docstrings.render_regular_section(
- section: boilerdata_docs.types.RegularSection,
Render any other section.
- boilerdata_docs.docstrings.render_parameter(
- parameter: numpydoc.docscrape.Parameter,
Render a single NumpyDoc Parameter as Markdown.
- boilerdata_docs.docstrings.render_parameter_section(
- section: list[numpydoc.docscrape.Parameter],
Convert parsed parameters into final markdown we want to render.
- boilerdata_docs.docstrings.report_errors_in_docstring(
- doc: str,
- document: docutils.nodes.document,
Warn for docstring errors.
- boilerdata_docs.docstrings.to_pure_markdown( ) str #
Convert a hybrid NumpyDoc/MyST docstring to pure Markdown.
- boilerdata_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 boilerdata_docs.docstrings.MystNumpyDocHybridParser#
Bases:
myst_parser.parsers.sphinx_.MystParser
Hybrid docstring. Use NumpyDoc style, but allow Markdown instead of rST.
- boilerdata_docs.docstrings.Parser#
None