Skip to content

Commit 2756110

Browse files
authored
Add darglint hook, and enable pydocstyle on ruff (#87)
1 parent 1af3001 commit 2756110

File tree

11 files changed

+136
-82
lines changed

11 files changed

+136
-82
lines changed

.darglint

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[darglint]
2+
# NOTE: All `darglint` styles except for `sphinx` hit ridiculously low
3+
# NOTE: performance on some of the in-project Python modules.
4+
# Refs:
5+
# * https://github.com/terrencepreilly/darglint/issues/186
6+
docstring_style = sphinx
7+
strictness = full

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@ repos:
2222
- id: end-of-file-fixer
2323
- id: no-commit-to-branch
2424
- id: trailing-whitespace
25+
26+
- repo: https://github.com/terrencepreilly/darglint
27+
rev: v1.8.1
28+
hooks:
29+
- id: darglint

collection_prep/cmd/__init__.py

Whitespace-only changes.

collection_prep/cmd/add_docs.py

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#!/usr/bin/env python
22
# PYTHON_ARGCOMPLETE_OK
33

4-
""" doc generator
5-
"""
4+
"""Generate or update collection documentation."""
65
import ast
76
import logging
87
import os
@@ -71,7 +70,7 @@
7170

7271

7372
def ensure_list(value):
74-
"""Ensure the value is a list
73+
"""Ensure the value is a list.
7574
7675
:param value: The value to check
7776
:type value: Unknown
@@ -83,7 +82,7 @@ def ensure_list(value):
8382

8483

8584
def convert_descriptions(data):
86-
"""Convert the descriptions for doc into lists
85+
"""Convert the descriptions for doc into lists.
8786
8887
:param data: the chunk from the doc
8988
:type data: dict
@@ -99,7 +98,7 @@ def convert_descriptions(data):
9998

10099

101100
def jinja_environment():
102-
"""Define the jinja environment
101+
"""Define the jinja environment.
103102
104103
:return: A jinja template, with the env set
105104
"""
@@ -121,12 +120,10 @@ def jinja_environment():
121120

122121

123122
def update_readme(content, path, gh_url, branch_name):
124-
"""Update the README.md in the repository
123+
"""Update the README.md in the repository.
125124
126125
:param content: The dict containing the content
127126
:type content: dict
128-
:param collection: The full collection name
129-
:type collection: str
130127
:param path: The path to the collection
131128
:type path: str
132129
:param gh_url: The url to the GitHub repository
@@ -193,9 +190,7 @@ def update_readme(content, path, gh_url, branch_name):
193190

194191

195192
def handle_simple(collection, fullpath, kind):
196-
"""Grab each plugin from a plugin file and
197-
use the def comment if available. Intended for use
198-
with "simple" plugins, like filter or tests
193+
"""Process "simple" plugins like filter or test.
199194
200195
:param collection: The full collection name
201196
:type collection: str
@@ -276,9 +271,7 @@ def handle_simple(collection, fullpath, kind):
276271
simple_map = dict(zip(keys, values))
277272
for name, func in simple_map.items():
278273
if func in function_definitions:
279-
comment = function_definitions[func] or "{collection} {name} {kind} plugin".format(
280-
collection=collection, name=name, kind=kind
281-
)
274+
comment = function_definitions[func] or f"{collection} {name} {kind} plugin"
282275

283276
# Get the first line from the docstring for the description and
284277
# make that the short description.
@@ -288,13 +281,13 @@ def handle_simple(collection, fullpath, kind):
288281

289282

290283
def process(collection: str, path: Path): # pylint: disable-msg=too-many-locals
291-
"""
292-
Process the files in each subdirectory
284+
"""Process the files in each subdirectory.
293285
294286
:param collection: The collection name
295287
:type collection: str
296288
:param path: The path to the collection
297-
:type path: str
289+
:type path: Path
290+
:return: A mapping of plugins to plugin types
298291
"""
299292
template = jinja_environment()
300293
docs_path = Path(path, "docs")
@@ -377,7 +370,7 @@ def process(collection: str, path: Path): # pylint: disable-msg=too-many-locals
377370

378371

379372
def load_galaxy(path):
380-
"""Load collection details from the galaxy.yml file in the collection
373+
"""Load collection details from the galaxy.yml file in the collection.
381374
382375
:param path: The path the collection
383376
:return: The collection name and gh url
@@ -395,7 +388,7 @@ def load_galaxy(path):
395388

396389

397390
def load_runtime(path):
398-
"""Load runtime details from the runtime.yml file in the collection
391+
"""Load runtime details from the runtime.yml file in the collection.
399392
400393
:param path: The path the collection
401394
:return: The runtime dict
@@ -413,14 +406,14 @@ def load_runtime(path):
413406

414407

415408
def link_collection(path: Path, galaxy: dict, collection_root: Optional[Path] = None):
416-
"""Link the provided collection into the Ansible default collection path
409+
"""Link the provided collection into the Ansible default collection path.
417410
418411
:param path: A path
419-
:type path: str
412+
:type path: Path
420413
:param galaxy: The galaxy.yml contents
421414
:type galaxy: dict
415+
:param collection_root: The root collections path
422416
"""
423-
424417
if collection_root is None:
425418
collection_root = Path(Path.home(), ".ansible/collections/ansible_collections")
426419

@@ -448,7 +441,12 @@ def link_collection(path: Path, galaxy: dict, collection_root: Optional[Path] =
448441

449442

450443
def add_collection(path: Path, galaxy: dict) -> Optional[tempfile.TemporaryDirectory]:
451-
"""Add path to collections dir so we can find local doc_fragments"""
444+
"""Add path to collections dir so we can find local doc_fragments.
445+
446+
:param path: The collections path
447+
:param galaxy: The contents of galaxy.yml
448+
:return: A temporary alternate directory if the collection is not in a valid location
449+
"""
452450
collections_path = None
453451
tempdir = None
454452

@@ -480,7 +478,7 @@ def add_collection(path: Path, galaxy: dict) -> Optional[tempfile.TemporaryDirec
480478

481479

482480
def add_ansible_compatibility(runtime, path):
483-
"""Add ansible compatibility information to README
481+
"""Add ansible compatibility information to README.
484482
485483
:param runtime: runtime.yml contents
486484
:type runtime: dict
@@ -515,9 +513,7 @@ def add_ansible_compatibility(runtime, path):
515513

516514

517515
def main():
518-
"""
519-
The entry point
520-
"""
516+
"""Run the script."""
521517
parser = ArgumentParser()
522518
parser.add_argument(
523519
"-p",

collection_prep/cmd/runtime.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
Get ready for 1.0.0
3-
"""
1+
"""Get ready for 1.0.0."""
42
import glob
53
import logging
64
import os
@@ -23,12 +21,21 @@
2321
REMOVAL_DAY_OF_MONTH = "01"
2422

2523

26-
def get_warning_msg(plugin_name=None):
27-
depcrecation_msg = "See the plugin documentation for more details"
28-
return depcrecation_msg
24+
def get_warning_msg():
25+
"""Return warning text for a plugin.
26+
27+
:return: Additional details on the deprecation
28+
"""
29+
return "See the plugin documentation for more details"
2930

3031

3132
def process_runtime_plugin_routing(collection, path):
33+
"""Process collection plugins to generate a plugin routing map.
34+
35+
:param collection: The name of the collection
36+
:param path: The collections path
37+
:return: A dictionary representing plugins and redirects and deprecations
38+
"""
3239
plugin_routing = {}
3340
plugins_path = f"{path}/{collection}/plugins"
3441
modules_path = f"{plugins_path}/modules"
@@ -93,7 +100,7 @@ def process_runtime_plugin_routing(collection, path):
93100
module_name: {
94101
"deprecation": {
95102
"removal_date": get_removed_at_date(),
96-
"warning_text": get_warning_msg(f"{collection}.{module_name}"),
103+
"warning_text": get_warning_msg(),
97104
}
98105
}
99106
}
@@ -106,7 +113,7 @@ def process_runtime_plugin_routing(collection, path):
106113
{
107114
"deprecation": {
108115
"removal_date": get_removed_at_date(),
109-
"warning_text": get_warning_msg(f"{collection}.{short_name}"),
116+
"warning_text": get_warning_msg(),
110117
}
111118
}
112119
)
@@ -115,6 +122,11 @@ def process_runtime_plugin_routing(collection, path):
115122

