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 update versions of other pre-commit hooks and
simplify the mypy configuration, aligning it with that of other typed
oslo projects.

Change-Id: I91320224dec622b9a39878d84f55b1a55fc23cc9
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane
2025-12-01 13:18:59 +00:00
parent f2d9a6fd21
commit 2b7e33c416
3 changed files with 28 additions and 54 deletions

View File

@@ -13,24 +13,14 @@ repos:
- id: check-yaml
files: .*\.(yaml|yml)$
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.13.0
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: []
exclude: '^(doc|releasenotes)/.*$'
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.17.1
hooks:
- id: mypy
exclude: |
(?x)(
oslo_context/fixture.py
| doc/.*
| releasenotes/.*
)

View File

@@ -37,6 +37,20 @@ packages = [
"oslo_context"
]
[tool.mypy]
python_version = "3.10"
show_column_numbers = true
show_error_context = true
strict = true
ignore_missing_imports = true
exclude = '(?x)(doc | releasenotes)'
[[tool.mypy.overrides]]
module = ["oslo_context.tests.*"]
disallow_untyped_calls = false
disallow_untyped_defs = false
disallow_subclassing_any = false
[tool.ruff]
line-length = 79
@@ -49,43 +63,3 @@ select = ["E4", "E7", "E9", "F", "S", "UP"]
[tool.ruff.lint.per-file-ignores]
"oslo_context/tests/*" = ["S"]
[tool.mypy]
python_version = "3.10"
show_column_numbers = true
show_error_context = true
ignore_missing_imports = true
follow_imports = "normal"
check_untyped_defs = true
warn_unused_ignores = false
warn_return_any = true
warn_unused_configs = true
warn_redundant_casts = true
strict_equality = true
disallow_untyped_decorators = true
disallow_any_generics = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_incomplete_defs = true
disallow_untyped_defs = true
no_implicit_reexport = true
extra_checks = true
# keep this in-sync with 'mypy.exclude' in '.pre-commit-config.yaml'
exclude = '''
(?x)(
doc
| releasenotes
)
'''
[[tool.mypy.overrides]]
module = [
"oslo_context.fixture",
"oslo_context.tests.*",
]
warn_return_any = false
disallow_untyped_decorators = false
disallow_any_generics = false
disallow_subclassing_any = false
disallow_untyped_calls = false
disallow_untyped_defs = false

14
tox.ini
View File

@@ -9,13 +9,23 @@ deps =
commands = stestr run --slowest {posargs}
[testenv:pep8]
skip_install = true
description =
Run linters.
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
commands =
mypy --cache-dir="{envdir}/mypy_cache" {posargs:oslo_context}
[testenv:venv]
commands = {posargs}