Skip to content

Commit 1c4ea9f

Browse files
authored
Remove self type (#266)
1 parent bce3317 commit 1c4ea9f

17 files changed

+132
-97
lines changed

.pre-commit-config.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,23 @@ repos:
5959
- id: tox-ini-fmt
6060

6161
- repo: https://github.com/astral-sh/ruff-pre-commit
62-
rev: v0.7.2
62+
rev: v0.7.3
6363
hooks:
6464
- id: ruff
6565
args:
66+
- --fix
6667
- --exit-non-zero-on-fix
68+
types_or: [python, pyi]
69+
- id: ruff-format # must be after ruff
70+
types_or: [python, pyi]
71+
72+
- repo: https://github.com/psf/black # must be after ruff
73+
rev: 24.10.0
74+
hooks:
75+
- id: black
6776

6877
- repo: https://github.com/streetsidesoftware/cspell-cli
69-
rev: v8.15.2
78+
rev: v8.16.0
7079
hooks:
7180
- id: cspell
7281
name: Spell check with cspell

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,10 @@ line-length = 100
333333
target-version = "py310"
334334

335335
[tool.ruff.lint]
336+
ignore = [
337+
"COM812", # conflicts with ISC001 on format
338+
"ISC001" # conflicts with COM812 on format
339+
]
336340
select = ["ALL"]
337341

338342
[tool.ruff.lint.flake8-pytest-style]

src/ansible_dev_environment/arg_parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ class ArgumentParser(argparse.ArgumentParser):
223223
"""A custom argument parser."""
224224

225225
def add_argument( # type: ignore[override]
226-
self: ArgumentParser,
226+
self,
227227
*args: Any, # noqa: ANN401
228228
**kwargs: Any, # noqa: ANN401
229229
) -> None:
@@ -244,7 +244,7 @@ def add_argument( # type: ignore[override]
244244
class CustomHelpFormatter(HelpFormatter):
245245
"""A custom help formatter."""
246246

247-
def __init__(self: CustomHelpFormatter, prog: str) -> None:
247+
def __init__(self, prog: str) -> None:
248248
"""Initialize the help formatter.
249249
250250
Args:
@@ -260,7 +260,7 @@ def __init__(self: CustomHelpFormatter, prog: str) -> None:
260260
)
261261

262262
def _format_action_invocation(
263-
self: CustomHelpFormatter,
263+
self,
264264
action: argparse.Action,
265265
) -> str:
266266
"""Format the action invocation.

src/ansible_dev_environment/cli.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,22 @@
2424
class Cli:
2525
"""The Cli class."""
2626

27-
def __init__(self: Cli) -> None:
27+
def __init__(self) -> None:
2828
"""Initialize the CLI and parse CLI args."""
2929
self.args: Namespace
3030
self.config: Config
3131
self.output: Output
3232
self.term_features: TermFeatures
3333

34-
def parse_args(self: Cli) -> None:
34+
def parse_args(self) -> None:
3535
"""Parse the command line arguments."""
3636
self.args = parse()
3737
if hasattr(self.args, "requirement") and self.args.requirement:
3838
self.args.requirement = Path(self.args.requirement).expanduser().resolve()
3939
if self.args.cpi:
4040
self.args.requirement = Path(".config/source-requirements.yml").expanduser().resolve()
4141

42-
def init_output(self: Cli) -> None:
42+
def init_output(self) -> None:
4343
"""Initialize the output object."""
4444
if not sys.stdout.isatty():
4545
self.term_features = TermFeatures(color=False, links=False)
@@ -57,7 +57,7 @@ def init_output(self: Cli) -> None:
5757
verbosity=self.args.verbose,
5858
)
5959

60-
def args_sanity(self: Cli) -> None:
60+
def args_sanity(self) -> None:
6161
"""Perform some sanity checking on the args."""
6262
# Missing args
6363
if (
@@ -88,7 +88,7 @@ def args_sanity(self: Cli) -> None:
8888
err = "Editable can not be used with a requirements file."
8989
self.output.critical(err)
9090

91-
def ensure_isolated(self: Cli) -> None:
91+
def ensure_isolated(self) -> None:
9292
"""Ensure the environment is isolated."""
9393
env_vars = os.environ
9494
errored = False
@@ -139,7 +139,7 @@ def ensure_isolated(self: Cli) -> None:
139139

140140
self.output.critical(err)
141141

142-
def run(self: Cli) -> None:
142+
def run(self) -> None:
143143
"""Run the application."""
144144
self.config = Config(
145145
args=self.args,
@@ -153,7 +153,7 @@ def run(self: Cli) -> None:
153153
subcommand.run()
154154
self._exit()
155155

156-
def _exit(self: Cli) -> None:
156+
def _exit(self) -> None:
157157
"""Exit the application setting the return code."""
158158
if self.output.call_count["error"]:
159159
sys.exit(1)

src/ansible_dev_environment/collection.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,28 @@ class Collection: # pylint: disable=too-many-instance-attributes
4343
original: str
4444

4545
@property
46-
def name(self: Collection) -> str:
46+
def name(self) -> str:
4747
"""Return the collection name."""
4848
return f"{self.cnamespace}.{self.cname}"
4949

5050
@property
51-
def cache_dir(self: Collection) -> Path:
51+
def cache_dir(self) -> Path:
5252
"""Return the collection cache directory."""
5353
collection_cache_dir = self.config.venv_cache_dir / self.name
5454
if not collection_cache_dir.exists():
5555
collection_cache_dir.mkdir()
5656
return collection_cache_dir
5757

5858
@property
59-
def build_dir(self: Collection) -> Path:
59+
def build_dir(self) -> Path:
6060
"""Return the collection cache directory."""
6161
collection_build_dir = self.cache_dir / "build"
6262
if not collection_build_dir.exists():
6363
collection_build_dir.mkdir()
6464
return collection_build_dir
6565

6666
@property
67-
def site_pkg_path(self: Collection) -> Path:
67+
def site_pkg_path(self) -> Path:
6868
"""Return the site packages collection path.
6969
7070
Returns:

src/ansible_dev_environment/config.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Config:
2626

2727
# pylint: disable=too-many-instance-attributes
2828
def __init__(
29-
self: Config,
29+
self,
3030
args: Namespace,
3131
output: Output,
3232
term_features: TermFeatures,
@@ -47,7 +47,7 @@ def __init__(
4747
self.venv_interpreter: Path
4848
self.term_features: TermFeatures = term_features
4949

50-
def init(self: Config) -> None:
50+
def init(self) -> None:
5151
"""Initialize the configuration."""
5252
if self.args.venv:
5353
self._create_venv = True
@@ -56,15 +56,15 @@ def init(self: Config) -> None:
5656
self._set_site_pkg_path()
5757

5858
@property
59-
def cache_dir(self: Config) -> Path:
59+
def cache_dir(self) -> Path:
6060
"""Return the cache directory."""
6161
cache_dir = self.venv / ".ansible-dev-environment"
6262
if not cache_dir.exists():
6363
cache_dir.mkdir(parents=True)
6464
return cache_dir
6565

6666
@property
67-
def venv(self: Config) -> Path:
67+
def venv(self) -> Path:
6868
"""Return the virtual environment path.
6969
7070
Raises:
@@ -80,40 +80,40 @@ def venv(self: Config) -> Path:
8080
raise SystemExit(1) # pragma: no cover # critical exits
8181

8282
@property
83-
def venv_cache_dir(self: Config) -> Path:
83+
def venv_cache_dir(self) -> Path:
8484
"""Return the virtual environment cache directory."""
8585
return self.cache_dir
8686

8787
@property
88-
def discovered_python_reqs(self: Config) -> Path:
88+
def discovered_python_reqs(self) -> Path:
8989
"""Return the discovered python requirements file."""
9090
return self.venv_cache_dir / "discovered_requirements.txt"
9191

9292
@property
93-
def discovered_bindep_reqs(self: Config) -> Path:
93+
def discovered_bindep_reqs(self) -> Path:
9494
"""Return the discovered system package requirements file."""
9595
return self.venv_cache_dir / "discovered_bindep.txt"
9696

9797
@property
98-
def site_pkg_collections_path(self: Config) -> Path:
98+
def site_pkg_collections_path(self) -> Path:
9999
"""Return the site packages collection path."""
100100
site_pkg_collections_path = self.site_pkg_path / "ansible_collections"
101101
if not site_pkg_collections_path.exists():
102102
site_pkg_collections_path.mkdir()
103103
return site_pkg_collections_path
104104

105105
@property
106-
def venv_bindir(self: Config) -> Path:
106+
def venv_bindir(self) -> Path:
107107
"""Return the virtual environment bin directory."""
108108
return self.venv / "bin"
109109

110110
@property
111-
def interpreter(self: Config) -> Path:
111+
def interpreter(self) -> Path:
112112
"""Return the current interpreter."""
113113
return Path(sys.executable)
114114

115115
@property
116-
def galaxy_bin(self: Config) -> Path:
116+
def galaxy_bin(self) -> Path:
117117
"""Find the ansible galaxy command.
118118
119119
Prefer the venv over the system package over the PATH.
@@ -141,7 +141,7 @@ def galaxy_bin(self: Config) -> Path:
141141
raise SystemExit(1) # pragma: no cover # critical exits
142142

143143
def _set_interpreter(
144-
self: Config,
144+
self,
145145
) -> None:
146146
"""Set the interpreter."""
147147
if not self.venv.exists():
@@ -179,7 +179,7 @@ def _set_interpreter(
179179
self._output.debug(msg)
180180
self.venv_interpreter = venv_interpreter
181181

182-
def _set_site_pkg_path(self: Config) -> None:
182+
def _set_site_pkg_path(self) -> None:
183183
"""Use the interpreter to find the site packages path."""
184184
command = (
185185
f"{self.venv_interpreter} -c"

src/ansible_dev_environment/output.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class Level(Enum):
9191
WARNING = "Warning"
9292

9393
@property
94-
def log_level(self: Level) -> int:
94+
def log_level(self) -> int:
9595
"""Return a log level.
9696
9797
:returns: The log level
@@ -125,7 +125,7 @@ def longest_formatted(cls) -> int:
125125
"""
126126
return max(len(str(member)) for member in cls)
127127

128-
def __str__(self: Level) -> str:
128+
def __str__(self) -> str:
129129
"""Return the exit message prefix as a string.
130130
131131
Returns:
@@ -144,7 +144,7 @@ class Msg:
144144
prefix: Level = Level.ERROR
145145

146146
@property
147-
def color(self: Msg) -> str:
147+
def color(self) -> str:
148148
"""Return a color for the prefix.
149149
150150
:returns: The color for the prefix
@@ -161,7 +161,7 @@ def color(self: Msg) -> str:
161161
return color_mapping[self.prefix]
162162

163163
def to_lines(
164-
self: Msg,
164+
self,
165165
color: bool, # noqa: FBT001
166166
width: int,
167167
with_prefix: bool, # noqa: FBT001
@@ -213,7 +213,7 @@ class Output:
213213
"""Output functionality."""
214214

215215
def __init__( # pylint: disable=too-many-positional-arguments
216-
self: Output,
216+
self,
217217
log_file: str,
218218
log_level: str,
219219
log_append: str,
@@ -258,7 +258,7 @@ def __init__( # pylint: disable=too-many-positional-arguments
258258
else:
259259
self.log_to_file = False
260260

261-
def critical(self: Output, msg: str) -> None:
261+
def critical(self, msg: str) -> None:
262262
"""Print a critical message to the console.
263263
264264
Args:
@@ -268,7 +268,7 @@ def critical(self: Output, msg: str) -> None:
268268
self.log(msg, level=Level.CRITICAL)
269269
sys.exit(1)
270270

271-
def debug(self: Output, msg: str) -> None:
271+
def debug(self, msg: str) -> None:
272272
"""Print a debug message to the console.
273273
274274
Args:
@@ -277,7 +277,7 @@ def debug(self: Output, msg: str) -> None:
277277
self.call_count["debug"] += 1
278278
self.log(msg, level=Level.DEBUG)
279279

280-
def error(self: Output, msg: str) -> None:
280+
def error(self, msg: str) -> None:
281281
"""Print an error message to the console.
282282
283283
Args:
@@ -286,7 +286,7 @@ def error(self: Output, msg: str) -> None:
286286
self.call_count["error"] += 1
287287
self.log(msg, level=Level.ERROR)
288288

289-
def hint(self: Output, msg: str) -> None:
289+
def hint(self, msg: str) -> None:
290290
"""Print a hint message to the console.
291291
292292
Args:
@@ -295,7 +295,7 @@ def hint(self: Output, msg: str) -> None:
295295
self.call_count["hint"] += 1
296296
self.log(msg, level=Level.HINT)
297297

298-
def info(self: Output, msg: str) -> None:
298+
def info(self, msg: str) -> None:
299299
"""Print a hint message to the console.
300300
301301
Args:
@@ -304,7 +304,7 @@ def info(self: Output, msg: str) -> None:
304304
self.call_count["info"] += 1
305305
self.log(msg, level=Level.INFO)
306306

307-
def note(self: Output, msg: str) -> None:
307+
def note(self, msg: str) -> None:
308308
"""Print a note message to the console.
309309
310310
Args:
@@ -313,7 +313,7 @@ def note(self: Output, msg: str) -> None:
313313
self.call_count["note"] += 1
314314
self.log(msg, level=Level.NOTE)
315315

316-
def warning(self: Output, msg: str) -> None:
316+
def warning(self, msg: str) -> None:
317317
"""Print a warning message to the console.
318318
319319
Args:
@@ -322,7 +322,7 @@ def warning(self: Output, msg: str) -> None:
322322
self.call_count["warning"] += 1
323323
self.log(msg, level=Level.WARNING)
324324

325-
def log(self: Output, msg: str, level: Level = Level.ERROR) -> None:
325+
def log(self, msg: str, level: Level = Level.ERROR) -> None:
326326
"""Print a message to the console.
327327
328328
Args:

0 commit comments

Comments
 (0)