blob: caeb2725a2053e7a8e930e0b29e7d6004bc48005 [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)
Tres Seaver560cf1e2021-08-03 16:35:54 -040061 session.install("-e", ".")
Bu Sun Kim65e33c02019-10-25 10:45:00 -070062 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))
Tres Seaver560cf1e2021-08-03 16:35:54 -040097 session.install("-e", ".", *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
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700110@nox.session(python="3.7")
111def cover(session):
112 session.install(*TEST_DEPENDENCIES)
Christopher Wilcox7e152582020-09-28 15:27:20 -0700113 session.install(*(ASYNC_DEPENDENCIES))
Tres Seaver560cf1e2021-08-03 16:35:54 -0400114 session.install("-e", ".")
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700115 session.run(
116 "pytest",
117 "--cov=google.auth",
118 "--cov=google.oauth2",
119 "--cov=tests",
Christopher Wilcox7e152582020-09-28 15:27:20 -0700120 "--cov=tests_async",
Tres Seaver1a6496a2021-05-25 11:57:22 -0400121 "--cov-report=term-missing",
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700122 "tests",
Christopher Wilcox7e152582020-09-28 15:27:20 -0700123 "tests_async",
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700124 )
125 session.run("coverage", "report", "--show-missing", "--fail-under=100")
126
127
128@nox.session(python="3.7")
129def docgen(session):
130 session.env["SPHINX_APIDOC_OPTIONS"] = "members,inherited-members,show-inheritance"
131 session.install(*TEST_DEPENDENCIES)
132 session.install("sphinx")
Tres Seaver560cf1e2021-08-03 16:35:54 -0400133 session.install("-e", ".")
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700134 session.run("rm", "-r", "docs/reference")
135 session.run(
136 "sphinx-apidoc",
137 "--output-dir",
138 "docs/reference",
139 "--separate",
140 "--module-first",
141 "google",
142 )
143
144
Tres Seaverb76f1512021-08-13 18:37:08 -0400145@nox.session(python="3.8")
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700146def docs(session):
Bu Sun Kimb1a12d22021-02-26 11:50:02 -0700147 """Build the docs for this library."""
148
149 session.install("-e", ".[aiohttp]")
150 session.install(
151 "sphinx<3.0.0", "alabaster", "recommonmark", "sphinx-docstring-typing"
152 )
153
154 shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
155 session.run(
156 "sphinx-build",
157 "-T", # show full traceback on exception
158 "-W", # warnings as errors
159 "-N", # no colors
160 "-b",
161 "html",
162 "-d",
163 os.path.join("docs", "_build", "doctrees", ""),
164 os.path.join("docs", ""),
165 os.path.join("docs", "_build", "html", ""),
166 )
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700167
168
169@nox.session(python="pypy")
170def pypy(session):
171 session.install(*TEST_DEPENDENCIES)
Tres Seaver3b3172e2020-10-22 16:05:20 -0400172 session.install(*ASYNC_DEPENDENCIES)
Tres Seaver560cf1e2021-08-03 16:35:54 -0400173 session.install("-e", ".")
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700174 session.run(
Christopher Wilcox7e152582020-09-28 15:27:20 -0700175 "pytest",
Bu Sun Kime87b1ec2021-03-15 09:02:06 -0600176 f"--junitxml=unit_{session.python}_sponge_log.xml",
Christopher Wilcox7e152582020-09-28 15:27:20 -0700177 "--cov=google.auth",
178 "--cov=google.oauth2",
179 "--cov=tests",
180 "tests",
181 "tests_async",
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700182 )