diff --git a/.gitignore b/.gitignore index 3c64ffabe0be..8b87e4d85825 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ *~ .autogenerated .coverage +.mypy_cache .nova-venv .project .pydevproject diff --git a/lower-constraints.txt b/lower-constraints.txt index 45fb9b9d5cf0..d1134653b1d7 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -57,6 +57,7 @@ monotonic==1.4 msgpack==0.5.6 msgpack-python==0.5.6 munch==2.2.0 +mypy==0.761 netaddr==0.7.18 netifaces==0.10.4 networkx==1.11 diff --git a/mypy-files.txt b/mypy-files.txt new file mode 100644 index 000000000000..4ee414816ed4 --- /dev/null +++ b/mypy-files.txt @@ -0,0 +1 @@ +nova/virt/libvirt/__init__.py diff --git a/setup.cfg b/setup.cfg index c89f1999a490..6356fc74c26c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -84,3 +84,12 @@ console_scripts = wsgi_scripts = nova-api-wsgi = nova.api.openstack.compute.wsgi:init_application nova-metadata-wsgi = nova.api.metadata.wsgi:init_application + +[mypy] +show_column_numbers = true +show_error_context = true +ignore_missing_imports = true +follow_imports = skip +incremental = true +check_untyped_defs = true +warn_unused_ignores = true diff --git a/test-requirements.txt b/test-requirements.txt index 25ac29b7ef00..d42fb05f18b7 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -3,6 +3,7 @@ # process, which may cause wedges in the gate later. hacking>=3.0.1,<3.1.0 # Apache-2.0 +mypy>=0.761 # MIT coverage!=4.4,>=4.0 # Apache-2.0 ddt>=1.0.1 # MIT fixtures>=3.0.0 # Apache-2.0/BSD diff --git a/tools/mypywrap.sh b/tools/mypywrap.sh new file mode 100644 index 000000000000..dd5868d6e248 --- /dev/null +++ b/tools/mypywrap.sh @@ -0,0 +1,22 @@ +#!/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 214a8c75f52f..5402c7edabe8 100644 --- a/tox.ini +++ b/tox.ini @@ -38,11 +38,19 @@ commands = env TEST_OSPROFILER=1 stestr run --combine --no-discover 'nova.tests.unit.test_profiler' stestr slowest +[testenv:mypy] +description = + Run type checks. +envdir = {toxworkdir}/shared +commands = + bash tools/mypywrap.sh {posargs} + [testenv:pep8] description = Run style checks. envdir = {toxworkdir}/shared commands = + {[testenv:mypy]commands} bash tools/flake8wrap.sh {posargs} # Check that all JSON files don't have \r\n in line. bash -c "! find doc/ -type f -name *.json | xargs grep -U -n $'\r'"