Skip to content

Commit 0acc690

Browse files
authored
Update pydoclint config and fix docstrings (#155)
* Update pydoclint config and fix docstrings * Remove uneeded ignore
1 parent 044c4fc commit 0acc690

File tree

13 files changed

+181
-58
lines changed

13 files changed

+181
-58
lines changed

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ strict = true
6767
allow-init-docstring = true
6868
arg-type-hints-in-docstring = false
6969
check-return-types = false
70+
show-filenames-in-every-violation-message = true
71+
skip-checking-short-docstrings = false
7072
style = 'google'
7173

7274
[tool.pylint]

src/ansible_dev_environment/arg_parser.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66

77
from argparse import HelpFormatter
88
from pathlib import Path
9+
from typing import TYPE_CHECKING
910

1011

12+
if TYPE_CHECKING:
13+
from typing import Any
14+
1115
try:
1216
from ._version import version as __version__ # type: ignore[unused-ignore,import-not-found]
1317
except ImportError: # pragma: no cover
@@ -214,12 +218,17 @@ def parse() -> argparse.Namespace:
214218
class ArgumentParser(argparse.ArgumentParser):
215219
"""A custom argument parser."""
216220

217-
def add_argument( # type: ignore[no-untyped-def, override]
221+
def add_argument( # type: ignore[override]
218222
self: ArgumentParser,
219-
*args, # noqa: ANN002
220-
**kwargs, # noqa: ANN003
223+
*args: Any, # noqa: ANN401
224+
**kwargs: Any, # noqa: ANN401
221225
) -> None:
222-
"""Add an argument."""
226+
"""Add an argument.
227+
228+
Args:
229+
*args: The arguments
230+
**kwargs: The keyword arguments
231+
"""
223232
if "choices" in kwargs:
224233
kwargs["help"] += f" (choices: {', '.join(kwargs['choices'])})"
225234
if "default" in kwargs and kwargs["default"] != "==SUPPRESS==":
@@ -234,7 +243,8 @@ class CustomHelpFormatter(HelpFormatter):
234243
def __init__(self: CustomHelpFormatter, prog: str) -> None:
235244
"""Initialize the help formatter.
236245
237-
:param prog: The program name
246+
Args:
247+
prog: The program name
238248
"""
239249
long_string = "--abc --really_really_really_log"
240250
# 3 here accounts for the spaces in the ljust(6) below

src/ansible_dev_environment/collection.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,13 @@ def build_dir(self: Collection) -> Path:
5454

5555
@property
5656
def site_pkg_path(self: Collection) -> Path:
57-
"""Return the site packages collection path."""
57+
"""Return the site packages collection path.
58+
59+
Returns:
60+
The site packages collection path
61+
Raises:
62+
RuntimeError: If the collection namespace or name is not set
63+
"""
5864
if not self.cnamespace or not self.cname:
5965
msg = "Collection namespace or name not set."
6066
raise RuntimeError(msg)

src/ansible_dev_environment/config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ def __init__(
3131
output: Output,
3232
term_features: TermFeatures,
3333
) -> None:
34-
"""Initialize the configuration."""
34+
"""Initialize the configuration.
35+
36+
Args:
37+
args: The command line arguments
38+
output: The output object
39+
term_features: The terminal features
40+
"""
3541
self._create_venv: bool = False
3642
self.args: Namespace = args
3743
self.bindir: Path

src/ansible_dev_environment/output.py

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ def round_half_up(number: float) -> int:
3030
3131
This will always round based on distance from zero. (e.g round(2.5) = 3, round(3.5) = 4).
3232
33-
:param number: The number to round
34-
:returns: The rounded number as an it
33+
Args:
34+
number: The number to round
35+
Returns:
36+
The rounded number as an it
3537
"""
3638
rounded = decimal.Decimal(number).quantize(
3739
decimal.Decimal("1"),
@@ -43,7 +45,8 @@ def round_half_up(number: float) -> int:
4345
def console_width() -> int:
4446
"""Get a console width based on common screen widths.
4547
46-
:returns: The console width
48+
Returns:
49+
The console width
4750
"""
4851
medium = 80
4952
wide = 132
@@ -109,22 +112,25 @@ def log_level(self: Level) -> int:
109112
def _longest_name(cls: type[T]) -> int:
110113
"""Return the longest exit message prefix.
111114
112-
:returns: The longest exit message prefix
115+
Returns:
116+
The longest exit message prefix
113117
"""
114118
return max(len(member.value) for member in cls)
115119

116120
@classmethod
117121
def longest_formatted(cls: type[T]) -> int:
118122
"""Return the longest exit message prefix.
119123
120-
:returns: The longest exit message prefix
124+
Returns:
125+
The longest exit message prefix
121126
"""
122127
return max(len(str(member)) for member in cls)
123128

124129
def __str__(self: Level) -> str:
125130
"""Return the exit message prefix as a string.
126131
127-
:returns: The exit message prefix as a string
132+
Returns:
133+
The exit message prefix as a string
128134
"""
129135
return (
130136
f"{' ' * (self._longest_name() - len(self.name))}{self.name.capitalize()}: "
@@ -165,10 +171,12 @@ def to_lines(
165171
) -> list[str]:
166172
"""Output exit message to the console.
167173
168-
:param color: Whether to color the message
169-
:param width: Constrain message to width
170-
:param with_prefix: Whether to prefix the message
171-
:returns: The exit message as a string
174+
Args:
175+
color: Whether to color the message
176+
width: Constrain message to width
177+
with_prefix: Whether to prefix the message
178+
Returns:
179+
The exit message as a string
172180
"""
173181
prefix_length = Level.longest_formatted()
174182
indent = " " * prefix_length
@@ -256,7 +264,8 @@ def __init__( # noqa: PLR0913
256264
def critical(self: Output, msg: str) -> None:
257265
"""Print a critical message to the console.
258266
259-
:param msg: The message to print
267+
Args:
268+
msg: The message to print
260269
"""
261270
self.call_count["critical"] += 1
262271
self.log(msg, level=Level.CRITICAL)
@@ -265,56 +274,63 @@ def critical(self: Output, msg: str) -> None:
265274
def debug(self: Output, msg: str) -> None:
266275
"""Print a debug message to the console.
267276
268-
:param msg: The message to print
277+
Args:
278+
msg: The message to print
269279
"""
270280
self.call_count["debug"] += 1
271281
self.log(msg, level=Level.DEBUG)
272282

273283
def error(self: Output, msg: str) -> None:
274284
"""Print an error message to the console.
275285
276-
:param msg: The message to print
286+
Args:
287+
msg: The message to print
277288
"""
278289
self.call_count["error"] += 1
279290
self.log(msg, level=Level.ERROR)
280291

281292
def hint(self: Output, msg: str) -> None:
282293
"""Print a hint message to the console.
283294
284-
:param msg: The message to print
295+
Args:
296+
msg: The message to print
285297
"""
286298
self.call_count["hint"] += 1
287299
self.log(msg, level=Level.HINT)
288300

289301
def info(self: Output, msg: str) -> None:
290302
"""Print a hint message to the console.
291303
292-
:param msg: The message to print
304+
Args:
305+
msg: The message to print
293306
"""
294307
self.call_count["info"] += 1
295308
self.log(msg, level=Level.INFO)
296309

297310
def note(self: Output, msg: str) -> None:
298311
"""Print a note message to the console.
299312
300-
:param msg: The message to print
313+
Args:
314+
msg: The message to print
301315
"""
302316
self.call_count["note"] += 1
303317
self.log(msg, level=Level.NOTE)
304318

305319
def warning(self: Output, msg: str) -> None:
306320
"""Print a warning message to the console.
307321
308-
:param msg: The message to print
322+
Args:
323+
msg: The message to print
309324
"""
310325
self.call_count["warning"] += 1
311326
self.log(msg, level=Level.WARNING)
312327

313328
def log(self: Output, msg: str, level: Level = Level.ERROR) -> None:
314329
"""Print a message to the console.
315330
316-
:param msg: The message to print
317-
:param prefix: The prefix for the message
331+
Args:
332+
msg: The message to print
333+
level: The message level
318334
"""
319335
if self.log_to_file:
320336
self.logger.log(level.log_level, msg, stacklevel=3)

src/ansible_dev_environment/subcommands/installer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ def _install_galaxy_collections(
146146
self: Installer,
147147
collections: list[Collection],
148148
) -> None:
149-
"""Install the collection from galaxy."""
149+
"""Install the collection from galaxy.
150+
151+
Args:
152+
collections: The collection objects.
153+
"""
150154
collections_str = " ".join(
151155
[f"'{collection.original}'" for collection in collections],
152156
)

src/ansible_dev_environment/subcommands/lister.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ def __init__(self: Lister, config: Config, output: Output) -> None:
2626
self._output = output
2727

2828
def run(self: Lister) -> None:
29-
"""Run the Lister."""
29+
"""Run the Lister.
30+
31+
Raises:
32+
TypeError: If the link is not a string.
33+
"""
3034
# pylint: disable=too-many-locals
3135
collections = collect_manifests(
3236
target=self._config.site_pkg_collections_path,

src/ansible_dev_environment/subcommands/treemaker.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ def __init__(self: TreeMaker, config: Config, output: Output) -> None:
3030
self._output = output
3131

3232
def run(self: TreeMaker) -> None: # noqa: C901, PLR0912, PLR0915
33-
"""Run the command."""
33+
"""Run the command.
34+
35+
Raises:
36+
TypeError: If the tree dict is not a dict.
37+
"""
3438
# pylint: disable=too-many-locals
3539
builder_introspect(self._config, self._output)
3640

src/ansible_dev_environment/tree.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ def __init__(
2323
obj: JSONVal,
2424
term_features: TermFeatures,
2525
) -> None:
26-
"""Initialize the renderer."""
26+
"""Initialize the renderer.
27+
28+
Args:
29+
obj: The object to render
30+
term_features: The terminal features
31+
"""
2732
self.obj = obj
2833
self._lines: list[str] = []
2934
self.blue: list[ScalarVal] = []
@@ -85,7 +90,13 @@ def in_color(self: Tree, val: ScalarVal) -> str:
8590

8691
@staticmethod
8792
def is_scalar(obj: JSONVal) -> bool:
88-
"""Check if the object is a scalar."""
93+
"""Check if the object is a scalar.
94+
95+
Args:
96+
obj: The object to check
97+
Returns:
98+
Whether the object is a scalar
99+
"""
89100
return isinstance(obj, str | int | float | bool) or obj is None
90101

91102
def _print_tree( # noqa: C901, PLR0913, PLR0912
@@ -167,11 +178,19 @@ def _print_tree( # noqa: C901, PLR0913, PLR0912
167178
raise TypeError(err)
168179

169180
def append(self: Tree, string: str) -> None:
170-
"""Append a line to the output."""
181+
"""Append a line to the output.
182+
183+
Args:
184+
string: The string to append
185+
"""
171186
self._lines.append(string)
172187

173188
def render(self: Tree) -> str:
174-
"""Render the root of the tree."""
189+
"""Render the root of the tree.
190+
191+
Returns:
192+
The rendered tree
193+
"""
175194
# if not isinstance(self.obj, dict):
176195
self._print_tree(self.obj, is_last=False, is_root=True, was_list=False)
177196
return "\n".join(self._lines) + "\n"

0 commit comments

Comments
 (0)