Documentation standards#
Providing instructive documentation is a key part of skbase’s mission.
To meet this, developers are expected to follow the project’s documentation standards.
These include:
Documenting code using NumPy docstrings
Following
skbase’s docstring convention for public code artifacts and modulesAdding new public functionality to the API Reference and user guide
More detailed information on skbase’s documentation format is provided below.
Docstring conventions#
skbase uses the numpydoc Sphinx extension and follows
NumPy docstring format.
To ensure docstrings meet expectations, skbase uses a combination of
validations built into numpydoc, pydocstyle pre-commit checks
(set to the NumPy convention) and automated testing of docstring examples to
ensurecthe code runs without error.
However, the automated docstring validation in pydocstyle only covers basic
formatting. Passing these tests is necessary to meet the skbase
docstring conventions, but is not sufficient for doing so.
To ensure docstrings meet skbase’s conventions, developers are expected
to check their docstrings against numpydoc and skbase conventions and
ref:reviewer’s <reviewer_guide_doc> are expected to also focus feedback on
docstring quality.
skbase specific conventions#
Beyond basic NumPy docstring formatting conventions, developers should focus on:
Ensuring all parameters (classes, functions, methods) and attributes (classes) are documented completely and consistently
Including links to the relevant topics in the Glossary of Common Terms or User Guide in the extended summary
Including an Examples section that demonstrates at least basic functionality in all public code artifacts
Adding a See Also section that references related
skbasecode artifacts as applicableIncluding citations to relevant sources in a References section
Accordingly, most public code artifacts in skbase
should generally include the following NumPy docstring convention sections:
Summary
Extended Summary
Parameters
Attributes (classes only)
Returns or Yields (as applicable)
Raises (as applicable)
See Also (as applicable)
Notes (as applicable)
References (as applicable)
Examples
Note
In many cases a parameter, attribute return object, or error may be described in the docstring of more than one class. To avoid confusion, developers should make sure their docstrings are as similar as possible to existing docstring descriptions of the the same parameter, attribute, return object or error. As applicable, this may mean copying the same docstring section for the parameter, attribute, return object or error.
Summary and extended summary#
The summary should be a single line, followed by a (properly formatted) extended summary.
The extended summary should include a user friendly explanation of the code artifacts functionality. The extended summary should also include links to relevant content in the Glossary of Common Terms and user guide.
If a “term” already exists in the glossary and the developer wants to link it directly they can use:
:term:`the glossary term`
In other cases you’ll want to use different phrasing but link to an existing glossary term, and the developer can use:
:term:`the link text <the glossary term>`
In the event a term is not already in the glossary, developers should add the term to the Glossary of Common Terms and include a reference (as shown above) to the added term.
Likewise, a developer can link to a particular area of the user guide by including an explicit cross-reference and following the steps for referencing in Sphinx (see the helpful description on Sphinx cross-references posted by Read the Docs). Again developers are encouraged to add important content to the user guide and link to it if it does not already exist.
See Also#
This section should reference other skbase code artifcats related to the code
artifact being documented by the docstring. Developers should use judgement in
determining related code artifcats.
Notes#
The notes section can include several types of information, including:
Mathematical details of a code object or other important implementation details (using ..math or :math:`` functionality)
Links to alternative implementations of the code artifact that are external to
skbaseA discussion of state changing methods
References#
Objects that implement functionality covered in a research article or other package, should include an applicable citation.
This should be done by adding references into the references section of the docstring, and then typically linking to these in other parts of the docstring.
The references you intend to link to within the docstring should follow a very specific format to ensure they render correctly. See the example below. Note the space between the “..” and opening bracket, the space after the closing bracket, and how all the lines after the first line are aligned immediately with the opening bracket. Additional references should be added in exactly the same way, but the number enclosed in the bracket should be incremented.
.. [1] Some research article, link or other type of citation.
Long references wrap onto multiple lines, but you need to
indent them so they start aligned with opening bracket on first line.
To link to the reference labeled as “[1]”, you use “[1]_”. This only works within the same docstring. Sometimes this is not rendered correctly if the “[1]_” link is preceded or followed by certain characters. If you run into this issue, try putting a space before and following the “[1]_” link.
To list a reference but not link it elsewhere in the docstring, you can leave out the “.. [1]” directive as shown below.
Some research article, link or other type of citation.
Long references wrap onto multiple lines. If you are
not linking the reference you can leave off the ".. [1]".
Examples#
Most code artifacts in skbase should include an examples section. At
a minimum this should include a single example that illustrates basic functionality.
The examples should use simple data (e.g. randomly generated data, etc)
generated using a skbase dependency and whereever possible only depend
on skbase or its core dependencies. Examples should also be designed to
run quickly where possible. For quick running code artifacts, additional examples
can be included to illustrate the affect of different parameter settings.
Examples of Good skbase Docstrings#
Here are a few examples of skbase code artifacts with good documentation.
Classes#
Functions#
Documentation Build#
We use sphinx to build our documentation and readthedocs to host it. You can find our latest documentation here.
The source files can be found
in docs/source/.
The main configuration file for sphinx is
conf.py
and the main page is
index.rst.
To add new pages, you need to add a new .rst file and link to it from the
applicable file in the existing documentation.
To build the documentation locally, you need to install a few extra dependencies listed in pyproject.toml.
To install extra dependencies from the root directory of your local copy of the forked repository, run:
pip install --editable .[docs]
To build the website locally, from the root directory of your local copy, run:
cd docs make html