summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2017-07-27 12:41:34 -0500
committerMonty Taylor <mordred@inaugust.com>2017-07-27 14:34:07 -0500
commitfb8f5a44bd3e828ce87f646ea82f4ce0dfe0c989 (patch)
treed39d97ab999e2837b29e65f8ea1f7621741055de
parente63dcc62a5a791fa5a50fffab93cf673131ead21 (diff)
downloadzuul-fb8f5a44bd3e828ce87f646ea82f4ce0dfe0c989.tar.gz
Use mypy to do static type checking
python3 includes support for optional type annotations which can be used by static analysis tools to perform type checking. The mypy tool is a static type checking tool that can also infer type information in many cases, but which will use explicit type information if it is present. Add mypy to test-requirements and to the pep8 job so that our pep8 job can do more analysis work and less with the code style. To support this, there were a few places in the current codebase that needed an explicit type hint. For variables/attributes in 3.5 this is done via comments. There is a conditional import that was confusion that just got marked with an 'ignore'. Our ansible action and lookup plugins confuse mypi with the way they import the ansible base classes. That's ok - they confuse us with that too. The .pyi files are 'typeshed' files, which are a way that one can provide static type annotations without putting the information into the file itself. mypy will always prefer a .pyi file over a .py file (since the point of them is to be external annotion/interface description) So in order to get mypy to not barf on the ansible import weirdness, just add a corresponding empty .pyi file. We could potentially actually put interface descriptions in them - but I don't think there is very much value in that. It should be amusing to at least someone that we have to flake8: noqa an import from typing that was done to provide a type hint in a comment. Change-Id: I6c4ac3dcfc6fd990e6c6886749de147ad28389d1
-rw-r--r--test-requirements.txt1
-rw-r--r--tox.ini8
-rw-r--r--zuul/ansible/action/add_host.pyi0
-rw-r--r--zuul/ansible/action/asa_config.pyi0
-rw-r--r--zuul/ansible/action/asa_template.pyi0
-rw-r--r--zuul/ansible/action/assemble.pyi0
-rw-r--r--zuul/ansible/action/copy.pyi0
-rw-r--r--zuul/ansible/action/dellos10_config.pyi0
-rw-r--r--zuul/ansible/action/dellos6_config.pyi0
-rw-r--r--zuul/ansible/action/dellos9_config.pyi0
-rw-r--r--zuul/ansible/action/eos_config.pyi0
-rw-r--r--zuul/ansible/action/eos_template.pyi0
-rw-r--r--zuul/ansible/action/fetch.pyi0
-rw-r--r--zuul/ansible/action/include_vars.pyi0
-rw-r--r--zuul/ansible/action/ios_config.pyi0
-rw-r--r--zuul/ansible/action/ios_template.pyi0
-rw-r--r--zuul/ansible/action/iosxr_config.pyi0
-rw-r--r--zuul/ansible/action/iosxr_template.pyi0
-rw-r--r--zuul/ansible/action/junos_config.pyi0
-rw-r--r--zuul/ansible/action/junos_template.pyi0
-rw-r--r--zuul/ansible/action/net_config.pyi0
-rw-r--r--zuul/ansible/action/net_template.pyi0
-rw-r--r--zuul/ansible/action/network.pyi0
-rw-r--r--zuul/ansible/action/normal.pyi0
-rw-r--r--zuul/ansible/action/nxos_config.pyi0
-rw-r--r--zuul/ansible/action/nxos_template.pyi0
-rw-r--r--zuul/ansible/action/ops_config.pyi0
-rw-r--r--zuul/ansible/action/ops_template.pyi0
-rw-r--r--zuul/ansible/action/patch.pyi0
-rw-r--r--zuul/ansible/action/script.pyi0
-rw-r--r--zuul/ansible/action/sros_config.pyi0
-rw-r--r--zuul/ansible/action/synchronize.pyi0
-rw-r--r--zuul/ansible/action/template.pyi0
-rw-r--r--zuul/ansible/action/unarchive.pyi0
-rw-r--r--zuul/ansible/action/vyos_config.pyi0
-rw-r--r--zuul/ansible/action/win_copy.pyi0
-rw-r--r--zuul/ansible/action/win_template.pyi0
-rw-r--r--zuul/ansible/lookup/_banned.pyi0
-rw-r--r--zuul/ansible/lookup/consul_kv.pyi0
-rw-r--r--zuul/ansible/lookup/credstash.pyi0
-rw-r--r--zuul/ansible/lookup/csvfile.pyi0
-rw-r--r--zuul/ansible/lookup/dig.pyi0
-rw-r--r--zuul/ansible/lookup/dnstxt.pyi0
-rw-r--r--zuul/ansible/lookup/env.pyi0
-rw-r--r--zuul/ansible/lookup/etcd.pyi0
-rw-r--r--zuul/ansible/lookup/file.pyi0
-rw-r--r--zuul/ansible/lookup/fileglob.pyi0
-rw-r--r--zuul/ansible/lookup/filetree.pyi0
-rw-r--r--zuul/ansible/lookup/first_found.pyi0
-rw-r--r--zuul/ansible/lookup/hashi_valut.pyi0
-rw-r--r--zuul/ansible/lookup/ini.pyi0
-rw-r--r--zuul/ansible/lookup/keyring.pyi0
-rw-r--r--zuul/ansible/lookup/lastpass.pyi0
-rw-r--r--zuul/ansible/lookup/lines.pyi0
-rw-r--r--zuul/ansible/lookup/mongodb.pyi0
-rw-r--r--zuul/ansible/lookup/password.pyi0
-rw-r--r--zuul/ansible/lookup/passwordstore.pyi0
-rw-r--r--zuul/ansible/lookup/pipe.pyi0
-rw-r--r--zuul/ansible/lookup/redis_kv.pyi0
-rw-r--r--zuul/ansible/lookup/shelvefile.pyi0
-rw-r--r--zuul/ansible/lookup/template.pyi0
-rw-r--r--zuul/ansible/lookup/url.pyi0
-rw-r--r--zuul/driver/__init__.py2
-rw-r--r--zuul/driver/bubblewrap/__init__.py4
-rw-r--r--zuul/lib/yamlutil.py3
65 files changed, 13 insertions, 5 deletions
diff --git a/test-requirements.txt b/test-requirements.txt
index eea1d691e..914dcf019 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -14,3 +14,4 @@ sphinxcontrib-programoutput
oslosphinx
mock
PyMySQL
+mypy
diff --git a/tox.ini b/tox.ini
index a3f018f97..cc5ea5851 100644
--- a/tox.ini
+++ b/tox.ini
@@ -27,8 +27,12 @@ deps = bindep
commands = bindep test
[testenv:pep8]
-# streamer is python3 only, so we need to run flake8 in python3
-commands = flake8 {posargs}
+# --ignore-missing-imports tells mypy to not try to follow imported modules
+# out of the current tree. As you might expect, we don't want to run static
+# type checking on the world - just on ourselves.
+commands =
+ flake8 {posargs}
+ mypy --ignore-missing-imports zuul
[testenv:cover]
commands =
diff --git a/zuul/ansible/action/add_host.pyi b/zuul/ansible/action/add_host.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/add_host.pyi
diff --git a/zuul/ansible/action/asa_config.pyi b/zuul/ansible/action/asa_config.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/asa_config.pyi
diff --git a/zuul/ansible/action/asa_template.pyi b/zuul/ansible/action/asa_template.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/asa_template.pyi
diff --git a/zuul/ansible/action/assemble.pyi b/zuul/ansible/action/assemble.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/assemble.pyi
diff --git a/zuul/ansible/action/copy.pyi b/zuul/ansible/action/copy.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/copy.pyi
diff --git a/zuul/ansible/action/dellos10_config.pyi b/zuul/ansible/action/dellos10_config.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/dellos10_config.pyi
diff --git a/zuul/ansible/action/dellos6_config.pyi b/zuul/ansible/action/dellos6_config.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/dellos6_config.pyi
diff --git a/zuul/ansible/action/dellos9_config.pyi b/zuul/ansible/action/dellos9_config.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/dellos9_config.pyi
diff --git a/zuul/ansible/action/eos_config.pyi b/zuul/ansible/action/eos_config.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/eos_config.pyi
diff --git a/zuul/ansible/action/eos_template.pyi b/zuul/ansible/action/eos_template.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/eos_template.pyi
diff --git a/zuul/ansible/action/fetch.pyi b/zuul/ansible/action/fetch.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/fetch.pyi
diff --git a/zuul/ansible/action/include_vars.pyi b/zuul/ansible/action/include_vars.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/include_vars.pyi
diff --git a/zuul/ansible/action/ios_config.pyi b/zuul/ansible/action/ios_config.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/ios_config.pyi
diff --git a/zuul/ansible/action/ios_template.pyi b/zuul/ansible/action/ios_template.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/ios_template.pyi
diff --git a/zuul/ansible/action/iosxr_config.pyi b/zuul/ansible/action/iosxr_config.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/iosxr_config.pyi
diff --git a/zuul/ansible/action/iosxr_template.pyi b/zuul/ansible/action/iosxr_template.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/iosxr_template.pyi
diff --git a/zuul/ansible/action/junos_config.pyi b/zuul/ansible/action/junos_config.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/junos_config.pyi
diff --git a/zuul/ansible/action/junos_template.pyi b/zuul/ansible/action/junos_template.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/junos_template.pyi
diff --git a/zuul/ansible/action/net_config.pyi b/zuul/ansible/action/net_config.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/net_config.pyi
diff --git a/zuul/ansible/action/net_template.pyi b/zuul/ansible/action/net_template.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/net_template.pyi
diff --git a/zuul/ansible/action/network.pyi b/zuul/ansible/action/network.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/network.pyi
diff --git a/zuul/ansible/action/normal.pyi b/zuul/ansible/action/normal.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/normal.pyi
diff --git a/zuul/ansible/action/nxos_config.pyi b/zuul/ansible/action/nxos_config.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/nxos_config.pyi
diff --git a/zuul/ansible/action/nxos_template.pyi b/zuul/ansible/action/nxos_template.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/nxos_template.pyi
diff --git a/zuul/ansible/action/ops_config.pyi b/zuul/ansible/action/ops_config.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/ops_config.pyi
diff --git a/zuul/ansible/action/ops_template.pyi b/zuul/ansible/action/ops_template.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/ops_template.pyi
diff --git a/zuul/ansible/action/patch.pyi b/zuul/ansible/action/patch.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/patch.pyi
diff --git a/zuul/ansible/action/script.pyi b/zuul/ansible/action/script.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/script.pyi
diff --git a/zuul/ansible/action/sros_config.pyi b/zuul/ansible/action/sros_config.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/sros_config.pyi
diff --git a/zuul/ansible/action/synchronize.pyi b/zuul/ansible/action/synchronize.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/synchronize.pyi
diff --git a/zuul/ansible/action/template.pyi b/zuul/ansible/action/template.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/template.pyi
diff --git a/zuul/ansible/action/unarchive.pyi b/zuul/ansible/action/unarchive.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/unarchive.pyi
diff --git a/zuul/ansible/action/vyos_config.pyi b/zuul/ansible/action/vyos_config.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/vyos_config.pyi
diff --git a/zuul/ansible/action/win_copy.pyi b/zuul/ansible/action/win_copy.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/win_copy.pyi
diff --git a/zuul/ansible/action/win_template.pyi b/zuul/ansible/action/win_template.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/action/win_template.pyi
diff --git a/zuul/ansible/lookup/_banned.pyi b/zuul/ansible/lookup/_banned.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/lookup/_banned.pyi
diff --git a/zuul/ansible/lookup/consul_kv.pyi b/zuul/ansible/lookup/consul_kv.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/lookup/consul_kv.pyi
diff --git a/zuul/ansible/lookup/credstash.pyi b/zuul/ansible/lookup/credstash.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/lookup/credstash.pyi
diff --git a/zuul/ansible/lookup/csvfile.pyi b/zuul/ansible/lookup/csvfile.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/lookup/csvfile.pyi
diff --git a/zuul/ansible/lookup/dig.pyi b/zuul/ansible/lookup/dig.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/lookup/dig.pyi
diff --git a/zuul/ansible/lookup/dnstxt.pyi b/zuul/ansible/lookup/dnstxt.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/lookup/dnstxt.pyi
diff --git a/zuul/ansible/lookup/env.pyi b/zuul/ansible/lookup/env.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/lookup/env.pyi
diff --git a/zuul/ansible/lookup/etcd.pyi b/zuul/ansible/lookup/etcd.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/lookup/etcd.pyi
diff --git a/zuul/ansible/lookup/file.pyi b/zuul/ansible/lookup/file.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/lookup/file.pyi
diff --git a/zuul/ansible/lookup/fileglob.pyi b/zuul/ansible/lookup/fileglob.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/lookup/fileglob.pyi
diff --git a/zuul/ansible/lookup/filetree.pyi b/zuul/ansible/lookup/filetree.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/lookup/filetree.pyi
diff --git a/zuul/ansible/lookup/first_found.pyi b/zuul/ansible/lookup/first_found.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/lookup/first_found.pyi
diff --git a/zuul/ansible/lookup/hashi_valut.pyi b/zuul/ansible/lookup/hashi_valut.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/lookup/hashi_valut.pyi
diff --git a/zuul/ansible/lookup/ini.pyi b/zuul/ansible/lookup/ini.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/lookup/ini.pyi
diff --git a/zuul/ansible/lookup/keyring.pyi b/zuul/ansible/lookup/keyring.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/lookup/keyring.pyi
diff --git a/zuul/ansible/lookup/lastpass.pyi b/zuul/ansible/lookup/lastpass.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/lookup/lastpass.pyi
diff --git a/zuul/ansible/lookup/lines.pyi b/zuul/ansible/lookup/lines.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/lookup/lines.pyi
diff --git a/zuul/ansible/lookup/mongodb.pyi b/zuul/ansible/lookup/mongodb.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/lookup/mongodb.pyi
diff --git a/zuul/ansible/lookup/password.pyi b/zuul/ansible/lookup/password.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/lookup/password.pyi
diff --git a/zuul/ansible/lookup/passwordstore.pyi b/zuul/ansible/lookup/passwordstore.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/lookup/passwordstore.pyi
diff --git a/zuul/ansible/lookup/pipe.pyi b/zuul/ansible/lookup/pipe.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/lookup/pipe.pyi
diff --git a/zuul/ansible/lookup/redis_kv.pyi b/zuul/ansible/lookup/redis_kv.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/lookup/redis_kv.pyi
diff --git a/zuul/ansible/lookup/shelvefile.pyi b/zuul/ansible/lookup/shelvefile.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/lookup/shelvefile.pyi
diff --git a/zuul/ansible/lookup/template.pyi b/zuul/ansible/lookup/template.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/lookup/template.pyi
diff --git a/zuul/ansible/lookup/url.pyi b/zuul/ansible/lookup/url.pyi
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/zuul/ansible/lookup/url.pyi
diff --git a/zuul/driver/__init__.py b/zuul/driver/__init__.py
index c78283d21..5193fe609 100644
--- a/zuul/driver/__init__.py
+++ b/zuul/driver/__init__.py
@@ -33,7 +33,7 @@ class Driver(object, metaclass=abc.ABCMeta):
The class or instance attribute **name** must be provided as a string.
"""
- name = None
+ name = None # type: str
def reconfigure(self, tenant):
"""Called when a tenant is reconfigured.
diff --git a/zuul/driver/bubblewrap/__init__.py b/zuul/driver/bubblewrap/__init__.py
index 3609a7172..83cac2e4f 100644
--- a/zuul/driver/bubblewrap/__init__.py
+++ b/zuul/driver/bubblewrap/__init__.py
@@ -23,6 +23,8 @@ import shlex
import subprocess
import sys
+from typing import Dict, List # flake8: noqa
+
from zuul.driver import (Driver, WrapperInterface)
@@ -70,7 +72,7 @@ class BubblewrapDriver(Driver, WrapperInterface):
name = 'bubblewrap'
log = logging.getLogger("zuul.BubblewrapDriver")
- mounts_map = {'rw': [], 'ro': []}
+ mounts_map = {'rw': [], 'ro': []} # type: Dict[str, List]
def __init__(self):
self.bwrap_command = self._bwrap_command()
diff --git a/zuul/lib/yamlutil.py b/zuul/lib/yamlutil.py
index 2419906cd..2c84b06ae 100644
--- a/zuul/lib/yamlutil.py
+++ b/zuul/lib/yamlutil.py
@@ -13,7 +13,8 @@ import yaml
from yaml import YAMLObject, YAMLError # noqa: F401
try:
- from yaml import cyaml
+ # Explicit type ignore to deal with provisional import failure
+ from yaml import cyaml # type: ignore
import _yaml
SafeLoader = cyaml.CSafeLoader
SafeDumper = cyaml.CSafeDumper