blob: 3b4863c2ded28d13f270671ff72ea3b0d420b550 [file] [log] [blame]
Bu Sun Kim65e33c02019-10-25 10:45:00 -07001# Copyright 2019 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Bu Sun Kimb1a12d22021-02-26 11:50:02 -070015import shutil
16import os
Bu Sun Kim65e33c02019-10-25 10:45:00 -070017import nox
18
19TEST_DEPENDENCIES = [
20 "flask",
Peter Lamutd86d7b82019-12-12 01:33:45 +010021 "freezegun",
Bu Sun Kim65e33c02019-10-25 10:45:00 -070022 "mock",
23 "oauth2client",
arithmetic1728bb9215a2020-03-20 09:49:44 -070024 "pyopenssl",
Bu Sun Kim65e33c02019-10-25 10:45:00 -070025 "pytest",
26 "pytest-cov",
27 "pytest-localserver",
28 "requests",
29 "urllib3",
30 "cryptography",
Brent Shafferbc0ec932020-02-13 14:11:34 -080031 "responses",
Bu Sun Kim65e33c02019-10-25 10:45:00 -070032 "grpcio",
33]
Christopher Wilcox7e152582020-09-28 15:27:20 -070034
Bu Sun Kimd7c63002021-03-08 14:17:54 -070035ASYNC_DEPENDENCIES = [
36 "pytest-asyncio",
37 "aioresponses",
38 "asynctest",
39 "aiohttp!=3.7.4.post0",
40]
Christopher Wilcox7e152582020-09-28 15:27:20 -070041
Bu Sun Kim65e33c02019-10-25 10:45:00 -070042BLACK_VERSION = "black==19.3b0"
Christopher Wilcox7e152582020-09-28 15:27:20 -070043BLACK_PATHS = [
44 "google",
45 "tests",
46 "tests_async",
47 "noxfile.py",
48 "setup.py",
49 "docs/conf.py",
50]
Bu Sun Kim65e33c02019-10-25 10:45:00 -070051
52
53@nox.session(python="3.7")
54def lint(session):
55 session.install("flake8", "flake8-import-order", "docutils", BLACK_VERSION)
56 session.install(".")
57 session.run("black", "--check", *BLACK_PATHS)
58 session.run(
59 "flake8",
60 "--import-order-style=google",
61 "--application-import-names=google,tests,system_tests",
62 "google",
63 "tests",
Christopher Wilcox7e152582020-09-28 15:27:20 -070064 "tests_async",
Bu Sun Kim65e33c02019-10-25 10:45:00 -070065 )
66 session.run(
67 "python", "setup.py", "check", "--metadata", "--restructuredtext", "--strict"
68 )
69
70
71@nox.session(python="3.6")
72def blacken(session):
73 """Run black.
Bu Sun Kim65e33c02019-10-25 10:45:00 -070074 Format code to uniform standard.
Bu Sun Kim65e33c02019-10-25 10:45:00 -070075 This currently uses Python 3.6 due to the automated Kokoro run of synthtool.
76 That run uses an image that doesn't have 3.6 installed. Before updating this
77 check the state of the `gcp_ubuntu_config` we use for that Kokoro run.
78 """
79 session.install(BLACK_VERSION)
80 session.run("black", *BLACK_PATHS)
81
82
Tres Seaver6de753d2020-12-11 13:20:39 -050083@nox.session(python=["3.6", "3.7", "3.8", "3.9"])
Bu Sun Kim65e33c02019-10-25 10:45:00 -070084def unit(session):
85 session.install(*TEST_DEPENDENCIES)
Christopher Wilcox7e152582020-09-28 15:27:20 -070086 session.install(*(ASYNC_DEPENDENCIES))
87 session.install(".")
88 session.run(
89 "pytest",
Bu Sun Kime87b1ec2021-03-15 09:02:06 -060090 f"--junitxml=unit_{session.python}_sponge_log.xml",
Christopher Wilcox7e152582020-09-28 15:27:20 -070091 "--cov=google.auth",
92 "--cov=google.oauth2",
93 "--cov=tests",
94 "tests",
95 "tests_async",
96 )
97
98
Tres Seaver6de753d2020-12-11 13:20:39 -050099@nox.session(python=["2.7"])
Christopher Wilcox7e152582020-09-28 15:27:20 -0700100def unit_prev_versions(session):
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700101 session.install(".")
Bu Sun Kim882d0ff2021-02-16 13:10:11 -0700102 session.install(*TEST_DEPENDENCIES)
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700103 session.run(
Bu Sun Kime87b1ec2021-03-15 09:02:06 -0600104 "pytest",
105 f"--junitxml=unit_{session.python}_sponge_log.xml",
106 "--cov=google.auth",
107 "--cov=google.oauth2",
108 "--cov=tests",
109 "tests",
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700110 )
111
112
113@nox.session(python="3.7")
114def cover(session):
115 session.install(*TEST_DEPENDENCIES)
Christopher Wilcox7e152582020-09-28 15:27:20 -0700116 session.install(*(ASYNC_DEPENDENCIES))
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700117 session.install(".")
118 session.run(
119 "pytest",
120 "--cov=google.auth",
121 "--cov=google.oauth2",
122 "--cov=tests",
Christopher Wilcox7e152582020-09-28 15:27:20 -0700123 "--cov=tests_async",
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700124 "--cov-report=",
125 "tests",
Christopher Wilcox7e152582020-09-28 15:27:20 -0700126 "tests_async",
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700127 )
128 session.run("coverage", "report", "--show-missing", "--fail-under=100")
129
130
131@nox.session(python="3.7")
132def docgen(session):
133 session.env["SPHINX_APIDOC_OPTIONS"] = "members,inherited-members,show-inheritance"
134 session.install(*TEST_DEPENDENCIES)
135 session.install("sphinx")
136 session.install(".")
137 session.run("rm", "-r", "docs/reference")
138 session.run(
139 "sphinx-apidoc",
140 "--output-dir",
141 "docs/reference",
142 "--separate",
143 "--module-first",
144 "google",
145 )
146
147
148@nox.session(python="3.7")
149def docs(session):
Bu Sun Kimb1a12d22021-02-26 11:50:02 -0700150 """Build the docs for this library."""
151
152 session.install("-e", ".[aiohttp]")
153 session.install(
154 "sphinx<3.0.0", "alabaster", "recommonmark", "sphinx-docstring-typing"
155 )
156
157 shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
158 session.run(
159 "sphinx-build",
160 "-T", # show full traceback on exception
161 "-W", # warnings as errors
162 "-N", # no colors
163 "-b",
164 "html",
165 "-d",
166 os.path.join("docs", "_build", "doctrees", ""),
167 os.path.join("docs", ""),
168 os.path.join("docs", "_build", "html", ""),
169 )
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700170
171
172@nox.session(python="pypy")
173def pypy(session):
174 session.install(*TEST_DEPENDENCIES)
Tres Seaver3b3172e2020-10-22 16:05:20 -0400175 session.install(*ASYNC_DEPENDENCIES)
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700176 session.install(".")
177 session.run(
Christopher Wilcox7e152582020-09-28 15:27:20 -0700178 "pytest",
Bu Sun Kime87b1ec2021-03-15 09:02:06 -0600179 f"--junitxml=unit_{session.python}_sponge_log.xml",
Christopher Wilcox7e152582020-09-28 15:27:20 -0700180 "--cov=google.auth",
181 "--cov=google.oauth2",
182 "--cov=tests",
183 "tests",
184 "tests_async",
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700185 )