Skip to content

Commit 6751de2

Browse files
authored
Streamline documentation style (redis#3232)
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. --------- Co-authored-by: Gabriel Erzse <[email protected]>
1 parent 0b20087 commit 6751de2

File tree

4 files changed

+73
-63
lines changed

4 files changed

+73
-63
lines changed

.github/wordlist.txt

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ bysource
7474
charset
7575
del
7676
dev
77+
docstring
78+
docstrings
7779
eg
7880
exc
7981
firsttimersonly

CONTRIBUTING.md

+13
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ using `invoke standalone-tests`; similarly, RedisCluster tests can be run by usi
8181
Each run of tests starts and stops the various dockers required. Sometimes
8282
things get stuck, an `invoke clean` can help.
8383

84+
## Documentation
85+
86+
If relevant, update the code documentation, via docstrings, or in `/docs`.
87+
88+
You can check how the documentation looks locally by running `invoke build-docs`
89+
and loading the generated HTML files in a browser.
90+
91+
Historically there is a mix of styles in the docstrings, but the preferred way
92+
of documenting code is by applying the
93+
[Google style](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html).
94+
Type hints should be added according to PEP484, and should not be repeated in
95+
the docstrings.
96+
8497
### Docker Tips
8598

8699
Following are a few tips that can help you work with the Docker-based

docs/conf.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# All configuration values have a default; values that are commented out
1111
# serve to show the default.
1212

13+
import datetime
1314
import os
1415
import sys
1516

@@ -30,19 +31,23 @@
3031
"nbsphinx",
3132
"sphinx_gallery.load_style",
3233
"sphinx.ext.autodoc",
33-
"sphinx_autodoc_typehints",
34-
"sphinx.ext.doctest",
3534
"sphinx.ext.viewcode",
3635
"sphinx.ext.autosectionlabel",
36+
"sphinx.ext.napoleon",
3737
]
3838

39+
# Napoleon settings. We only accept Google-style docstrings.
40+
napoleon_google_docstring = True
41+
napoleon_numpy_docstring = False
42+
3943
# AutosectionLabel settings.
4044
# Uses a <page>:<label> schema which doesn't work for duplicate sub-section
4145
# labels, so set max depth.
4246
autosectionlabel_prefix_document = True
4347
autosectionlabel_maxdepth = 2
4448

4549
# AutodocTypehints settings.
50+
autodoc_typehints = 'description'
4651
always_document_param_types = True
4752
typehints_defaults = "comma"
4853

@@ -60,7 +65,8 @@
6065

6166
# General information about the project.
6267
project = "redis-py"
63-
copyright = "2023, Redis Inc"
68+
current_year = datetime.datetime.now().year
69+
copyright = f"{current_year}, Redis Inc"
6470

6571
# The version info for the project you're documenting, acts as replacement for
6672
# |version| and |release|, also used in various other places throughout the

redis/commands/core.py

