blob: 94661df319c789e75d854708d987a77ce8b77ec4 [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 os
Tres Seaver1a6496a2021-05-25 11:57:22 -040016import pathlib
17import shutil
18
Bu Sun Kim65e33c02019-10-25 10:45:00 -070019import nox
20
Tres Seaver1a6496a2021-05-25 11:57:22 -040021CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
22
Bu Sun Kim65e33c02019-10-25 10:45:00 -070023TEST_DEPENDENCIES = [
24 "flask",
Peter Lamutd86d7b82019-12-12 01:33:45 +010025 "freezegun",
Bu Sun Kim65e33c02019-10-25 10:45:00 -070026 "mock",
27 "oauth2client",
arithmetic1728bb9215a2020-03-20 09:49:44 -070028 "pyopenssl",
Bu Sun Kim65e33c02019-10-25 10:45:00 -070029 "pytest",
30 "pytest-cov",
31 "pytest-localserver",
arithmetic172882293fe2021-04-14 11:22:13 -070032 "pyu2f",
Bu Sun Kim65e33c02019-10-25 10:45:00 -070033 "requests",
34 "urllib3",
35 "cryptography",
Brent Shafferbc0ec932020-02-13 14:11:34 -080036 "responses",
Bu Sun Kim65e33c02019-10-25 10:45:00 -070037 "grpcio",
38]
Christopher Wilcox7e152582020-09-28 15:27:20 -070039
Bu Sun Kimd7c63002021-03-08 14:17:54 -070040ASYNC_DEPENDENCIES = [
41 "pytest-asyncio",
42 "aioresponses",
43 "asynctest",
44 "aiohttp!=3.7.4.post0",
45]
Christopher Wilcox7e152582020-09-28 15:27:20 -070046
Bu Sun Kim65e33c02019-10-25 10:45:00 -070047BLACK_VERSION = "black==19.3b0"
Christopher Wilcox7e152582020-09-28 15:27:20 -070048BLACK_PATHS = [
49 "google",
50 "tests",
51 "tests_async",
52 "noxfile.py",
53 "setup.py",
54 "docs/conf.py",
55]
Bu Sun Kim65e33c02019-10-25 10:45:00 -070056
57
58@nox.session(python="3.7")
59def lint(session):
60 session.install("flake8", "flake8-import-order", "docutils", BLACK_VERSION)
61 session.install(".")
62 session.run("black", "--check", *BLACK_PATHS)
63 session.run(
64 "flake8",
65 "--import-order-style=google",
66 "--application-import-names=google,tests,system_tests",
67 "google",
68 "tests",
Christopher Wilcox7e152582020-09-28 15:27:20 -070069 "tests_async",
Bu Sun Kim65e33c02019-10-25 10:45:00 -070070 )
71 session.run(
72 "python", "setup.py", "check", "--metadata", "--restructuredtext", "--strict"
73 )
74
75
Bu Sun Kima9234422021-05-24 18:16:01 -060076@nox.session(python="3.8")
Bu Sun Kim65e33c02019-10-25 10:45:00 -070077def blacken(session):
78 """Run black.
Bu Sun Kim65e33c02019-10-25 10:45:00 -070079 Format code to uniform standard.
Bu Sun Kima9234422021-05-24 18:16:01 -060080 The Python version should be consistent with what is
81 supplied in the Python Owlbot postprocessor.
82
83 https://github.com/googleapis/synthtool/blob/master/docker/owlbot/python/Dockerfile
Bu Sun Kim65e33c02019-10-25 10:45:00 -070084 """
85 session.install(BLACK_VERSION)
86 session.run("black", *BLACK_PATHS)
87
88
Tres Seaver6de753d2020-12-11 13:20:39 -050089@nox.session(python=["3.6", "3.7", "3.8", "3.9"])
Bu Sun Kim65e33c02019-10-25 10:45:00 -070090def unit(session):
Tres Seaver1a6496a2021-05-25 11:57:22 -040091 constraints_path = str(
92 CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
93 )
94 add_constraints = ["-c", constraints_path]
95 session.install(*(TEST_DEPENDENCIES + add_constraints))
96 session.install(*(ASYNC_DEPENDENCIES + add_constraints))
97 session.install(".", *add_constraints)
Christopher Wilcox7e152582020-09-28 15:27:20 -070098 session.run(
99 "pytest",
Bu Sun Kime87b1ec2021-03-15 09:02:06 -0600100 f"--junitxml=unit_{session.python}_sponge_log.xml",
Christopher Wilcox7e152582020-09-28 15:27:20 -0700101 "--cov=google.auth",
102 "--cov=google.oauth2",
103 "--cov=tests",
Tres Seaver1a6496a2021-05-25 11:57:22 -0400104 "--cov-report=term-missing",
Christopher Wilcox7e152582020-09-28 15:27:20 -0700105 "tests",
106 "tests_async",
107 )
108
109
Tres Seaver6de753d2020-12-11 13:20:39 -0500110@nox.session(python=["2.7"])
Christopher Wilcox7e152582020-09-28 15:27:20 -0700111def unit_prev_versions(session):
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700112 session.install(".")
Bu Sun Kim882d0ff2021-02-16 13:10:11 -0700113 session.install(*TEST_DEPENDENCIES)
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700114 session.run(
Bu Sun Kime87b1ec2021-03-15 09:02:06 -0600115 "pytest",
116 f"--junitxml=unit_{session.python}_sponge_log.xml",
117 "--cov=google.auth",
118 "--cov=google.oauth2",
119 "--cov=tests",
120 "tests",
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700121 )
122
123
124@nox.session(python="3.7")
125def cover(session):
126 session.install(*TEST_DEPENDENCIES)
Christopher Wilcox7e152582020-09-28 15:27:20 -0700127 session.install(*(ASYNC_DEPENDENCIES))
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700128 session.install(".")
129 session.run(
130 "pytest",
131 "--cov=google.auth",
132 "--cov=google.oauth2",
133 "--cov=tests",
Christopher Wilcox7e152582020-09-28 15:27:20 -0700134 "--cov=tests_async",
Tres Seaver1a6496a2021-05-25 11:57:22 -0400135 "--cov-report=term-missing",
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700136 "tests",
Christopher Wilcox7e152582020-09-28 15:27:20 -0700137 "tests_async",
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700138 )
139 session.run("coverage", "report", "--show-missing", "--fail-under=100")
140
141
142@nox.session(python="3.7")
143def docgen(session):
144 session.env["SPHINX_APIDOC_OPTIONS"] = "members,inherited-members,show-inheritance"
145 session.install(*TEST_DEPENDENCIES)
146 session.install("sphinx")
147 session.install(".")
148 session.run("rm", "-r", "docs/reference")
149 session.run(
150 "sphinx-apidoc",
151 "--output-dir",
152 "docs/reference",
153 "--separate",
154 "--module-first",
155 "google",
156 )
157
158
159@nox.session(python="3.7")
160def docs(session):
Bu Sun Kimb1a12d22021-02-26 11:50:02 -0700161 """Build the docs for this library."""
162
163 session.install("-e", ".[aiohttp]")
164 session.install(
165 "sphinx<3.0.0", "alabaster", "recommonmark", "sphinx-docstring-typing"
166 )
167
168 shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
169 session.run(
170 "sphinx-build",
171 "-T", # show full traceback on exception
172 "-W", # warnings as errors
173 "-N", # no colors
174 "-b",
175 "html",
176 "-d",
177 os.path.join("docs", "_build", "doctrees", ""),
178 os.path.join("docs", ""),
179 os.path.join("docs", "_build", "html", ""),
180 )
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700181
182
183@nox.session(python="pypy")
184def pypy(session):
185 session.install(*TEST_DEPENDENCIES)
Tres Seaver3b3172e2020-10-22 16:05:20 -0400186 session.install(*ASYNC_DEPENDENCIES)
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700187 session.install(".")
188 session.run(
Christopher Wilcox7e152582020-09-28 15:27:20 -0700189 "pytest",
Bu Sun Kime87b1ec2021-03-15 09:02:06 -0600190 f"--junitxml=unit_{session.python}_sponge_log.xml",
Christopher Wilcox7e152582020-09-28 15:27:20 -0700191 "--cov=google.auth",
192 "--cov=google.oauth2",
193 "--cov=tests",
194 "tests",
195 "tests_async",
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700196 )