Skip to content

Commit 8e6c6c1

Browse files
committed
chore: use ruff pydocstyle instead of docformatter
1 parent 23a97bf commit 8e6c6c1

12 files changed

Lines changed: 83 additions & 90 deletions

File tree

.pre-commit-config.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ repos:
1515
- id: end-of-file-fixer
1616
exclude: "\\.svg$|\\.map$|\\.min\\.css$|\\.min\\.js$|\\.po$|\\.pot$"
1717
- id: check-toml
18-
- repo: https://github.com/PyCQA/docformatter
19-
rev: v1.7.5
20-
hooks:
21-
- id: docformatter
2218
- repo: https://github.com/codespell-project/codespell
2319
rev: v2.3.0
2420
hooks:

pyproject.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ exclude_lines = [
6868

6969
[tool.ruff.lint]
7070
select = [
71+
"D", # pydocstyle
7172
"E", # pycodestyle
7273
"F", # pyflakes
7374
"I", # isort
@@ -76,6 +77,16 @@ select = [
7677
ignore = [
7778
"E501", # line-too-long
7879
"E722", # bare-except
80+
"D100", # public module
81+
"D101", # public class
82+
"D102", # public method
83+
"D103", # public function
84+
"D104", # public package
85+
"D105", # magic method
86+
"D106", # nested class
87+
"D107", # public init
88+
"D203", # no-blank-line-before-class
89+
"D213", # multi-line-summary-second-line
7990
]
8091

8192
[tool.ruff.lint.isort]
@@ -84,6 +95,7 @@ force-single-line = true
8495
[tool.ruff.format]
8596
docstring-code-format = true
8697

98+
8799
[tool.pytest.ini_options]
88100
addopts = "--doctest-modules --doctest-glob='*.rst'"
89101
doctest_optionflags= "ALLOW_UNICODE IGNORE_EXCEPTION_DETAIL ELLIPSIS"

scim2_server/backend.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,30 +37,30 @@ def __init__(self):
3737
self.models_dict: dict[str, BaseModel] = {}
3838

3939
def __enter__(self):
40-
"""Allows the backend to be used as a context manager.
40+
"""Allow the backend to be used as a context manager.
4141
4242
This enables support for transactions.
4343
"""
4444
return self
4545

4646
def __exit__(self, exc_type, exc_val, exc_tb):
47-
"""Exits the transaction."""
47+
"""Exit the transaction."""
4848
pass
4949

5050
def register_schema(self, schema: Schema):
51-
"""Registers a Schema for use with the backend."""
51+
"""Register a Schema for use with the backend."""
5252
self.schemas[schema.id] = schema
5353

5454
def get_schemas(self):
55-
"""Returns all schemas registered with the backend."""
55+
"""Return all schemas registered with the backend."""
5656
return self.schemas.values()
5757

5858
def get_schema(self, schema_id: str) -> Schema | None:
59-
"""Gets a schema by its id."""
59+
"""Get a schema by its id."""
6060
return self.schemas.get(schema_id)
6161

6262
def register_resource_type(self, resource_type: ResourceType):
63-
"""Registers a ResourceType for use with the backend.
63+
"""Register a ResourceType for use with the backend.
6464
6565
The schemas used for the resource and its extensions must have
6666
been registered with the Backend beforehand.
@@ -86,31 +86,31 @@ def register_resource_type(self, resource_type: ResourceType):
8686
]
8787

8888
def get_resource_types(self):
89-
"""Returns all resource types registered with the backend."""
89+
"""Return all resource types registered with the backend."""
9090
return self.resource_types.values()
9191

9292
def get_resource_type(self, resource_type_id: str) -> ResourceType | None:
93-
"""Returns the resource type by its id."""
93+
"""Return the resource type by its id."""
9494
return self.resource_types.get(resource_type_id)
9595

9696
def get_resource_type_by_endpoint(self, endpoint: str) -> ResourceType | None:
97-
"""Returns the resource type by its endpoint."""
97+
"""Return the resource type by its endpoint."""
9898
return self.resource_types_by_endpoint.get(endpoint.lower())
9999

100100
def get_model(self, resource_type_id: str) -> BaseModel | None:
101-
"""Returns the Pydantic Python model for a given resource type."""
101+
"""Return the Pydantic Python model for a given resource type."""
102102
return self.models_dict.get(resource_type_id)
103103

104104
def get_models(self):
105-
"""Returns all Pydantic Python models for all known resource types."""
105+
"""Return all Pydantic Python models for all known resource types."""
106106
return self.models_dict.values()
107107

108108
def query_resources(
109109
self,
110110
search_request: SearchRequest,
111111
resource_type_id: str | None = None,
112112
) -> tuple[int, list[Resource]]:
113-
"""Queries the backend for a set of resources.
113+
"""Query the backend for a set of resources.
114114
115115
:param search_request: SearchRequest instance describing the
116116
query.
@@ -128,7 +128,7 @@ def query_resources(
128128
raise NotImplementedError
129129

130130
def get_resource(self, resource_type_id: str, object_id: str) -> Resource | None:
131-
"""Queries the backend for a resources by its ID.
131+
"""Query the backend for a resources by its ID.
132132
133133
:param resource_type_id: ID of the resource type to get the
134134
object from.
@@ -140,7 +140,7 @@ def get_resource(self, resource_type_id: str, object_id: str) -> Resource | None
140140
raise NotImplementedError
141141

142142
def delete_resource(self, resource_type_id: str, object_id: str) -> bool:
143-
"""Deletes a resource.
143+
"""Delete a resource.
144144
145145
:param resource_type_id: ID of the resource type to delete the
146146
object from.
@@ -152,7 +152,7 @@ def delete_resource(self, resource_type_id: str, object_id: str) -> bool:
152152
def create_resource(
153153
self, resource_type_id: str, resource: Resource
154154
) -> Resource | None:
155-
"""Creates a resource.
155+
"""Create a resource.
156156
157157
:param resource_type_id: ID of the resource type to create.
158158
:param resource: Resource to create.
@@ -165,7 +165,7 @@ def create_resource(
165165
def update_resource(
166166
self, resource_type_id: str, resource: Resource
167167
) -> Resource | None:
168-
"""Updates a resource. The resource is identified by its ID.
168+
"""Update a resource. The resource is identified by its ID.
169169
170170
:param resource_type_id: ID of the resource type to update.
171171
:param resource: Resource to update.
@@ -177,7 +177,7 @@ def update_resource(
177177

178178

179179
class InMemoryBackend(Backend):
180-
"""This is an example in-memory backend for the SCIM provider.
180+
"""An example in-memory backend for the SCIM provider.
181181
182182
It is not optimized for performance. Many operations are O(n) or
183183
worse, whereas they would perform better with an actual production

scim2_server/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
def log_environ(handler):
17-
"""A simple decorator to log all WSGI environment variables."""
17+
"""Build a simple decorator to log all WSGI environment variables."""
1818

1919
def _inner(environ, start_fn):
2020
logging.getLogger("log_environ").debug(pprint.pformat(environ))

scim2_server/filter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
def evaluate_filter(
1414
obj: BaseModel | list[BaseModel], tree: scim2ast.AST
1515
) -> bool | list[bool]:
16-
"""This implementation is limited by the specifics of the
17-
scim2_filter_parser module.
16+
"""Resolve filters.
17+
18+
This implementation is limited by the specifics of the scim2_filter_parser module.
1819
1920
It works well enough for simple cases, though. It should be re-
2021
implemented in the future. Probably once
@@ -117,8 +118,7 @@ def evaluate_filter(
117118

118119

119120
def check_comparable_value(value):
120-
"""Certain values may not be compared in a filter, see RFC 7644, section
121-
3.4.2.2:
121+
"""Certain values may not be compared in a filter, see RFC 7644, section 3.4.2.2.
122122
123123
"Boolean and Binary attributes SHALL cause a failed response (HTTP
124124
status code 400) with "scimType" of "invalidFilter"."

scim2_server/operators.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727

2828
def patch_resource(resource: Resource, operation: PatchOperation):
29-
"""Runs a patch operation against a resource."""
29+
"""Run a patch operation against a resource."""
3030
match operation.op:
3131
case PatchOperation.Op.add:
3232
operator = AddOperator(operation.path, operation.value)
@@ -40,7 +40,7 @@ def patch_resource(resource: Resource, operation: PatchOperation):
4040

4141

4242
def parse_attribute_path(attribute_path: str | None) -> dict[str, Any] | None:
43-
"""Parses an attribute path and returns a dictionary of attributes.
43+
"""Parse an attribute path and returns a dictionary of attributes.
4444
4545
The attributes are the named captures in the regex
4646
ATTRIBUTE_PATH_REGEX.
@@ -61,8 +61,7 @@ def parse_attribute_path(attribute_path: str | None) -> dict[str, Any] | None:
6161

6262

6363
class Operator:
64-
"""An operator operates on a resource and is constructed using a path and a
65-
value."""
64+
"""An operator operates on a resource and is constructed using a path and a value."""
6665

6766
OPERATE_ON_ROOT = True # Whether the operator may operate on the root of a resource (e.g. remove may not)
6867
REQUIRES_VALUE = True # Whether the operator modifies the resource or not
@@ -76,22 +75,22 @@ def __init__(self, path: str | None, value: Any | None):
7675
def init_return(
7776
cls, model: BaseModel, attribute: str, sub_attribute: str | None, value: Any
7877
):
79-
"""Initializes the return value if the operator returns something."""
78+
"""Initialize the return value if the operator returns something."""
8079
pass
8180

8281
def do_return(self):
83-
"""Returns the return value for the operator."""
82+
"""Return the return value for the operator."""
8483
return None
8584

8685
@classmethod
8786
def operation(
8887
cls, model: BaseModel, attribute: str, value: Any, index: int | None = None
8988
):
90-
"""Performs the actual operation of the operator."""
89+
"""Perform the actual operation of the operator."""
9190
raise NotImplementedError
9291

9392
def parse_path(self, model: BaseModel):
94-
"""Parses a path and optionally handles model extensions.
93+
"""Parse a path and optionally handles model extensions.
9594
9695
:return: A tuple of the model to operate on and the parsed path.
9796
"""
@@ -101,7 +100,7 @@ def parse_path(self, model: BaseModel):
101100
return model, parse_attribute_path(path)
102101

103102
def __call__(self, model: BaseModel):
104-
"""Executes the operator against a model."""
103+
"""Execute the operator against a model."""
105104
if not self.path:
106105
self.call_on_root(model)
107106
return self.do_return()
@@ -302,8 +301,7 @@ def operation(cls, model: BaseModel, attribute: str, value: Any):
302301

303302

304303
class ResolveResult:
305-
"""A descriptor for the result returned from the "ResolveOperator", used to
306-
resolve attributes from a model."""
304+
"""A descriptor for the result returned from the "ResolveOperator", used to resolve attributes from a model."""
307305

308306
def __init__(self):
309307
self.records = []
@@ -313,11 +311,11 @@ def __init__(self):
313311
self.sub_attribute = None
314312

315313
def add_result(self, model: BaseModel, attribute_name: str):
316-
"""Adds a result to the descriptor."""
314+
"""Add a result to the descriptor."""
317315
self.records.append((model, attribute_name))
318316

319317
def add_result_index(self, model: BaseModel, attribute_name: str, index: int):
320-
"""Adds a result to the descriptor.
318+
"""Add a result to the descriptor.
321319
322320
The resulting attribute is part of a multi-valued attribute
323321
described by its index.
@@ -387,13 +385,13 @@ def operation(
387385

388386

389387
class ResolveSortOperator(ResolveOperator):
390-
"""
391-
Helper-Operator that implements sorting, according to RFC 7644, Section 3.4.2.3
388+
"""Implement sorting in a helper Operator, according to RFC 7644, Section 3.4.2.3.
389+
392390
The ResolveResult returned by this operator contains at most 1 value, according to
393391
the specification:
394392
"[...] if it's a multi-valued attribute, resources are sorted by the value of the
395393
primary attribute (see Section 2.4 of [RFC7643]), if any, or else the first value
396-
in the list, if any. [...]"
394+
in the list, if any. [...]".
397395
398396
Since a Query can result in resources of different types, sorting by an attribute
399397
that is not defined for a certain resource type does not result in an error. No
@@ -464,7 +462,7 @@ def __call__(self, model: BaseModel):
464462
return self.value
465463

466464
def select_candidate(self, values: list[Any]) -> tuple[Any | None, int]:
467-
"""Selects a viable candidate from a list of possible values."""
465+
"""Select a viable candidate from a list of possible values."""
468466
for value in values:
469467
primary = getattr(value, "primary", False)
470468
if primary:

0 commit comments

Comments
 (0)