+49-60
Original file line numberDiff line numberDiff line change
@@ -199,69 +199,58 @@ def acl_setuser(
199199
"""
200200
Create or update an ACL user.
201201
202-
Create or update the ACL for ``username``. If the user already exists,
202+
Create or update the ACL for `username`. If the user already exists,
203203
the existing ACL is completely overwritten and replaced with the
204204
specified values.
205205
206-
``enabled`` is a boolean indicating whether the user should be allowed
207-
to authenticate or not. Defaults to ``False``.
208-
209-
``nopass`` is a boolean indicating whether the can authenticate without
210-
a password. This cannot be True if ``passwords`` are also specified.
211-
212-
``passwords`` if specified is a list of plain text passwords
213-
to add to or remove from the user. Each password must be prefixed with
214-
a '+' to add or a '-' to remove. For convenience, the value of
215-
``passwords`` can be a simple prefixed string when adding or
216-
removing a single password.
217-
218-
``hashed_passwords`` if specified is a list of SHA-256 hashed passwords
219-
to add to or remove from the user. Each hashed password must be
220-
prefixed with a '+' to add or a '-' to remove. For convenience,
221-
the value of ``hashed_passwords`` can be a simple prefixed string when
222-
adding or removing a single password.
223-
224-
``categories`` if specified is a list of strings representing category
225-
permissions. Each string must be prefixed with either a '+' to add the
226-
category permission or a '-' to remove the category permission.
227-
228-
``commands`` if specified is a list of strings representing command
229-
permissions. Each string must be prefixed with either a '+' to add the
230-
command permission or a '-' to remove the command permission.
231-
232-
``keys`` if specified is a list of key patterns to grant the user
233-
access to. Keys patterns allow '*' to support wildcard matching. For
234-
example, '*' grants access to all keys while 'cache:*' grants access
235-
to all keys that are prefixed with 'cache:'. ``keys`` should not be
236-
prefixed with a '~'.
237-
238-
``reset`` is a boolean indicating whether the user should be fully
239-
reset prior to applying the new ACL. Setting this to True will
240-
remove all existing passwords, flags and privileges from the user and
241-
then apply the specified rules. If this is False, the user's existing
242-
passwords, flags and privileges will be kept and any new specified
243-
rules will be applied on top.
244-
245-
``reset_keys`` is a boolean indicating whether the user's key
246-
permissions should be reset prior to applying any new key permissions
247-
specified in ``keys``. If this is False, the user's existing
248-
key permissions will be kept and any new specified key permissions
249-
will be applied on top.
250-
251-
``reset_channels`` is a boolean indicating whether the user's channel
252-
permissions should be reset prior to applying any new channel permissions
253-
specified in ``channels``.If this is False, the user's existing
254-
channel permissions will be kept and any new specified channel permissions
255-
will be applied on top.
256-
257-
``reset_passwords`` is a boolean indicating whether to remove all
258-
existing passwords and the 'nopass' flag from the user prior to
259-
applying any new passwords specified in 'passwords' or
260-
'hashed_passwords'. If this is False, the user's existing passwords
261-
and 'nopass' status will be kept and any new specified passwords
262-
or hashed_passwords will be applied on top.
263-
264-
For more information see https://redis.io/commands/acl-setuser
206+
For more information, see https://redis.io/commands/acl-setuser
207+
208+
Args:
209+
username: The name of the user whose ACL is to be created or updated.
210+
enabled: Indicates whether the user should be allowed to authenticate.
211+
Defaults to `False`.
212+
nopass: Indicates whether the user can authenticate without a password.
213+
This cannot be `True` if `passwords` are also specified.
214+
passwords: A list of plain text passwords to add to or remove from the user.
215+
Each password must be prefixed with a '+' to add or a '-' to
216+
remove. For convenience, a single prefixed string can be used
217+
when adding or removing a single password.
218+
hashed_passwords: A list of SHA-256 hashed passwords to add to or remove
219+
from the user. Each hashed password must be prefixed with
220+
a '+' to add or a '-' to remove. For convenience, a single
221+
prefixed string can be used when adding or removing a
222+
single password.
223+
categories: A list of strings representing category permissions. Each string
224+
must be prefixed with either a '+' to add the category
225+
permission or a '-' to remove the category permission.
226+
commands: A list of strings representing command permissions. Each string
227+
must be prefixed with either a '+' to add the command permission
228+
or a '-' to remove the command permission.
229+
keys: A list of key patterns to grant the user access to. Key patterns allow
230+
'*' to support wildcard matching. For example, '*' grants access to
231+
all keys while 'cache:*' grants access to all keys that are prefixed
232+
with 'cache:'. `keys` should not be prefixed with a '~'.
233+
reset: Indicates whether the user should be fully reset prior to applying
234+
the new ACL. Setting this to `True` will remove all existing
235+
passwords, flags, and privileges from the user and then apply the
236+
specified rules. If `False`, the user's existing passwords, flags,
237+
and privileges will be kept and any new specified rules will be
238+
applied on top.
239+
reset_keys: Indicates whether the user's key permissions should be reset
240+
prior to applying any new key permissions specified in `keys`.
241+
If `False`, the user's existing key permissions will be kept and
242+
any new specified key permissions will be applied on top.
243+
reset_channels: Indicates whether the user's channel permissions should be
244+
reset prior to applying any new channel permissions
245+
specified in `channels`. If `False`, the user's existing
246+
channel permissions will be kept and any new specified
247+
channel permissions will be applied on top.
248+
reset_passwords: Indicates whether to remove all existing passwords and the
249+
`nopass` flag from the user prior to applying any new
250+
passwords specified in `passwords` or `hashed_passwords`.
251+
If `False`, the user's existing passwords and `nopass`
252+
status will be kept and any new specified passwords or
253+
hashed passwords will be applied on top.
265254
"""
266255
encoder = self.get_encoder()
267256
pieces: List[EncodableT] = [username]

0 commit comments

Comments
 (0)