From e3e35ba2d078e0e779895c10000bc75df09f46ee Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Fri, 22 Sep 2023 11:44:48 +0100 Subject: [PATCH] pre-commit: Add mypy Add mypy so we can run these checks as part of our linting step. Note that mypy is the last item in the list of checks since flake8 is going to catch e.g. syntax issues which should be addressed first. This also allows us to drop use of mypywrap: rather than wrapping mypy, we can make use of mypy's configuration to specify the files we wish to run checks on. Change-Id: Ie51401ead4e31ccd70ab833c59cb397f802ff188 Signed-off-by: Stephen Finucane --- .pre-commit-config.yaml | 36 +++++++++++++++++++++++++++++++++++- mypy-files.txt | 24 ------------------------ setup.cfg | 27 ++++++++++++++++++++++++++- test-requirements.txt | 2 -- tools/mypywrap.sh | 22 ---------------------- tox.ini | 17 +++++++++-------- 6 files changed, 70 insertions(+), 58 deletions(-) delete mode 100644 mypy-files.txt delete mode 100644 tools/mypywrap.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 34547655a5..a9109e4543 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -40,4 +40,38 @@ repos: rev: v2.2.4 hooks: - id: codespell - args: ['--ignore-words=doc/dictionary.txt'] \ No newline at end of file + args: ['--ignore-words=doc/dictionary.txt'] + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.4.1 + hooks: + - id: mypy + additional_dependencies: + - types-paramiko + # keep this in-sync with '[mypy] files' in 'setup.cfg' + files: | + (?x)( + nova/compute/manager.py + | nova/compute/pci_placement_translator.py + | nova/crypto.py + | nova/filesystem.py + | nova/limit/local.py + | nova/limit/placement.py + | nova/network/neutron.py + | nova/pci + | nova/privsep/path.py + | nova/scheduler/client/report.py + | nova/scheduler/request_filter.py + | nova/scheduler/utils.py + | nova/virt/driver.py + | nova/virt/hardware.py + | nova/virt/libvirt/machine_type_utils.py + | nova/virt/libvirt/__init__.py + | nova/virt/libvirt/cpu/__init__.py + | nova/virt/libvirt/cpu/api.py + | nova/virt/libvirt/cpu/core.py + | nova/virt/libvirt/driver.py + | nova/virt/libvirt/event.py + | nova/virt/libvirt/guest.py + | nova/virt/libvirt/host.py + | nova/virt/libvirt/utils.py + ) diff --git a/mypy-files.txt b/mypy-files.txt deleted file mode 100644 index 391ed58d87..0000000000 --- a/mypy-files.txt +++ /dev/null @@ -1,24 +0,0 @@ -nova/compute/manager.py -nova/compute/pci_placement_translator.py -nova/crypto.py -nova/filesystem.py -nova/limit/local.py -nova/limit/placement.py -nova/network/neutron.py -nova/pci -nova/privsep/path.py -nova/scheduler/client/report.py -nova/scheduler/request_filter.py -nova/scheduler/utils.py -nova/virt/driver.py -nova/virt/hardware.py -nova/virt/libvirt/machine_type_utils.py -nova/virt/libvirt/__init__.py -nova/virt/libvirt/cpu/__init__.py -nova/virt/libvirt/cpu/api.py -nova/virt/libvirt/cpu/core.py -nova/virt/libvirt/driver.py -nova/virt/libvirt/event.py -nova/virt/libvirt/guest.py -nova/virt/libvirt/host.py -nova/virt/libvirt/utils.py diff --git a/setup.cfg b/setup.cfg index 5dd37efc61..eceb6c4ab5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -101,8 +101,33 @@ follow_imports = skip incremental = true check_untyped_defs = true warn_unused_ignores = true +files = + nova/compute/manager.py, + nova/compute/pci_placement_translator.py, + nova/crypto.py, + nova/filesystem.py, + nova/limit/local.py, + nova/limit/placement.py, + nova/network/neutron.py, + nova/pci/*.py, + nova/privsep/path.py, + nova/scheduler/client/report.py, + nova/scheduler/request_filter.py, + nova/scheduler/utils.py, + nova/virt/driver.py, + nova/virt/hardware.py, + nova/virt/libvirt/machine_type_utils.py, + nova/virt/libvirt/__init__.py, + nova/virt/libvirt/cpu/__init__.py, + nova/virt/libvirt/cpu/api.py, + nova/virt/libvirt/cpu/core.py, + nova/virt/libvirt/driver.py, + nova/virt/libvirt/event.py, + nova/virt/libvirt/guest.py, + nova/virt/libvirt/host.py, + nova/virt/libvirt/utils.py [codespell] skip = *.po,*.js,*.css,*.html,*.svg,HACKING.py,*hacking*,*build*,*_static*,doc/dictionary.txt,*.pyc,*.inv,*.gz,*.jpg,*.png,*.vsd,*.graffle,*.json count = -quiet-level = 4 \ No newline at end of file +quiet-level = 4 diff --git a/test-requirements.txt b/test-requirements.txt index 8bada67d3f..04dcc056ee 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,6 +1,4 @@ hacking==6.1.0 # Apache-2.0 -mypy>=0.761 # MIT -types-paramiko>=0.1.3 # Apache-2.0 coverage!=4.4,>=4.0 # Apache-2.0 ddt>=1.2.1 # MIT fixtures>=3.0.0 # Apache-2.0/BSD diff --git a/tools/mypywrap.sh b/tools/mypywrap.sh deleted file mode 100644 index dd5868d6e2..0000000000 --- a/tools/mypywrap.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh -# -# A wrapper around mypy that allows us to specify what files to run 'mypy' type -# checks on. Intended to be invoked via tox: -# -# tox -e mypy -# -# Eventually this should go away once we have either converted everything or -# converted enough and ignored [1] the rest. -# -# [1] http://mypy.readthedocs.io/en/latest/config_file.html#per-module-flags - -ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -if [ $# -eq 0 ]; then - # if no arguments provided, use the standard converted lists - lines=$(grep -v '#' $ROOT_DIR/../mypy-files.txt) - python -m mypy ${lines[@]} -else - # else test what the user asked us to - python -m mypy $@ -fi diff --git a/tox.ini b/tox.ini index c96276de2d..852f12c141 100644 --- a/tox.ini +++ b/tox.ini @@ -99,14 +99,6 @@ extras = commands = stestr --test-path=./nova/tests/functional run --exclude-regex '((?:api|notification)_sample_tests|functional\.db\.)' {posargs} -[testenv:mypy] -description = - Run type checks. -envdir = {toxworkdir}/shared -extras = -commands = - bash tools/mypywrap.sh {posargs} - [testenv:pep8] description = Run style checks. @@ -116,6 +108,15 @@ extras = commands = pre-commit run --all-files --show-diff-on-failure +[testenv:mypy] +description = + Run type checks. +deps = + pre-commit +extras = +commands = + pre-commit run --all-files --show-diff-on-failure mypy + [testenv:autopep8] extras = deps =