blob: d1f61b90c65ad7fb1627af8ae67c637f1a839bad [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
David Buxtonb790e652020-10-29 21:38:01 +000035ASYNC_DEPENDENCIES = ["pytest-asyncio", "aioresponses", "asynctest"]
Christopher Wilcox7e152582020-09-28 15:27:20 -070036
Bu Sun Kim65e33c02019-10-25 10:45:00 -070037BLACK_VERSION = "black==19.3b0"
Christopher Wilcox7e152582020-09-28 15:27:20 -070038BLACK_PATHS = [
39 "google",
40 "tests",
41 "tests_async",
42 "noxfile.py",
43 "setup.py",
44 "docs/conf.py",
45]
Bu Sun Kim65e33c02019-10-25 10:45:00 -070046
47
48@nox.session(python="3.7")
49def lint(session):
50 session.install("flake8", "flake8-import-order", "docutils", BLACK_VERSION)
51 session.install(".")
52 session.run("black", "--check", *BLACK_PATHS)
53 session.run(
54 "flake8",
55 "--import-order-style=google",
56 "--application-import-names=google,tests,system_tests",
57 "google",
58 "tests",
Christopher Wilcox7e152582020-09-28 15:27:20 -070059 "tests_async",
Bu Sun Kim65e33c02019-10-25 10:45:00 -070060 )
61 session.run(
62 "python", "setup.py", "check", "--metadata", "--restructuredtext", "--strict"
63 )
64
65
66@nox.session(python="3.6")
67def blacken(session):
68 """Run black.
Bu Sun Kim65e33c02019-10-25 10:45:00 -070069 Format code to uniform standard.
Bu Sun Kim65e33c02019-10-25 10:45:00 -070070 This currently uses Python 3.6 due to the automated Kokoro run of synthtool.
71 That run uses an image that doesn't have 3.6 installed. Before updating this
72 check the state of the `gcp_ubuntu_config` we use for that Kokoro run.
73 """
74 session.install(BLACK_VERSION)
75 session.run("black", *BLACK_PATHS)
76
77
Tres Seaver6de753d2020-12-11 13:20:39 -050078@nox.session(python=["3.6", "3.7", "3.8", "3.9"])
Bu Sun Kim65e33c02019-10-25 10:45:00 -070079def unit(session):
80 session.install(*TEST_DEPENDENCIES)
Christopher Wilcox7e152582020-09-28 15:27:20 -070081 session.install(*(ASYNC_DEPENDENCIES))
82 session.install(".")
83 session.run(
84 "pytest",
85 "--cov=google.auth",
86 "--cov=google.oauth2",
87 "--cov=tests",
88 "tests",
89 "tests_async",
90 )
91
92
Tres Seaver6de753d2020-12-11 13:20:39 -050093@nox.session(python=["2.7"])
Christopher Wilcox7e152582020-09-28 15:27:20 -070094def unit_prev_versions(session):
Bu Sun Kim65e33c02019-10-25 10:45:00 -070095 session.install(".")
Bu Sun Kim882d0ff2021-02-16 13:10:11 -070096 session.install(*TEST_DEPENDENCIES)
Bu Sun Kim65e33c02019-10-25 10:45:00 -070097 session.run(
98 "pytest", "--cov=google.auth", "--cov=google.oauth2", "--cov=tests", "tests"
99 )
100
101
102@nox.session(python="3.7")
103def cover(session):
104 session.install(*TEST_DEPENDENCIES)
Christopher Wilcox7e152582020-09-28 15:27:20 -0700105 session.install(*(ASYNC_DEPENDENCIES))
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700106 session.install(".")
107 session.run(
108 "pytest",
109 "--cov=google.auth",
110 "--cov=google.oauth2",
111 "--cov=tests",
Christopher Wilcox7e152582020-09-28 15:27:20 -0700112 "--cov=tests_async",
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700113 "--cov-report=",
114 "tests",
Christopher Wilcox7e152582020-09-28 15:27:20 -0700115 "tests_async",
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700116 )
117 session.run("coverage", "report", "--show-missing", "--fail-under=100")
118
119
120@nox.session(python="3.7")
121def docgen(session):
122 session.env["SPHINX_APIDOC_OPTIONS"] = "members,inherited-members,show-inheritance"
123 session.install(*TEST_DEPENDENCIES)
124 session.install("sphinx")
125 session.install(".")
126 session.run("rm", "-r", "docs/reference")
127 session.run(
128 "sphinx-apidoc",
129 "--output-dir",
130 "docs/reference",
131 "--separate",
132 "--module-first",
133 "google",
134 )
135
136
137@nox.session(python="3.7")
138def docs(session):
Bu Sun Kimb1a12d22021-02-26 11:50:02 -0700139 """Build the docs for this library."""
140
141 session.install("-e", ".[aiohttp]")
142 session.install(
143 "sphinx<3.0.0", "alabaster", "recommonmark", "sphinx-docstring-typing"
144 )
145
146 shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
147 session.run(
148 "sphinx-build",
149 "-T", # show full traceback on exception
150 "-W", # warnings as errors
151 "-N", # no colors
152 "-b",
153 "html",
154 "-d",
155 os.path.join("docs", "_build", "doctrees", ""),
156 os.path.join("docs", ""),
157 os.path.join("docs", "_build", "html", ""),
158 )
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700159
160
161@nox.session(python="pypy")
162def pypy(session):
163 session.install(*TEST_DEPENDENCIES)
Tres Seaver3b3172e2020-10-22 16:05:20 -0400164 session.install(*ASYNC_DEPENDENCIES)
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700165 session.install(".")
166 session.run(
Christopher Wilcox7e152582020-09-28 15:27:20 -0700167 "pytest",
168 "--cov=google.auth",
169 "--cov=google.oauth2",
170 "--cov=tests",
171 "tests",
172 "tests_async",
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700173 )