Skip to content

Commit 08b68a5

Browse files
authored
fix: ruff, mypy and pylint violations (#2040)
1 parent 0032e02 commit 08b68a5

File tree

5 files changed

+62
-109
lines changed

5 files changed

+62
-109
lines changed

.pre-commit-config.yaml

Lines changed: 41 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,46 @@
1-
---
21
ci:
3-
# We rely on renovate to update it but there is no way to fully disable it
4-
# https://github.com/pre-commit-ci/issues/issues/83
52
autoupdate_schedule: quarterly
63
skip:
7-
- renovate-config-validator # container limits
4+
- renovate-config-validator
85
default_language_version:
9-
# ensures that we get same behavior on CI(s) as on local machines
106
python: python3.11
11-
exclude: >
12-
(?x)^(
13-
_readthedocs|
14-
.tox
15-
)$
7+
exclude: "(?x)^(\n _readthedocs|\n .tox\n)$\n"
168
repos:
179
- repo: https://github.com/renovatebot/pre-commit-hooks
18-
rev: 41.113.0
10+
rev: 41.113.6
1911
hooks:
2012
- id: renovate-config-validator
2113
alias: renovate
22-
args: [--strict]
14+
args:
15+
- --strict
2316
- repo: https://github.com/rbubley/mirrors-prettier
24-
rev: "v3.6.2"
17+
rev: v3.6.2
2518
hooks:
2619
- id: prettier
27-
# Original hook implementation is flaky due to *several* bugs described
28-
# in https://github.com/prettier/prettier/issues/12364
29-
# a) CI=1 needed to avoid incomplete output
30-
# b) two executions are needed because --list-different works correctly
31-
# only when run with --check as with --write the output will also
32-
# include other entries and logging level cannot be used to keep only
33-
# modified files listed (any file is listes using the log level, regardless if
34-
# is modified or not).
35-
# c) We avoid letting pre-commit pass each filename in order to avoid
36-
# runing multiple instances in parallel. This also ensures that running
37-
# prettier from the command line behaves identically with the pre-commit
38-
# one. No real performance downsides.
39-
# d) exit with the return code from list-different (0=none, 1=some)
40-
# rather than the write (0=successfully rewrote files). pre-commit.ci
41-
entry: env CI=1 bash -c "prettier --list-different . || ec=$? && prettier --loglevel=error --write . && exit $ec"
20+
entry:
21+
env CI=1 bash -c "prettier --list-different . || ec=$? && prettier
22+
--loglevel=error --write . && exit $ec"
4223
pass_filenames: false
4324
args: []
4425
additional_dependencies:
4526
- prettier
4627
- prettier-plugin-toml
47-
4828
- repo: https://github.com/pappasam/toml-sort
4929
rev: v0.24.3
5030
hooks:
5131
- id: toml-sort-fix
52-
5332
- repo: https://github.com/tox-dev/tox-ini-fmt
5433
rev: 1.6.0
5534
hooks:
5635
- id: tox-ini-fmt
57-
58-
- repo: https://github.com/astral-sh/ruff-pre-commit
59-
rev: "v0.13.0"
60-
hooks:
61-
- id: ruff
62-
entry: sh -c 'ruff check --fix --force-exclude && ruff format --force-exclude'
63-
types_or: [python, pyi]
64-
6536
- repo: https://github.com/streetsidesoftware/cspell-cli
6637
rev: v9.2.0
6738
hooks:
6839
- id: cspell
6940
name: Spell check with cspell
70-
71-
- repo: https://github.com/Lucas-C/pre-commit-hooks.git
72-
rev: v1.5.5
73-
hooks:
74-
- id: remove-tabs
75-
exclude: >
76-
(?x)^(
77-
.config/pylint-baseline.txt
78-
)$
79-
8041
- repo: https://github.com/pre-commit/pre-commit-hooks.git
8142
rev: v6.0.0
8243
hooks:
83-
# Side-effects:
8444
- id: trailing-whitespace
8545
- id: check-merge-conflict
8646
- id: end-of-file-fixer
@@ -90,84 +50,71 @@ repos:
9050
- id: check-case-conflict
9151
- id: check-symlinks
9252
- id: check-yaml
93-
exclude: >
94-
(?x)^
95-
(
96-
mkdocs.yml
97-
)
98-
$
53+
exclude: "(?x)^\n (\n mkdocs.yml\n )\n$\n"
9954
- id: detect-private-key
100-
# Heavy checks:
10155
- id: check-ast
10256
- id: debug-statements
103-
10457
- repo: https://gitlab.com/bmares/check-json5
105-
# Allow json comments, trailing commas
106-
# https://github.com/pre-commit/pre-commit-hooks/issues/395
10758
rev: v1.0.0
10859
hooks:
10960
- id: check-json5
110-
11161
- repo: https://github.com/igorshubovych/markdownlint-cli
11262
rev: v0.45.0
11363
hooks:
11464
- id: markdownlint
115-
exclude: >
116-
(?x)^
117-
(
118-
\.github/ISSUE_TEMPLATE/\w+|
119-
docs/(
120-
faq|
121-
index|
122-
)|
123-
README|
124-
src/ansible_navigator/data/(help|welcome)
125-
)\.md
126-
$
127-
65+
exclude:
66+
"(?x)^\n (\n \\.github/ISSUE_TEMPLATE/\\w+|\n docs/(\n faq|\n
67+
\ index|\n )|\n README|\n src/ansible_navigator/data/(help|welcome)\n
68+
\ )\\.md\n$\n"
12869
- repo: https://github.com/codespell-project/codespell
12970
rev: v2.4.1
13071
hooks:
13172
- id: codespell
132-
# NOTE: dout is part of the stdout action regex
133-
args: ["-L", "dout"]
134-
# We exclude generated and external files as they are not directly under
135-
# our control, so we cannot fix spelling in them.
136-
exclude: >
137-
(?x)^
138-
(
139-
tests/fixtures/integration/actions/.*\.json|
140-
src/ansible_navigator/data/grammar/.*\.json
141-
)
142-
$
143-
73+
args:
74+
- -L
75+
- dout
76+
exclude:
77+
"(?x)^\n (\n tests/fixtures/integration/actions/.*\\.json|\n
78+
\ src/ansible_navigator/data/grammar/.*\\.json\n )\n$\n"
14479
- repo: https://github.com/adrienverge/yamllint.git
14580
rev: v1.37.1
14681
hooks:
14782
- id: yamllint
14883
args:
14984
- --strict
150-
types: [file, yaml]
151-
85+
types:
86+
- file
87+
- yaml
15288
- repo: https://github.com/PyCQA/flake8.git
15389
rev: 7.3.0
15490
hooks:
15591
- id: flake8
15692
language_version: python3
15793
additional_dependencies:
158-
- flake8-docstrings # uses pydocstyle
159-
94+
- flake8-docstrings
16095
- repo: https://github.com/jsh9/pydoclint
16196
rev: 0.7.3
16297
hooks:
16398
- id: pydoclint
164-
16599
- repo: https://github.com/asottile/pyupgrade
166-
# keep it after flake8
167100
rev: v3.20.0
168101
hooks:
169102
- id: pyupgrade
170-
args: ["--py310-plus"]
103+
args:
104+
- --py310-plus
105+
- repo: https://github.com/pappasam/toml-sort
106+
rev: v0.24.2
107+
hooks:
108+
- id: toml-sort-fix
109+
alias: toml
110+
111+
- repo: https://github.com/astral-sh/ruff-pre-commit
112+
rev: v0.13.0
113+
hooks:
114+
- id: ruff-format
115+
alias: ruff
116+
- id: ruff-check
117+
alias: ruff
171118
- repo: https://github.com/pre-commit/mirrors-mypy.git
172119
rev: v1.18.1
173120
hooks:
@@ -182,9 +129,8 @@ repos:
182129
- types-docutils
183130
- types-mock
184131
- types-PyYAML
185-
- types-setuptools # Needed logging version
132+
- types-setuptools
186133
- types-typed-ast
187-
188134
- repo: https://github.com/pycqa/pylint.git
189135
rev: v3.3.8
190136
hooks:
@@ -197,7 +143,7 @@ repos:
197143
- ansible-core
198144
- ansible-runner
199145
- astroid
200-
- dill>=0.3.6 # needed for py311
146+
- dill>=0.3.6
201147
- jinja2
202148
- jsonschema
203149
- libtmux

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ disable = [
122122
"too-few-public-methods",
123123
"unsubscriptable-object",
124124
"unknown-option-value",
125+
"CPY001", # copyright notice at top of file
125126
# https://gist.github.com/cidrblock/ec3412bacfeb34dbc2d334c1d53bef83
126127
"C0103", # invalid-name / ruff N815
127128
"C0105", # typevar-name-incorrect-variance / ruff PLC0105
@@ -344,10 +345,13 @@ disable = [
344345
enable = [
345346
"useless-suppression" # Identify unneeded pylint disable statements
346347
]
348+
# disabled "useless-suppression" on fail-on due to conflict with needed deprecated-class on older python versions
347349
fail-on = [
348-
"useless-suppression"
349350
]
350351

352+
[tool.pylint.reports]
353+
score = false
354+
351355
[tool.pytest.ini_options]
352356
# do not add xdist options here as this will make running of a single test and
353357
# debugging hard.
@@ -371,6 +375,7 @@ builtins = ["__"]
371375
exclude = ["tests/fixtures/**", ".git"]
372376
fix = true
373377
line-length = 100
378+
unsafe-fixes = true
374379

375380
[tool.ruff.lint]
376381
ignore = [

src/ansible_navigator/utils/compatibility.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
from typing import TypeAlias
99

1010

11-
if sys.version_info < (3, 11):
12-
from importlib.abc import Traversable
13-
else:
11+
if sys.version_info >= (3, 11):
1412
from importlib.resources.abc import Traversable
13+
else:
14+
from importlib.abc import Traversable # pylint: disable=deprecated-class
1515

1616

1717
__all__ = ["Traversable", "TypeAlias", "importlib_metadata"]

src/ansible_navigator/utils/json_schema.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import json
66

7+
from collections import deque
78
from dataclasses import dataclass
89
from typing import TYPE_CHECKING
910
from typing import Any
@@ -16,10 +17,10 @@
1617

1718

1819
if TYPE_CHECKING:
19-
from collections import deque
20+
from collections.abc import Sequence
2021

2122

22-
def to_path(schema_path: deque[Any]) -> str:
23+
def to_path(schema_path: Sequence[Any] | str) -> str:
2324
"""Flatten a path to a dot delimited string.
2425
2526
Args:
@@ -28,10 +29,11 @@ def to_path(schema_path: deque[Any]) -> str:
2829
Returns:
2930
The dot delimited path
3031
"""
31-
return ".".join(str(index) for index in schema_path)
32+
queue = schema_path if isinstance(schema_path, deque) else deque(schema_path)
33+
return ".".join(str(index) for index in queue)
3234

3335

34-
def json_path(absolute_path: deque[Any]) -> str:
36+
def json_path(absolute_path: Sequence[Any]) -> str:
3537
"""Flatten a data path to a dot delimited string.
3638
3739
Args:
@@ -97,7 +99,7 @@ def validate(schema: str | dict[str, Any], data: dict[str, Any]) -> list[JsonSch
9799

98100
if isinstance(schema, str):
99101
schema = json.loads(schema)
100-
if isinstance(schema, bool):
102+
if isinstance(schema, (bool, str)):
101103
msg = "Unexpected schema data."
102104
raise TypeError(msg)
103105
validator = validator_for(schema)
@@ -129,10 +131,10 @@ def validate(schema: str | dict[str, Any], data: dict[str, Any]) -> list[JsonSch
129131
data_path=to_path(validation_error.absolute_path),
130132
json_path=json_path(validation_error.absolute_path),
131133
schema_path=to_path(validation_error.relative_schema_path),
132-
relative_schema=validation_error.schema,
133-
expected=validation_error.validator_value,
134-
validator=validation_error.validator,
135-
found=validation_error.instance,
134+
relative_schema=str(validation_error.schema),
135+
expected=str(validation_error.validator_value),
136+
validator=str(validation_error.validator),
137+
found=str(validation_error.instance),
136138
)
137139
errors.append(error)
138140
return errors

tests/integration/_common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def copytree(
248248
try:
249249
if symlinks and source_path.is_symlink():
250250
source_link = source_path.readlink()
251-
Path(destination_path).symlink_to(source_link)
251+
source_link.symlink_to(destination_path)
252252
elif source_path.is_dir():
253253
copytree(
254254
source_path,

0 commit comments

Comments
 (0)