Skip to content

Commit

Permalink
Streamline documentation style (#3232)
Browse files Browse the repository at this point in the history
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.

---------

Co-authored-by: Gabriel Erzse <gabriel.erzse@redis.com>
  • Loading branch information
gerzse and gerzse committed Jul 11, 2024
1 parent 55bf558 commit c35eb96
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 63 deletions.
2 changes: 2 additions & 0 deletions .github/wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ bysource
charset
del
dev
docstring
docstrings
eg
exc
firsttimersonly
Expand Down
12 changes: 9 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -30,19 +31,23 @@
"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 <page>:<label> schema which doesn't work for duplicate sub-section
# labels, so set max depth.
autosectionlabel_prefix_document = True
autosectionlabel_maxdepth = 2

# AutodocTypehints settings.
autodoc_typehints = 'description'
always_document_param_types = True
typehints_defaults = "comma"

Expand All @@ -60,7 +65,8 @@

# General information about the project.
project = "redis-py"
copyright = "2023, Redis Inc"
current_year = datetime.datetime.now().year
copyright = f"{current_year}, Redis Inc"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down
109 changes: 49 additions & 60 deletions redis/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,69 +201,58 @@ def acl_setuser(
"""
Create or update an ACL user.
Create or update the ACL for ``username``. If the user already exists,
Create or update the ACL for `username`. If the user already exists,
the existing ACL is completely overwritten and replaced with the
specified values.
``enabled`` is a boolean indicating whether the user should be allowed
to authenticate or not. Defaults to ``False``.
``nopass`` is a boolean indicating whether the can authenticate without
a password. This cannot be True if ``passwords`` are also specified.
``passwords`` if specified is a list of plain text passwords
to add to or remove from the user. Each password must be prefixed with
a '+' to add or a '-' to remove. For convenience, the value of
``passwords`` can be a simple prefixed string when adding or
removing a single password.
``hashed_passwords`` if specified is a list of SHA-256 hashed passwords
to add to or remove from the user. Each hashed password must be
prefixed with a '+' to add or a '-' to remove. For convenience,
the value of ``hashed_passwords`` can be a simple prefixed string when
adding or removing a single password.
``categories`` if specified is a list of strings representing category
permissions. Each string must be prefixed with either a '+' to add the
category permission or a '-' to remove the category permission.
``commands`` if specified is a list of strings representing command
permissions. Each string must be prefixed with either a '+' to add the
command permission or a '-' to remove the command permission.
``keys`` if specified is a list of key patterns to grant the user
access to. Keys patterns allow '*' to support wildcard matching. For
example, '*' grants access to all keys while 'cache:*' grants access
to all keys that are prefixed with 'cache:'. ``keys`` should not be
prefixed with a '~'.
``reset`` is a boolean indicating whether the user should be fully
reset prior to applying the new ACL. Setting this to True will
remove all existing passwords, flags and privileges from the user and
then apply the specified rules. If this is False, the user's existing
passwords, flags and privileges will be kept and any new specified
rules will be applied on top.
``reset_keys`` is a boolean indicating whether the user's key
permissions should be reset prior to applying any new key permissions
specified in ``keys``. If this is False, the user's existing
key permissions will be kept and any new specified key permissions
will be applied on top.
``reset_channels`` is a boolean indicating whether the user's channel
permissions should be reset prior to applying any new channel permissions
specified in ``channels``.If this is False, the user's existing
channel permissions will be kept and any new specified channel permissions
will be applied on top.
``reset_passwords`` is a boolean indicating whether to remove all
existing passwords and the 'nopass' flag from the user prior to
applying any new passwords specified in 'passwords' or
'hashed_passwords'. If this is False, the user's existing passwords
and 'nopass' status will be kept and any new specified passwords
or hashed_passwords will be applied on top.
For more information see https://redis.io/commands/acl-setuser
For more information, see https://redis.io/commands/acl-setuser
Args:
username: The name of the user whose ACL is to be created or updated.
enabled: Indicates whether the user should be allowed to authenticate.
Defaults to `False`.
nopass: Indicates whether the user can authenticate without a password.
This cannot be `True` if `passwords` are also specified.
passwords: A list of plain text passwords to add to or remove from the user.
Each password must be prefixed with a '+' to add or a '-' to
remove. For convenience, a single prefixed string can be used
when adding or removing a single password.
hashed_passwords: A list of SHA-256 hashed passwords to add to or remove
from the user. Each hashed password must be prefixed with
a '+' to add or a '-' to remove. For convenience, a single
prefixed string can be used when adding or removing a
single password.
categories: A list of strings representing category permissions. Each string
must be prefixed with either a '+' to add the category
permission or a '-' to remove the category permission.
commands: A list of strings representing command permissions. Each string
must be prefixed with either a '+' to add the command permission
or a '-' to remove the command permission.
keys: A list of key patterns to grant the user access to. Key patterns allow
'*' to support wildcard matching. For example, '*' grants access to
all keys while 'cache:*' grants access to all keys that are prefixed
with 'cache:'. `keys` should not be prefixed with a '~'.
reset: Indicates whether the user should be fully reset prior to applying
the new ACL. Setting this to `True` will remove all existing
passwords, flags, and privileges from the user and then apply the
specified rules. If `False`, the user's existing passwords, flags,
and privileges will be kept and any new specified rules will be
applied on top.
reset_keys: Indicates whether the user's key permissions should be reset
prior to applying any new key permissions specified in `keys`.
If `False`, the user's existing key permissions will be kept and
any new specified key permissions will be applied on top.
reset_channels: Indicates whether the user's channel permissions should be
reset prior to applying any new channel permissions
specified in `channels`. If `False`, the user's existing
channel permissions will be kept and any new specified
channel permissions will be applied on top.
reset_passwords: Indicates whether to remove all existing passwords and the
`nopass` flag from the user prior to applying any new
passwords specified in `passwords` or `hashed_passwords`.
If `False`, the user's existing passwords and `nopass`
status will be kept and any new specified passwords or
hashed passwords will be applied on top.
"""
encoder = self.get_encoder()
pieces: List[EncodableT] = [username]
Expand Down

0 comments on commit c35eb96

Please sign in to comment.