Skip to content

Commit bcdf87f

Browse files
committed
fix: ruff, mypy and pylint violations
Fixes: #2039
1 parent 7288de0 commit bcdf87f

File tree

6 files changed

+26
-32
lines changed

6 files changed

+26
-32
lines changed

.pre-commit-config.yaml

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ exclude: >
1515
)$
1616
repos:
1717
- repo: https://github.com/renovatebot/pre-commit-hooks
18-
rev: 41.99.7
18+
rev: 41.113.0
1919
hooks:
2020
- id: renovate-config-validator
2121
alias: renovate
@@ -54,29 +54,12 @@ repos:
5454
rev: 1.6.0
5555
hooks:
5656
- id: tox-ini-fmt
57-
58-
- repo: https://github.com/astral-sh/ruff-pre-commit
59-
rev: "v0.12.12"
60-
hooks:
61-
- id: ruff
62-
entry: sh -c 'ruff check --fix --force-exclude && ruff format --force-exclude'
63-
types_or: [python, pyi]
64-
6557
- repo: https://github.com/streetsidesoftware/cspell-cli
6658
rev: v9.2.0
6759
hooks:
6860
- id: cspell
6961
name: Spell check with cspell
7062

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-
8063
- repo: https://github.com/pre-commit/pre-commit-hooks.git
8164
rev: v6.0.0
8265
hooks:
@@ -168,8 +151,15 @@ repos:
168151
hooks:
169152
- id: pyupgrade
170153
args: ["--py310-plus"]
154+
- repo: https://github.com/astral-sh/ruff-pre-commit
155+
rev: v0.12.11
156+
hooks:
157+
- id: ruff-format
158+
alias: ruff
159+
- id: ruff-check
160+
alias: ruff
171161
- repo: https://github.com/pre-commit/mirrors-mypy.git
172-
rev: v1.17.1
162+
rev: v1.18.1
173163
hooks:
174164
- id: mypy
175165
additional_dependencies:

pyproject.toml

Lines changed: 2 additions & 0 deletions
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
@@ -371,6 +372,7 @@ builtins = ["__"]
371372
exclude = ["tests/fixtures/**", ".git"]
372373
fix = true
373374
line-length = 100
375+
unsafe-fixes = true
374376

375377
[tool.ruff.lint]
376378
ignore = [

src/ansible_navigator/tm_tokenize/fchainmap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
TValue_co = TypeVar("TValue_co", covariant=True)
99

1010

11-
class Indexable(Generic[TKey_contra, TValue_co], Protocol):
12-
def __getitem__(self, key: TKey_contra) -> TValue_co:
11+
class Indexable(Protocol[TKey_contra, TValue_co]):
12+
def __getitem__(self, key: TKey_contra) -> TValue_co: # type: ignore
1313
"""Get the value associated with the given key.
1414
1515
Args:

src/ansible_navigator/utils/compatibility.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

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

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-
os.symlink(source_link, destination_path)
251+
source_link.symlink_to(destination_path)
252252
elif source_path.is_dir():
253253
copytree(
254254
source_path,

0 commit comments

Comments
 (0)