diff --git a/.gitignore b/.gitignore index b4243ced7..99c3a1444 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,7 @@ pip-log.txt .nox .cache .pytest_cache +.pytype # Mac diff --git a/noxfile.py b/noxfile.py index 23c89a0ea..c1f6fdf1c 100644 --- a/noxfile.py +++ b/noxfile.py @@ -27,6 +27,8 @@ BLACK_VERSION = "black==19.10b0" BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] +PYTYPE_VERSION = "pytype==2021.4.9" + DEFAULT_PYTHON_VERSION = "3.8" SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"] UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] @@ -41,6 +43,7 @@ "lint", "lint_setup_py", "blacken", + "pytype", "docs", ] @@ -48,6 +51,14 @@ nox.options.error_on_missing_interpreters = True +@nox.session(python=DEFAULT_PYTHON_VERSION) +def pytype(session): + """Run type checks.""" + session.install("-e", ".[all]") + session.install(PYTYPE_VERSION) + session.run("pytype") + + @nox.session(python=DEFAULT_PYTHON_VERSION) def lint(session): """Run linters. diff --git a/owlbot.py b/owlbot.py index 244643883..3cd62ed0f 100644 --- a/owlbot.py +++ b/owlbot.py @@ -351,4 +351,60 @@ # ---------------------------------------------------------------------------- python.py_samples() +# ---------------------------------------------------------------------------- +# pytype-related changes +# ---------------------------------------------------------------------------- + +# Add .pytype to .gitignore +s.replace(".gitignore", r"\.pytest_cache", "\g<0>\n.pytype") + +# Add pytype config to setup.cfg +s.replace( + "setup.cfg", + r"universal = 1", + textwrap.dedent( + """ \g<0> + + [pytype] + python_version = 3.8 + inputs = + google/cloud/ + exclude = + tests/ + google/pubsub_v1/ # generated code + output = .pytype/ + disable = + # There's some issue with finding some pyi files, thus disabling. + # The issue https://github.com/google/pytype/issues/150 is closed, but the + # error still occurs for some reason. + pyi-error""" + ), +) + +# Add pytype session to noxfile.py +s.replace( + "noxfile.py", + r"BLACK_PATHS = \[.*?\]", + '\g<0>\n\nPYTYPE_VERSION = "pytype==2021.4.9"\n', +) +s.replace( + "noxfile.py", r'"blacken",', '\g<0>\n "pytype",', +) +s.replace( + "noxfile.py", + r"nox\.options\.error_on_missing_interpreters = True", + textwrap.dedent( + ''' \g<0> + + + @nox.session(python=DEFAULT_PYTHON_VERSION) + def pytype(session): + """Run type checks.""" + session.install("-e", ".[all]") + session.install(PYTYPE_VERSION) + session.run("pytype")''' + ), +) + + s.shell.run(["nox", "-s", "blacken"], hide_output=False) diff --git a/setup.cfg b/setup.cfg index c3a2b39f6..a79cb6a60 100644 --- a/setup.cfg +++ b/setup.cfg @@ -17,3 +17,17 @@ # Generated by synthtool. DO NOT EDIT! [bdist_wheel] universal = 1 + +[pytype] +python_version = 3.8 +inputs = + google/cloud/ +exclude = + tests/ + google/pubsub_v1/ # generated code +output = .pytype/ +disable = + # There's some issue with finding some pyi files, thus disabling. + # The issue https://github.com/google/pytype/issues/150 is closed, but the + # error still occurs for some reason. + pyi-error