116123

117124
def process(collection, path):
125+
"""Generate or update runtime.yml on a collection.
126+
127+
:param collection: The collection name
128+
:param path: The collections path
129+
"""
118130
rt_obj = {}
119131
collection_path = os.path.join(path, collection)
120132
if not os.path.exists(collection_path):
@@ -143,9 +155,7 @@ def process(collection, path):
143155

144156

145157
def main():
146-
"""
147-
The entry point
148-
"""
158+
"""Run the script."""
149159
parser = ArgumentParser()
150160
parser.add_argument("-c", "--collection", help="The name of the collection", required=True)
151161
parser.add_argument("-p", "--path", help="The path to the collection", required=True)

collection_prep/cmd/update.py

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
Get ready for 1.0.0
3-
"""
1+
"""Get ready for 1.0.0."""
42
import logging
53
import os
64
import platform
@@ -35,8 +33,7 @@
3533

3634

3735
def remove_assigment_in_ast(name, ast_file):
38-
"""
39-
REmoves an assignment in an ast object
36+
"""Remove an assignment in an ast object.
4037
4138
:param name: The name of the assignement to remove
4239
:param ast_file: The ast object
@@ -47,9 +44,9 @@ def remove_assigment_in_ast(name, ast_file):
4744

4845

4946
def retrieve_plugin_name(plugin_type, bodypart):
50-
"""
51-
Retrieve the module name from a docstring
47+
"""Retrieve the module name from a docstring.
5248
49+
:param plugin_type: The plugin's type
5350
:param bodypart: The doctstring extracted from the ast body
5451
:return: The module name
5552
"""
@@ -65,15 +62,18 @@ def retrieve_plugin_name(plugin_type, bodypart):
6562

