Skip to content

Commit

Permalink
chore: use ruff 'pydocstyle' instead of 'docformatter'
Browse files Browse the repository at this point in the history
  • Loading branch information
azmeuk committed Jan 14, 2025
1 parent 80cfc81 commit e303dca
Show file tree
Hide file tree
Showing 32 changed files with 82 additions and 141 deletions.
4 changes: 0 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ repos:
- id: end-of-file-fixer
exclude: "\\.svg$|\\.map$|\\.min\\.css$|\\.min\\.js$|\\.po$|\\.pot$"
- id: check-toml
# - repo: https://github.com/PyCQA/docformatter
# rev: v1.7.5
# hooks:
# - id: docformatter
- repo: https://github.com/rtts/djhtml
rev: 3.0.7
hooks:
Expand Down
11 changes: 6 additions & 5 deletions canaille/app/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@


class RootSettings(BaseSettings):
"""The top-level namespace contains the configuration settings unrelated to
Canaille.
"""The top-level namespace contains the configuration settings unrelated to Canaille.
The configuration parameters from the following libraries can be used:
Expand Down Expand Up @@ -77,9 +76,11 @@ class RootSettings(BaseSettings):


def settings_factory(config, env_file=None, env_prefix=""):
"""Pushes the backend specific configuration into CoreSettings, in the
purpose break dependency against backends libraries like python-ldap or
sqlalchemy."""
"""Push the backend specific configuration into CoreSettings.
In the purpose to break dependency against backends libraries like python-ldap or
sqlalchemy.
"""
attributes = {"CANAILLE": (CoreSettings, CoreSettings())}

