Run mypy from tox

This avoids the need to duplicate our dependency list in multiple
places and allows us to take advantage of tox's dependency management
infrastructure, to ensure we always get the latest and greatest version
of a package allowed by upper-constraints.

While here, we also bump the other pre-commit hooks and update hints to
accommodate typed fixtures.

Change-Id: I4020374b45c8ead4b3b65651389c1e903a1de7bd
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
Stephen Finucane
2025-12-01 13:46:27 +00:00
parent 0127b20b22
commit 67bfcbdd0b
15 changed files with 38 additions and 54 deletions

View File

@@ -1,49 +1,25 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
rev: v6.0.0
hooks:
- id: trailing-whitespace
# Replaces or checks mixed line ending
- id: mixed-line-ending
args: ['--fix', 'lf']
exclude: '.*\.(svg)$'
# Forbid files which have a UTF-8 byte-order marker
- id: check-byte-order-marker
# Checks that non-binary executables have a proper shebang
- id: fix-byte-order-marker
- id: check-executables-have-shebangs
# Check for files that contain merge conflict strings.
- id: check-merge-conflict
# Check for debugger imports and py37+ breakpoint()
# calls in python source
- id: debug-statements
- id: check-yaml
files: .*\.(yaml|yml)$
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.7
rev: v0.14.8
hooks:
- id: ruff-check
args: ['--fix', '--unsafe-fixes']
- id: ruff-format
- repo: https://opendev.org/openstack/hacking
rev: 7.0.0
rev: 8.0.0
hooks:
- id: hacking
additional_dependencies: []
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.17.1
hooks:
- id: mypy
additional_dependencies:
- fixtures
- iso8601
- packaging
- pyparsing
- types-PyYAML
- types-greenlet
- types-netaddr
- types-psutil
exclude: |
(?x)(
doc/.*
| releasenotes/.*
)

View File

@@ -16,7 +16,7 @@
import sys
from typing import Any
import debtcollector.removals
import debtcollector.removals # type: ignore
def safe_decode(

View File

@@ -25,7 +25,7 @@ import threading
from typing import TYPE_CHECKING
import warnings
import debtcollector
import debtcollector # type: ignore
from oslo_utils import importutils
from oslo_utils import timeutils

View File

@@ -29,7 +29,7 @@ import json
import re
from typing import Any
import debtcollector
import debtcollector # type: ignore
from oslo_utils._i18n import _
from oslo_utils import strutils

View File

@@ -25,7 +25,7 @@ import secrets
import string as _string
from typing import Any, cast
import debtcollector.removals
import debtcollector.removals # type: ignore
@debtcollector.removals.remove(

View File

@@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslotest import base
from oslotest import base # type: ignore
class BaseTestCase(base.BaseTestCase): ...

View File

@@ -20,7 +20,7 @@ import subprocess
import tempfile
from unittest import mock
import ddt
import ddt # type: ignore
from oslo_utils.imageutils import format_inspector
from oslo_utils.imageutils import QemuImgInfo
@@ -1161,7 +1161,7 @@ class TestFormatInspectorInfra(test_base.BaseTestCase):
# Test with an expected format, but not the one we're going to
# intentionally fail to make sure that we do not log failures
# for non-expected formats.
self.test_wrapper_iter_like_eats_error(expected='vhd') # type: ignore
self.test_wrapper_iter_like_eats_error(expected='vhd')
def test_wrapper_aborts_early(self):
# Run the InspectWrapper with non-qcow2 data, expecting qcow2, first

View File

@@ -16,7 +16,7 @@
from unittest import mock
import warnings
import testscenarios
import testscenarios # type: ignore
from oslo_utils import imageutils
from oslo_utils.tests import base as test_base

View File

@@ -16,7 +16,7 @@ import threading
from unittest import mock
import warnings
import eventlet
import eventlet # type: ignore
from eventlet import greenthread
from oslo_utils import eventletutils

View File

@@ -15,7 +15,7 @@
import hashlib
import hmac
import testscenarios
import testscenarios # type: ignore
from oslo_utils import secretutils
from oslo_utils.tests import base as test_base

View File

@@ -19,8 +19,8 @@ import math
from typing import Any
from unittest import mock
import ddt
import testscenarios
import ddt # type: ignore
import testscenarios # type: ignore
from oslo_utils import strutils
from oslo_utils.tests import base as test_base

View File

@@ -19,7 +19,7 @@ import time
from unittest import mock
import iso8601
from testtools import matchers
from testtools import matchers # type: ignore
from oslo_utils.tests import base as test_base
from oslo_utils import timeutils

View File

@@ -12,7 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import pbr.version
import pbr.version # type: ignore
version_info = pbr.version.VersionInfo('oslo.utils')

View File

@@ -42,21 +42,14 @@ show_error_context = true
strict = true
# debtcollector is untyped (for now)
disallow_untyped_decorators = false
exclude = '''
(?x)(
doc
| releasenotes
)
'''
exclude = '(?x)(doc | releasenotes)'
[[tool.mypy.overrides]]
module = [
"oslo_utils.fixture",
"oslo_utils.tests.*",
]
module = ["oslo_utils.tests.*"]
disallow_untyped_calls = false
disallow_untyped_defs = false
disallow_subclassing_any = false
ignore_missing_imports = true
[tool.ruff]
line-length = 79

18
tox.ini
View File

@@ -10,11 +10,27 @@ deps =
commands = stestr run --slowest {posargs}
[testenv:pep8]
skip_install = true
description =
Run style checks.
deps =
pre-commit
{[testenv:mypy]deps}
commands =
pre-commit run -a
{[testenv:mypy]commands}
[testenv:mypy]
description =
Run type checks.
deps =
{[testenv]deps}
mypy
types-greenlet
types-netaddr
types-psutil
types-PyYAML
commands =
mypy --cache-dir="{envdir}/mypy_cache" {posargs:oslo_utils}
[testenv:venv]
commands = {posargs}