From 7f3b2aba3118c379355518a0560ca9155409fd4e Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Fri, 6 Mar 2026 16:47:59 +0000 Subject: [PATCH] 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. It also removes the slowest pre-commit hook (by some distance), making pre-commit faster. While here, we also enable some more rules for ruff and configure hacking as an external linter. Change-Id: I47e34c34003273146e4afbef74385ca91fb28823 Signed-off-by: Stephen Finucane --- .pre-commit-config.yaml | 20 +------------------- pyproject.toml | 12 ++++-------- tox.ini | 19 +++++++++++++++---- 3 files changed, 20 insertions(+), 31 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1c05a65..8a50b48 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,26 +13,8 @@ repos: - id: check-yaml files: .*\.(yaml|yml)$ - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.14.5 + rev: v0.15.5 hooks: - id: ruff-check args: ['--fix', '--unsafe-fixes'] - id: ruff-format - - repo: https://opendev.org/openstack/hacking - rev: 8.0.0 - hooks: - - id: hacking - additional_dependencies: [] - exclude: '^(doc|releasenotes|tools)/.*$' - - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.18.2 - hooks: - - id: mypy - additional_dependencies: - - types-WebOb - # keep this in-sync with '[mypy] exclude' in 'pyproject.toml' - exclude: | - (?x)( - doc/.* - | releasenotes/.* - ) diff --git a/pyproject.toml b/pyproject.toml index fb83c3f..856ca46 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,13 +40,8 @@ python_version = "3.10" show_column_numbers = true show_error_context = true strict = true -# keep this in-sync with 'mypy.exclude' in '.pre-commit-config.yaml' -exclude = ''' -(?x)( - doc - | releasenotes - ) -''' +disable_error_code = ["import-untyped"] +exclude = "(?x)(doc | releasenotes)" [[tool.mypy.overrides]] module = ["microversion_parse.tests.*"] @@ -62,7 +57,8 @@ quote-style = "single" docstring-code-format = true [tool.ruff.lint] -select = ["E4", "E5", "E7", "E9", "F", "S", "UP"] +select = ["E4", "E5", "E7", "E9", "F", "G", "LOG", "S", "UP"] +external = ["H"] ignore = [ # we only use asserts for type narrowing "S101", diff --git a/tox.ini b/tox.ini index a45f33a..ebdb708 100644 --- a/tox.ini +++ b/tox.ini @@ -17,12 +17,23 @@ commands = {posargs} [testenv:pep8] description = - Run style checks. -skip_install = true + Run style checks. deps = - pre-commit + pre-commit + {[testenv:mypy]deps} commands = - pre-commit run --all-files --show-diff-on-failure + pre-commit run -a + {[testenv:mypy]commands} + +[testenv:mypy] +description = + Run type checks. +deps = + {[testenv]deps} + mypy + types-WebOb +commands = + mypy --cache-dir="{envdir}/mypy_cache" {posargs:microversion_parse} [testenv:cover] description =