Skip to content

Commit

Permalink
Add pytype nox session
Browse files Browse the repository at this point in the history
  • Loading branch information
plamut committed Sep 17, 2021
1 parent 50202e0 commit e22f1d2
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pip-log.txt
.nox
.cache
.pytest_cache
.pytype


# Mac
Expand Down
11 changes: 11 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -41,13 +43,22 @@
"lint",
"lint_setup_py",
"blacken",
"pytype",
"docs",
]

# Error if a python version is missing
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.
Expand Down
56 changes: 56 additions & 0 deletions owlbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
14 changes: 14 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e22f1d2

Please sign in to comment.