From c8c4fc953c4a563ed2295efaf82c75b52de06a2c Mon Sep 17 00:00:00 2001 From: Brian Rosmaita Date: Fri, 9 Jul 2021 15:43:18 -0400 Subject: [PATCH] Add installation of mypy stubs packages The cinder-mypy job is failing because library stubs aren't installed for requests [0]. Modify the mypywrap.sh to accept options specified in an environment variable named OS_MYPY_OPTS to the mypy invocation, and set this var in tox.ini. The value is "--install-types --non-interactive" which is suitable for CI purposes, and seems to make sense for local tox use as well [1]. The downside is it basically runs mypy twice, once to determine whether there are any library stubs missing and then install them, and againto do the actual check. If we don't want this setting in tox.ini, we can move it to .zuul.yaml for the cinder-mypy job run. Also, update the version of mypy in test-requirements to a version that supports the above options. And, run mypy in its own env (instead of reusing pep8) so that the tox logs are preserved during CI runs. [0] https://zuul.opendev.org/t/openstack/build/b66ee6c21e594940941585b0e9e5082a [1] https://mypy.readthedocs.io/en/stable/running_mypy.html#library-stubs-not-installed Change-Id: Id69cb519ee7300b33ff087de4e7d46cdad67d162 --- test-requirements.txt | 2 +- tools/mypywrap.sh | 4 ++-- tox.ini | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/test-requirements.txt b/test-requirements.txt index 591debf04bc..731e4e59ce4 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -21,5 +21,5 @@ testtools>=2.4.0 # MIT # so we need to pin it here to a known working version bandit==1.6.0 # Apache-2.0 doc8>=0.8.1 # Apache-2.0 -mypy>=0.782 # MIT +mypy>=0.910 # MIT moto>=1.3.15 # Apache-2.0 diff --git a/tools/mypywrap.sh b/tools/mypywrap.sh index b1ada5f838c..433312152e6 100755 --- a/tools/mypywrap.sh +++ b/tools/mypywrap.sh @@ -17,8 +17,8 @@ export MYPYPATH=$ROOT_DIR/../cinder/tests/stubs/ 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[@]} + python -m mypy $OS_MYPY_OPTS ${lines[@]} else # else test what the user asked us to - python -m mypy $@ + python -m mypy $OS_MYPY_OPTS $@ fi diff --git a/tox.ini b/tox.ini index e3e54544feb..d5733e5aef2 100644 --- a/tox.ini +++ b/tox.ini @@ -169,7 +169,8 @@ usedevelop = False [testenv:mypy] description = Run type checks. -envdir = {toxworkdir}/pep8 +setenv = + OS_MYPY_OPTS=--install-types --non-interactive commands = {toxinidir}/tools/mypywrap.sh {posargs}