Skip to content

Commit 7c2b2aa

Browse files
committed
chore: enable mypy with baseline
Related: orsinium-labs/mypy-baseline#30
1 parent f153ae6 commit 7c2b2aa

File tree

44 files changed

+509
-31
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+509
-31
lines changed

mypy-baseline.txt

Lines changed: 279 additions & 0 deletions
Large diffs are not rendered by default.

pyproject.toml

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,28 @@ docker = [
2222
lint = [
2323
"molecule>=25.7.0",
2424
"pre-commit>=4.1",
25-
"pre-commit-uv>=4.1.4",
26-
"toml>=0.10.2"
25+
"pre-commit-uv>=4.1.4"
2726
]
2827
pkg = [
2928
"build>=0.9",
3029
"pip>=25.2",
3130
"pipx>=1.7.1",
3231
"twine>=4.0.1"
3332
]
33+
type = [
34+
"types-docker",
35+
"mypy>=1.17.1",
36+
"mypy-baseline>=0.7.3",
37+
"pytest", # for mypy
38+
"toml>=0.10.2",
39+
"types-toml>=0.10.8.20240310",
40+
"openstacksdk>=4.7.0",
41+
"boto3>=1.40.26",
42+
"google-auth>=2.40.3",
43+
"python-vagrant>=1.0.0",
44+
"ansible-core>=2.17.13",
45+
"pycryptodome>=3.23.0"
46+
]
3447

3548
[project]
3649
# https://peps.python.org/pep-0621/#readme
@@ -122,16 +135,36 @@ changelog = "https://github.com/ansible-community/molecule-plugins/releases"
122135
[tool.codespell]
123136
skip = "uv.lock"
124137

138+
[tool.mypy]
139+
files = "."
140+
color_output = true
141+
error_summary = true
142+
# explicit_package_bases = true
143+
namespace_packages = false
144+
exclude = [
145+
".ansible",
146+
".cache",
147+
".tox",
148+
".venv",
149+
"node_modules",
150+
"build",
151+
"dist",
152+
"site",
153+
"scenarios"
154+
]
155+
strict = true
156+
125157
[tool.pytest.ini_options]
126158
addopts = "-v -rxXs --doctest-modules --durations 10 -p no:pytest_ansible"
127159
doctest_optionflags = "ALLOW_UNICODE ELLIPSIS"
128160
junit_suite_name = "molecule_test_suite"
129161
norecursedirs = ["dist", "doc", "build", ".tox", ".eggs", "src", "test/*/scenarios", "test/*/resources"]
130162

131163
[tool.ruff]
132-
target-version = "py39"
164+
target-version = "py310"
133165
# Same as Black.
134166
line-length = 88
167+
unsafe-fixes = true
135168
lint.ignore = [
136169
"E501", # we use black
137170
# we deliberately ignore these:
@@ -195,12 +228,13 @@ uv_sync_flags = ["--upgrade", "--prerelease=allow"]
195228
uv_sync_locked = false
196229

197230
[tool.tox.env.lint]
198-
dependency_groups = ["lint"]
231+
dependency_groups = ["lint", "dev", "type"]
199232
description = "Run all linters"
200233
runner = "uv-venv-lock-runner"
201-
skip_install = false
202234
commands_pre = []
203235
commands = [
236+
# move inside a pre-commit hook once https://github.com/orsinium-labs/mypy-baseline/pull/30 is released
237+
["bash", "-c", "mypy --no-error-summary --hide-error-context | mypy-baseline filter --hide-stats --allow-unsynced && mypy --no-error-summary --hide-error-context | mypy-baseline sync --sort-baseline"],
204238
["pre-commit", "run", "-a"],
205239
["bash", "{tox_root}/tools/generate-templates.sh"],
206240
["rm", "-rf", "test/roles"]

src/molecule_plugins/docker/driver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def sanity_checks(self):
242242
import docker # noqa: PLC0415
243243

244244
docker_client = docker.from_env()
245-
docker_client.ping()
245+
docker_client.ping() # type: ignore[no-untyped-call]
246246
except docker.errors.DockerException:
247247
msg = (
248248
"Unable to contact the Docker daemon. "
@@ -264,7 +264,7 @@ def reset(self):
264264
for c in client.containers.list(filters={"label": "owner=molecule"}):
265265
log.info("Stopping docker container %s ...", c.id)
266266
c.stop(timeout=3)
267-
result = client.containers.prune(filters={"label": "owner=molecule"})
267+
result = client.containers.prune(filters={"label": "owner=molecule"}) # type: ignore[no-untyped-call]
268268
for c in result.get("ContainersDeleted") or []:
269269
log.info("Deleted container %s", c)
270270
for n in client.networks.list(filters={"label": "owner=molecule"}):

src/molecule_plugins/ec2/driver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
HAS_CRYPTOGRAPHY = False
3333

3434
try:
35-
import boto3
35+
import boto3 # type: ignore[import-untyped]
3636

3737
HAS_BOTO3 = True
3838
except ImportError:

src/molecule_plugins/gce/playbooks/files/windows_auth.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@
2525
# https://developers.google.com/api-client-library/python/start/get_started
2626
import google.auth
2727

28-
# PyCrypto library: https://pypi.python.org/pypi/pycrypto
28+
# https://pypi.org/project/pycryptodome/
2929
from Crypto.Cipher import PKCS1_OAEP
3030
from Crypto.PublicKey import RSA
3131
from Crypto.Util.number import long_to_bytes
32-
from googleapiclient.discovery import build
32+
from googleapiclient.discovery import build # type: ignore[import-not-found]
3333

3434

3535
def GetCompute():
3636
"""Get a compute object for communicating with the Compute Engine API."""
37-
credentials, project = google.auth.default()
37+
credentials, project = google.auth.default() # type: ignore[no-untyped-call]
3838
compute = build("compute", "v1", credentials=credentials)
3939
return compute
4040

src/molecule_plugins/vagrant/modules/vagrant.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from collections.abc import MutableMapping
3131

3232
import jinja2
33-
from ansible.module_utils.basic import AnsibleModule
33+
from ansible.module_utils.basic import AnsibleModule # type: ignore[import-untyped]
3434

3535
try:
3636
import vagrant
File renamed without changes.

test/gce/scenarios/linux/files/windows_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import json
2222
import time
2323

24-
# PyCrypto library: https://pypi.python.org/pypi/pycrypto
24+
# https://pypi.org/project/pycryptodome/
2525
from Crypto.Cipher import PKCS1_OAEP
2626
from Crypto.PublicKey import RSA
2727
from Crypto.Util.number import long_to_bytes

test/gce/scenarios/windows/files/windows_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import json
2222
import time
2323

24-
# PyCrypto library: https://pypi.python.org/pypi/pycrypto
24+
# https://pypi.org/project/pycryptodome/
2525
from Crypto.Cipher import PKCS1_OAEP
2626
from Crypto.PublicKey import RSA
2727
from Crypto.Util.number import long_to_bytes

test/openstack/test_func.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import subprocess
77
from pathlib import Path
88

9+
import openstack
910
import pytest
1011

11-
import openstack
1212
from conftest import change_dir_to
1313
from molecule import logger
1414
from molecule.app import get_app

0 commit comments

Comments
 (0)