if "CANAILLE_SQL" in config or any(
Expand Down
9 changes: 0 additions & 9 deletions canaille/app/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def has_intruder_lockout(self):
It is controlled by the :attr:`CANAILLE.ENABLE_INTRUDER_LOCKOUT <canaille.core.configuration.CoreSettings.ENABLE_INTRUDER_LOCKOUT>` configuration parameter.
"""

return self.app.config["CANAILLE"]["ENABLE_INTRUDER_LOCKOUT"]

@property
Expand All @@ -39,7 +38,6 @@ def has_otp(self):
It is controlled by the :attr:`CANAILLE.OTP_METHOD <canaille.core.configuration.CoreSettings.OTP_METHOD>` configuration parameter,
and needs the ``otp`` extra package to be installed.
"""

try:
import otpauth # noqa: F401

Expand All @@ -53,7 +51,6 @@ def has_email_otp(self):
It is controlled by the :attr:`CANAILLE.EMAIL_OTP <canaille.core.configuration.CoreSettings.EMAIL_OTP>` configuration parameter.
"""

return bool(self.app.config["CANAILLE"]["EMAIL_OTP"])

@property
Expand All @@ -63,7 +60,6 @@ def has_sms_otp(self):
It is controlled by the :attr:`CANAILLE.SMS_OTP <canaille.core.configuration.CoreSettings.SMS_OTP>` configuration parameter,
and needs the ``smpp`` extra package to be installed.
"""

try:
import smpplib # noqa: F401

Expand All @@ -77,7 +73,6 @@ def has_registration(self):
It is controlled by the :attr:`CANAILLE.ENABLE_REGISTRATION <canaille.core.configuration.CoreSettings.ENABLE_REGISTRATION>` configuration parameter.
"""

return self.app.config["CANAILLE"]["ENABLE_REGISTRATION"]

@property
Expand All @@ -87,7 +82,6 @@ def has_account_lockability(self):
It depends on the backend used by Canaille.
This is only disabled for OpenLDAP versions under 2.6.
"""

return self.app.backend.instance.has_account_lockability()

@property
Expand All @@ -96,7 +90,6 @@ def has_email_confirmation(self):
It is controlled by the :attr:`CANAILLE.EMAIL_CONFIRMATION <canaille.core.configuration.CoreSettings.EMAIL_CONFIRMATION>` configuration parameter.
"""

return self.app.config["CANAILLE"]["EMAIL_CONFIRMATION"] is True or (
self.app.config["CANAILLE"]["EMAIL_CONFIRMATION"] is None and self.has_smtp
)
Expand All @@ -109,7 +102,6 @@ def has_oidc(self):
It is controlled by the :class:`CANAILLE_OIDC <canaille.oidc.configuration.OIDCSettings>` configuration parameter,
and needs the ``oidc`` extra package to be installed.
"""

try:
import authlib # noqa: F401

Expand All @@ -125,7 +117,6 @@ def has_scim_server(self):
It is controlled by the :attr:`CANAILLE_SCIM.ENABLE_SERVER <canaille.scim.configuration.SCIMSettings.ENABLE_SERVER>` configuration parameter,
and needs the ``scim`` extra package to be installed.
"""

try:
import scim2_models # noqa: F401

Expand Down
10 changes: 3 additions & 7 deletions canaille/app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ def field_from_name(self, field_name):
return fieldlist[indice], context

def validate(self, *args, **kwargs):
"""If the request is a HTMX request, this will only render the field
that triggered the request (after having validated the form).
"""If the request is a HTMX request, this will only render the field that triggered the request (after having validated the form).
This uses the Flask abort method to interrupt the flow with an
exception.
Expand Down Expand Up @@ -200,8 +199,7 @@ def render_field(self, field, *args, **kwargs):
abort(response)

def form_control(self):
"""Check whether the current request is the result of the users adding
or removing a field from a FieldList."""
"""Check whether the current request is the result of the users adding or removing a field from a FieldList."""
FIELDLIST_ADD_BUTTON = "fieldlist_add"
FIELDLIST_REMOVE_BUTTON = "fieldlist_remove"

Expand Down Expand Up @@ -262,9 +260,7 @@ class BaseForm(HTMXFormMixin, I18NFormMixin, wtforms.form.BaseForm):


class TableForm(I18NFormMixin, FlaskForm):
"""
A form for table rendering of object collections.
"""
"""A form for table rendering of object collections."""

def __init__(
self, cls=None, page_size: int = 25, fields=None, filter=None, **kwargs
Expand Down
7 changes: 4 additions & 3 deletions canaille/app/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ def filter(self, record):


def add_log_level(level_name, level_num, method_name=None):
"""
Adapted from https://stackoverflow.com/a/35804945/2700168
"""Adapted from https://stackoverflow.com/a/35804945/2700168.
Comprehensively adds a new logging level to the `logging` module and the
currently configured logging class.
Expand All @@ -25,14 +24,16 @@ def add_log_level(level_name, level_num, method_name=None):
To avoid accidental clobberings of existing attributes, this method will
raise an `AttributeError` if the level name is already an attribute of the
`logging` module or if the method name is already present
Example
Example:
-------
>>> addLoggingLevel("TRACE", logging.DEBUG - 5)
>>> logging.getLogger(__name__).setLevel("TRACE")
>>> logging.getLogger(__name__).trace("that worked")
>>> logging.trace("so did this")
>>> logging.TRACE
5
"""
if not method_name:
method_name = level_name.lower()
Expand Down
20 changes: 7 additions & 13 deletions canaille/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class ModelEncoder(json.JSONEncoder):
def serialize_model(instance):
def serialize_attribute(attribute_name, value):
"""Replace model instances by their id."""

multiple = typing.get_origin(instance.attributes[attribute_name]) is list
if multiple and isinstance(value, list):
return [serialize_attribute(attribute_name, v) for v in value]
Expand Down Expand Up @@ -84,12 +83,10 @@ def install(self, app):
raise NotImplementedError()

def setup(self):
"""Is called before each http request, it should open the connection to
the backend."""
"""Is called before each http request, it should open the connection to the backend."""

def teardown(self):
"""Is called after each http request, it should close the connections
to the backend."""
"""Is called after each http request, it should close the connections to the backend."""

@classmethod
def validate(cls, config):
Expand All @@ -101,8 +98,8 @@ def validate(cls, config):
raise NotImplementedError()

def query(self, model, **kwargs):
"""
Perform a query on the database and return a collection of instances.
"""Perform a query on the database and return a collection of instances.
Parameters can be any valid attribute with the expected value:
>>> backend.query(User, first_name="George")
Expand All @@ -120,13 +117,11 @@ def query(self, model, **kwargs):
raise NotImplementedError()

def fuzzy(self, model, query, attributes=None, **kwargs):
"""Works like :meth:`~canaille.backends.Backend.query` but attribute
values loosely be matched."""
"""Work like :meth:`~canaille.backends.Backend.query` but attribute values loosely be matched."""
raise NotImplementedError()

def get(self, model, identifier=None, **kwargs):
"""Works like :meth:`~canaille.backends.Backend.query` but return only
one element or :py:data:`None` if no item is matching."""
"""Work like :meth:`~canaille.backends.Backend.query` but return only one element or :py:data:`None` if no item is matching."""
raise NotImplementedError()

def save(self, instance):
Expand All @@ -153,8 +148,7 @@ def reload(self, instance):
raise NotImplementedError()

def update(self, instance, **kwargs):
"""Assign a whole dict to the current instance. This is useful to
update models based on forms.
"""Assign a whole dict to the current instance. This is useful to update models based on forms.
>>> user = User.get(user_name="george")
>>> user.first_name
Expand Down
7 changes: 2 additions & 5 deletions canaille/backends/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ def is_multiple(attribute_type):


def register(cli):
"""Generate commands using factories that each have one subcommand per
available model."""
"""Generate commands using factories that each have one subcommand per available model."""
cli.add_command(get_command)
cli.add_command(set_command)
cli.add_command(create_command)
Expand Down Expand Up @@ -280,12 +279,10 @@ def delete_command():
@with_backendcontext
@click.argument("identifier")
def reset_otp(identifier):
"""Reset one-time password authentication for a user and display the
edited user in JSON format in the standard output.
"""Reset one-time password authentication for a user and display the edited user in JSON format in the standard output.
IDENTIFIER should be a user id or user_name
"""

user = Backend.instance.get(models.User, identifier)
if not user:
raise click.ClickException(f"No user with id '{identifier}'")
Expand Down
3 changes: 1 addition & 2 deletions canaille/backends/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ def __html__(self):

@property
def identifier(self):
"""Returns a unique value that will be used to identify the model
instance.
"""Return a unique value that will be used to identify the model instance.
This value will be used in URLs in canaille, so it should be
unique and short.
Expand Down
2 changes: 1 addition & 1 deletion canaille/backends/sql/migrations/1736443094_init.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""initial migration
"""initial migration.
Represents the state of the database in version 0.0.56
Expand Down
2 changes: 1 addition & 1 deletion canaille/backends/sql/migrations/1736443538_0_0_58.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""0.0.58
"""0.0.58.
Revision ID: 1736443538
Revises: 1736443094
Expand Down
10 changes: 6 additions & 4 deletions canaille/core/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@


class SMTPSettings(BaseModel):
"""The SMTP configuration. Belong in the ``CANAILLE.SMTP`` namespace. If
unset, mail related features will be disabled, such as mail verification or
"""The SMTP configuration. Belong in the ``CANAILLE.SMTP`` namespace.
If unset, mail related features will be disabled, such as mail verification or
password recovery emails.
By default, Canaille will try to send mails from localhost without
Expand Down Expand Up @@ -40,8 +41,9 @@ class SMTPSettings(BaseModel):


class SMPPSettings(BaseModel):
"""The SMPP configuration. Belong in the ``CANAILLE.SMPP`` namespace. If
not set, sms related features such as sms one-time passwords will be disabled.
"""The SMPP configuration. Belong in the ``CANAILLE.SMPP`` namespace.
If not set, sms related features such as sms one-time passwords will be disabled.
"""

HOST: str | None = "localhost"
Expand Down
18 changes: 9 additions & 9 deletions canaille/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@


class User(Model):
"""User model, based on the `SCIM User schema
"""User model.
Based on the `SCIM User schema
<https://datatracker.ietf.org/doc/html/rfc7643#section-4.1>`_,
`Entreprise User Schema Extension
<https://datatracker.ietf.org/doc/html/rfc7643#section-4.3>`_
Expand Down Expand Up @@ -311,9 +313,7 @@ def __getattribute__(self, name):
raise

def can(self, *permissions: Permission):
"""Whether or not the user has the
:class:`~canaille.core.configuration.Permission` according to the
:class:`configuration <canaille.core.configuration.ACLSettings>`."""
"""Whether or not the user has the :class:`~canaille.core.configuration.Permission` according to the :class:`configuration <canaille.core.configuration.ACLSettings>`."""
if self._permissions is None:
self._permissions = set()
acls = current_app.config["CANAILLE"]["ACL"].values()
Expand All @@ -338,8 +338,7 @@ def reload(self):

@property
def readable_fields(self):
"""The fields the user can read according to the :class:`configuration
<canaille.core.configuration.ACLSettings>` configuration.
"""The fields the user can read according to the :class:`configuration <canaille.core.configuration.ACLSettings>` configuration.
This does not include the :attr:`writable
<canaille.core.models.User.writable_fields>` fields.
Expand All @@ -355,8 +354,7 @@ def readable_fields(self):

@property
def writable_fields(self):
"""The fields the user can write according to the :class:`configuration
<canaille.core.configuration.ACLSettings>`."""
"""The fields the user can write according to the :class:`configuration <canaille.core.configuration.ACLSettings>`."""
if self._writable_fields is None:
self._writable_fields = set()
acls = current_app.config["CANAILLE"]["ACL"].values()
Expand Down Expand Up @@ -511,7 +509,9 @@ def has_expired_password(self):


class Group(Model):
"""User model, based on the `SCIM Group schema
"""Group model.
Based on the `SCIM Group schema
<https://datatracker.ietf.org/doc/html/rfc7643#section-4.2>`_.
"""

Expand Down
3 changes: 1 addition & 2 deletions canaille/core/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ def existing_group_member(form, field):


def non_empty_groups(form, field):
"""LDAP groups cannot be empty because groupOfNames.member is a MUST
attribute.
"""LDAP groups cannot be empty because groupOfNames.member is a MUST attribute.
https://www.rfc-editor.org/rfc/rfc2256.html#section-7.10
"""
Expand Down
10 changes: 4 additions & 6 deletions canaille/oidc/basemodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@


class Client(Model):
"""OpenID Connect client definition, based on the
`OAuth 2.0 Dynamic Client Registration protocols
<https://datatracker.ietf.org/doc/html/rfc7591.html>`_
and the `OpenID Connect RP-Initiated Logout
<https://openid.net/specs/openid-connect-rpinitiated-1_0.html>`_
specifications.
"""OpenID Connect client definition.
Based on the :rfc:`OAuth 2.0 Dynamic Client Registration protocols <7591>` and the
`OpenID Connect RP-Initiated Logout <https://openid.net/specs/openid-connect-rpinitiated-1_0.html>`_ specifications.
"""

identifier_attribute: ClassVar[str] = "client_id"
Expand Down
3 changes: 1 addition & 2 deletions canaille/scim/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ def get_service_provider_config():


def get_resource_types():
"""The resource types implemented by Canaille."""

"""Return the resource types implemented by Canaille."""
return {
"User": ResourceType(
id="User",
Expand Down
2 changes: 1 addition & 1 deletion doc/commands.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Temporary workaround for https://github.com/click-contrib/sphinx-click/issues/139"""
"""Temporary workaround for https://github.com/click-contrib/sphinx-click/issues/139."""

import inspect

Expand Down
Loading

0 comments on commit e303dca

Please sign in to comment.