Skip to content

Commit 91ab4ec

Browse files
authored
Merge branch 'main' into chore-format-ruff
2 parents 9cd20b4 + 0acc690 commit 91ab4ec

File tree

13 files changed

+168
-45
lines changed

13 files changed

+168
-45
lines changed

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ strict = true
7070
allow-init-docstring = true
7171
arg-type-hints-in-docstring = false
7272
check-return-types = false
73+
show-filenames-in-every-violation-message = true
74+
skip-checking-short-docstrings = false
7375
style = 'google'
7476

7577
[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 f"{' ' * (self._longest_name() - len(self.name))}{self.name.capitalize()}: "
130136

@@ -163,10 +169,12 @@ def to_lines(
163169
) -> list[str]:
164170
"""Output exit message to the console.
165171
166-
:param color: Whether to color the message
167-
:param width: Constrain message to width
168-
:param with_prefix: Whether to prefix the message
169-
:returns: The exit message as a string
172+
Args:
173+
color: Whether to color the message
174+
width: Constrain message to width
175+
with_prefix: Whether to prefix the message
176+
Returns:
177+
The exit message as a string
170178
"""
171179
prefix_length = Level.longest_formatted()
172180
indent = " " * prefix_length
@@ -254,7 +262,8 @@ def __init__( # noqa: PLR0913
254262
def critical(self: Output, msg: str) -> None:
255263
"""Print a critical message to the console.
256264
257-
:param msg: The message to print
265+
Args:
266+
msg: The message to print
258267
"""
259268
self.call_count["critical"] += 1
260269
self.log(msg, level=Level.CRITICAL)
@@ -263,56 +272,63 @@ def critical(self: Output, msg: str) -> None:
263272
def debug(self: Output, msg: str) -> None:
264273
"""Print a debug message to the console.
265274
266-
:param msg: The message to print
275+
Args:
276+
msg: The message to print
267277
"""
268278
self.call_count["debug"] += 1
269279
self.log(msg, level=Level.DEBUG)
270280

271281
def error(self: Output, msg: str) -> None:
272282
"""Print an error message to the console.
273283
274-
:param msg: The message to print
284+
Args:
285+
msg: The message to print
275286
"""
276287
self.call_count["error"] += 1
277288
self.log(msg, level=Level.ERROR)
278289

279290
def hint(self: Output, msg: str) -> None:
280291
"""Print a hint message to the console.
281292
282-
:param msg: The message to print
293+
Args:
294+
msg: The message to print
283295
"""
284296
self.call_count["hint"] += 1
285297
self.log(msg, level=Level.HINT)
286298

287299
def info(self: Output, msg: str) -> None:
288300
"""Print a hint message to the console.
289301
290-
:param msg: The message to print
302+
Args:
303+
msg: The message to print
291304
"""
292305
self.call_count["info"] += 1
293306
self.log(msg, level=Level.INFO)
294307

295308
def note(self: Output, msg: str) -> None:
296309
"""Print a note message to the console.
297310
298-
:param msg: The message to print
311+
Args:
312+
msg: The message to print
299313
"""
300314
self.call_count["note"] += 1
301315
self.log(msg, level=Level.NOTE)
302316

303317
def warning(self: Output, msg: str) -> None:
304318
"""Print a warning message to the console.
305319
306-
:param msg: The message to print
320+
Args:
321+
msg: The message to print
307322
"""
308323
self.call_count["warning"] += 1
309324
self.log(msg, level=Level.WARNING)
310325

311326
def log(self: Output, msg: str, level: Level = Level.ERROR) -> None:
312327
"""Print a message to the console.
313328
314-
:param msg: The message to print
315-
:param prefix: The prefix for the message
329+
Args:
330+
msg: The message to print
331+
level: The message level
316332
"""
317333
if self.log_to_file:
318334
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
@@ -137,7 +137,11 @@ def _install_galaxy_collections(
137137
self: Installer,
138138
collections: list[Collection],
139139
) -> None:
140-
"""Install the collection from galaxy."""
140+
"""Install the collection from galaxy.
141+
142+
Args:
143+
collections: The collection objects.
144+
"""
141145
collections_str = " ".join(
142146
[f"'{collection.original}'" for collection in collections],
143147
)

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"

src/ansible_dev_environment/utils.py

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ class TermFeatures:
4242
links: bool
4343

4444
def any_enabled(self: TermFeatures) -> bool:
45-
"""Return True if any features are enabled."""
45+
"""Return True if any features are enabled.
46+
47+
Returns:
48+
True if any features are enabled
49+
"""
4650
return any((self.color, self.links))
4751

4852

@@ -95,7 +99,18 @@ def subprocess_run( # noqa: PLR0913
9599
cwd: Path | None = None,
96100
env: dict[str, str] | None = None,
97101
) -> subprocess.CompletedProcess[str]:
98-
"""Run a subprocess command."""
102+
"""Run a subprocess command.
103+
104+
Args:
105+
command: The command to run
106+
verbose: The verbosity level
107+
msg: The message to display
108+
output: The output object
109+
cwd: The current working directory
110+
env: The environment variables
111+
Returns:
112+
The completed process
113+
"""
99114
cmd = f"Running command: {command}"
100115
output.debug(cmd)
101116
log_level = logging.ERROR - (verbose * 10)
@@ -123,8 +138,10 @@ def subprocess_run( # noqa: PLR0913
123138
def oxford_join(words: list[str]) -> str:
124139
"""Join a list of words with commas and an oxford comma.
125140
126-
:param words: A list of words to join
127-
:return: A string of words joined with commas and an oxford comma
141+
Args:
142+
words: A list of words to join
143+
Returns:
144+
A string of words joined with commas and an oxford comma
128145
"""
129146
words.sort()
130147
if not words:
@@ -139,8 +156,11 @@ def oxford_join(words: list[str]) -> str:
139156
def opt_deps_to_files(collection_path: Path, dep_str: str) -> list[Path]:
140157
"""Convert a string of optional dependencies to a list of files.
141158
142-
:param dep_str: A string of optional dependencies
143-
:return: A list of files
159+
Args:
160+
collection_path: The path to the collection
161+
dep_str: A string of optional dependencies
162+
Returns:
163+
A list of files
144164
"""
145165
deps = dep_str.split(",")
146166
files = []
@@ -286,7 +306,13 @@ def builder_introspect(config: Config, output: Output) -> None:
286306

287307

288308
def collections_from_requirements(file: Path) -> list[dict[str, str]]:
289-
"""Build a list of collections from a requirements file."""
309+
"""Build a list of collections from a requirements file.
310+
311+
Args:
312+
file: The requirements file
313+
Returns:
314+
A list of collections
315+
"""
290316
collections = []
291317
try:
292318
with file.open() as requirements_file:

0 commit comments

Comments
 (0)