From f3a0b2430372d41479db34810a5448fc54e750d7 Mon Sep 17 00:00:00 2001 From: Gabriel Erzse Date: Wed, 15 May 2024 12:02:27 +0300 Subject: [PATCH 1/2] Streamline documentation style Adopt the Google docstrings style as the preferred way to document code. Update one of the existing docstrings to the new format, to showcase how it would look like. Enable the `napoleon` preprocessor in Sphinx, to be able to process Google style docstrings. Take the opportunity to make the copyright year dynamic, so we don't have to manually keep it up to date. Add a section about documentation to the contributors guide. --- CONTRIBUTING.md | 13 +++++ docs/conf.py | 12 +++-- redis/commands/core.py | 109 ++++++++++++++++++----------------------- 3 files changed, 71 insertions(+), 63 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4da55c737c..d87e6ba1c3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -81,6 +81,19 @@ using `invoke standalone-tests`; similarly, RedisCluster tests can be run by usi Each run of tests starts and stops the various dockers required. Sometimes things get stuck, an `invoke clean` can help. +## Documentation + +If relevant, update the code documentation, via docstrings, or in `/docs`. + +You can check how the documentation looks locally by running `invoke build-docs` +and loading the generated HTML files in a browser. + +Historically there is a mix of styles in the docstrings, but the preferred way +of documenting code is by applying the +[Google style](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html). +Type hints should be added according to PEP484, and should not be repeated in +the docstrings. + ### Docker Tips Following are a few tips that can help you work with the Docker-based diff --git a/docs/conf.py b/docs/conf.py index a201da2fc0..33a8589654 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -10,6 +10,7 @@ # All configuration values have a default; values that are commented out # serve to show the default. +import datetime import os import sys @@ -30,12 +31,15 @@ "nbsphinx", "sphinx_gallery.load_style", "sphinx.ext.autodoc", - "sphinx_autodoc_typehints", - "sphinx.ext.doctest", "sphinx.ext.viewcode", "sphinx.ext.autosectionlabel", + "sphinx.ext.napoleon", ] +# Napoleon settings. We only accept Google-style docstrings. +napoleon_google_docstring = True +napoleon_numpy_docstring = False + # AutosectionLabel settings. # Uses a :