Skip to content

Commit da4a3c6

Browse files
authored
Add ruff and mypy into tox (#188)
* Add extra ruff checks * Add mypy test target * Add missing __init__ file * Enable check_untyped_defs in mypy
1 parent ce35d80 commit da4a3c6

File tree

6 files changed

+31
-6
lines changed

6 files changed

+31
-6
lines changed

capi_janitor/__init__.py

Whitespace-only changes.

capi_janitor/openstack/operator.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
import kopf
99
import yaml
1010

11-
import easykube # type: ignore
11+
import easykube
1212
import httpx
1313

1414
from . import openstack
1515

16-
ekconfig = None
17-
ekclient = None
16+
ekconfig: easykube.Configuration
17+
ekclient: easykube.AsyncClient
1818

1919
CAPO_API_GROUP = "infrastructure.cluster.x-k8s.io"
2020
FINALIZER = "janitor.capi.stackhpc.com"
@@ -310,7 +310,7 @@ async def wrapper(**kwargs):
310310
kwargs["logger"].warn(str(exc))
311311
backoff = exc.delay
312312
elif isinstance(
313-
exc, (FinalizerStillPresentError, ResourcesStillPresentError)
313+
exc, FinalizerStillPresentError | ResourcesStillPresentError
314314
):
315315
kwargs["logger"].warn(str(exc))
316316
backoff = 5
@@ -319,6 +319,8 @@ async def wrapper(**kwargs):
319319
# Calculate the backoff
320320
backoff = RETRY_DEFAULT_DELAY
321321
# Wait for the backoff before annotating the resource
322+
if backoff is None:
323+
backoff = RETRY_DEFAULT_DELAY
322324
await asyncio.sleep(backoff)
323325
# Annotate the object with a random value to trigger another event
324326
try:

capi_janitor/tests/openstack/test_operator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async def test_operator(self):
1515
mock_easykube = mock.AsyncMock(spec=easykube.AsyncClient)
1616
operator.ekclient = mock_easykube
1717

18-
await operator.on_cleanup()
18+
await operator.on_cleanup() # type: ignore
1919

2020
mock_easykube.aclose.assert_awaited_once_with()
2121

pyproject.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,21 @@ builtins = ["_"]
2323
quote-style = "double"
2424
indent-style = "space"
2525
line-ending = "auto"
26+
27+
[tool.ruff.lint]
28+
select = [
29+
# pycodestyle
30+
"E",
31+
# Pyflakes
32+
"F",
33+
# flake8-async
34+
"ASYNC",
35+
# pyupgrade
36+
"UP",
37+
]
38+
39+
[tool.mypy]
40+
follow_imports = "silent"
41+
warn_redundant_casts = true
42+
warn_unused_ignores = true
43+
check_untyped_defs = true

test-requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ coverage>=4.0,!=4.4 # Apache-2.0
55
stestr>=4.2.0 # Apache-2.0
66
codespell
77
types-PyYAML
8+
types-setuptools
9+
mypy

tox.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tox]
22
minversion = 4.0.0
3-
envlist = py3,ruff,codespell,pep8
3+
envlist = py3,ruff,codespell,pep8,mypy
44
skipsdist = True
55

66
[testenv]
@@ -45,6 +45,9 @@ commands =
4545
coverage xml -o cover/coverage.xml
4646
coverage report
4747

48+
[testenv:mypy]
49+
commands = mypy {tox_root} {posargs}
50+
4851
[flake8]
4952
# select only hacking errors
5053
select = H

0 commit comments

Comments
 (0)