6663

6764
def update_deprecation_notice(documentation):
65+
"""Update deprecation notices to use removed_at_date instead of removed_in.
66+
67+
:param documentation: The DOCUMENTATION section of the module
68+
"""
6869
if "deprecated" in documentation:
6970
logging.info("Updating deprecation notice")
7071
documentation["deprecated"].update({"removed_at_date": get_removed_at_date()})
7172
documentation["deprecated"].pop("removed_in", None)
7273

7374

7475
def update_documentation(bodypart):
75-
"""
76-
Update the docuementation of the module
76+
"""Update the documentation of the module.
7777
7878
:param bodypart: The DOCUMENTATION section of the module
7979
"""
@@ -100,14 +100,12 @@ def update_documentation(bodypart):
100100

101101

102102
def update_examples(bodypart, module_name, collection):
103-
"""
104-
Update the example
103+
"""Update the example.
105104
106105
:param bodypart: The EXAMPLE section of the module
107106
:param module_name: The name of the module
108107
:param collection: The name of the collection
109108
"""
110-
111109
if not bodypart:
112110
logging.warning("Failed to find EXAMPLES assignment")
113111
return
@@ -135,10 +133,10 @@ def update_examples(bodypart, module_name, collection):
135133

136134

137135
def update_short_description(retrn, documentation, module_name):
138-
"""
139-
Update the short description of the module
136+
"""Update the short description of the module.
140137
141-
:param bodypart: The DOCUMENTATION section of the module
138+
:param retrn: The RETURN section of the module
139+
:param documentation: The DOCUMENTATION section of the module
142140
:param module_name: The module name
143141
"""
144142
if not retrn:
@@ -186,8 +184,7 @@ def update_short_description(retrn, documentation, module_name):
186184

187185

188186
def black(filename):
189-
"""
190-
Run black against the file
187+
"""Run black against the file.
191188
192189
:param filename: The full path to the file
193190
"""
@@ -196,8 +193,10 @@ def black(filename):
196193

197194

198195
def process(collection, path):
199-
"""
200-
Process the files in each subdirectory
196+
"""Process the files in each subdirectory.
197+
198+
:param collection: The name of the collection
199+
:param path: The collections path
201200
"""
202201
for subdir in SUBDIRS:
203202
dirpath = f"{path}{collection}/plugins/{subdir}"
@@ -257,9 +256,7 @@ def process(collection, path):
257256

258257

259258
def main():
260-
"""
261-
The entry point
262-
"""
259+
"""Run the script."""
263260
if not platform.python_version().startswith("3.8"):
264261
sys.exit("Python 3.8+ required")
265262
parser = ArgumentParser()

0 commit comments

Comments
 (0)