blob: 168c1e2b63f2146e796d20c32bd61d16a9cc61ee [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",
90 "--cov=google.auth",
91 "--cov=google.oauth2",
92 "--cov=tests",
93 "tests",
94 "tests_async",
95 )
96
97
Tres Seaver6de753d2020-12-11 13:20:39 -050098@nox.session(python=["2.7"])
Christopher Wilcox7e152582020-09-28 15:27:20 -070099def unit_prev_versions(session):
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700100 session.install(".")
Bu Sun Kim882d0ff2021-02-16 13:10:11 -0700101 session.install(*TEST_DEPENDENCIES)
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700102 session.run(
103 "pytest", "--cov=google.auth", "--cov=google.oauth2", "--cov=tests", "tests"
104 )
105
106
107@nox.session(python="3.7")
108def cover(session):
109 session.install(*TEST_DEPENDENCIES)
Christopher Wilcox7e152582020-09-28 15:27:20 -0700110 session.install(*(ASYNC_DEPENDENCIES))
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700111 session.install(".")
112 session.run(
113 "pytest",
114 "--cov=google.auth",
115 "--cov=google.oauth2",
116 "--cov=tests",
Christopher Wilcox7e152582020-09-28 15:27:20 -0700117 "--cov=tests_async",
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700118 "--cov-report=",
119 "tests",
Christopher Wilcox7e152582020-09-28 15:27:20 -0700120 "tests_async",
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700121 )
122 session.run("coverage", "report", "--show-missing", "--fail-under=100")
123
124
125@nox.session(python="3.7")
126def docgen(session):
127 session.env["SPHINX_APIDOC_OPTIONS"] = "members,inherited-members,show-inheritance"
128 session.install(*TEST_DEPENDENCIES)
129 session.install("sphinx")
130 session.install(".")
131 session.run("rm", "-r", "docs/reference")
132 session.run(
133 "sphinx-apidoc",
134 "--output-dir",
135 "docs/reference",
136 "--separate",
137 "--module-first",
138 "google",
139 )
140
141
142@nox.session(python="3.7")
143def docs(session):
Bu Sun Kimb1a12d22021-02-26 11:50:02 -0700144 """Build the docs for this library."""
145
146 session.install("-e", ".[aiohttp]")
147 session.install(
148 "sphinx<3.0.0", "alabaster", "recommonmark", "sphinx-docstring-typing"
149 )
150
151 shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
152 session.run(
153 "sphinx-build",
154 "-T", # show full traceback on exception
155 "-W", # warnings as errors
156 "-N", # no colors
157 "-b",
158 "html",
159 "-d",
160 os.path.join("docs", "_build", "doctrees", ""),
161 os.path.join("docs", ""),
162 os.path.join("docs", "_build", "html", ""),
163 )
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700164
165
166@nox.session(python="pypy")
167def pypy(session):
168 session.install(*TEST_DEPENDENCIES)
Tres Seaver3b3172e2020-10-22 16:05:20 -0400169 session.install(*ASYNC_DEPENDENCIES)
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700170 session.install(".")
171 session.run(
Christopher Wilcox7e152582020-09-28 15:27:20 -0700172 "pytest",
173 "--cov=google.auth",
174 "--cov=google.oauth2",
175 "--cov=tests",
176 "tests",
177 "tests_async",
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700178 )