blob: efb367e83891b05eeef56a6d4619fe9fca1dfbd2 [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 -070023BLACK_VERSION = "black==19.3b0"
Christopher Wilcox7e152582020-09-28 15:27:20 -070024BLACK_PATHS = [
25 "google",
26 "tests",
27 "tests_async",
28 "noxfile.py",
29 "setup.py",
30 "docs/conf.py",
31]
Bu Sun Kim65e33c02019-10-25 10:45:00 -070032
33
34@nox.session(python="3.7")
35def lint(session):
36 session.install("flake8", "flake8-import-order", "docutils", BLACK_VERSION)
Tres Seaver560cf1e2021-08-03 16:35:54 -040037 session.install("-e", ".")
Bu Sun Kim65e33c02019-10-25 10:45:00 -070038 session.run("black", "--check", *BLACK_PATHS)
39 session.run(
40 "flake8",
41 "--import-order-style=google",
42 "--application-import-names=google,tests,system_tests",
43 "google",
44 "tests",
Christopher Wilcox7e152582020-09-28 15:27:20 -070045 "tests_async",
Bu Sun Kim65e33c02019-10-25 10:45:00 -070046 )
47 session.run(
48 "python", "setup.py", "check", "--metadata", "--restructuredtext", "--strict"
49 )
50
51
Bu Sun Kima9234422021-05-24 18:16:01 -060052@nox.session(python="3.8")
Bu Sun Kim65e33c02019-10-25 10:45:00 -070053def blacken(session):
54 """Run black.
Bu Sun Kim65e33c02019-10-25 10:45:00 -070055 Format code to uniform standard.
Bu Sun Kima9234422021-05-24 18:16:01 -060056 The Python version should be consistent with what is
57 supplied in the Python Owlbot postprocessor.
58
59 https://github.com/googleapis/synthtool/blob/master/docker/owlbot/python/Dockerfile
Bu Sun Kim65e33c02019-10-25 10:45:00 -070060 """
61 session.install(BLACK_VERSION)
62 session.run("black", *BLACK_PATHS)
63
64
Tres Seaver19d41f82021-10-07 13:05:19 -040065@nox.session(python=["3.6", "3.7", "3.8", "3.9", "3.10"])
Bu Sun Kim65e33c02019-10-25 10:45:00 -070066def unit(session):
Tres Seaver1a6496a2021-05-25 11:57:22 -040067 constraints_path = str(
68 CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
69 )
Bu Sun Kima4cf9b12021-10-15 11:26:39 -060070 session.install("-r", "testing/requirements.txt", "-c", constraints_path)
71 session.install("-e", ".", "-c", constraints_path)
Christopher Wilcox7e152582020-09-28 15:27:20 -070072 session.run(
73 "pytest",
Bu Sun Kime87b1ec2021-03-15 09:02:06 -060074 f"--junitxml=unit_{session.python}_sponge_log.xml",
Christopher Wilcox7e152582020-09-28 15:27:20 -070075 "--cov=google.auth",
76 "--cov=google.oauth2",
77 "--cov=tests",
Tres Seaver1a6496a2021-05-25 11:57:22 -040078 "--cov-report=term-missing",
Christopher Wilcox7e152582020-09-28 15:27:20 -070079 "tests",
80 "tests_async",
81 )
82
83
arithmetic17285bd5ccf2021-10-21 15:25:46 -070084@nox.session(python=["2.7"])
85def unit_prev_versions(session):
86 constraints_path = str(
87 CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
88 )
89 session.install("-r", "testing/requirements.txt", "-c", constraints_path)
90 session.install("-e", ".", "-c", constraints_path)
91 session.run(
92 "pytest",
93 f"--junitxml=unit_{session.python}_sponge_log.xml",
94 "--cov=google.auth",
95 "--cov=google.oauth2",
96 "--cov=tests",
97 "tests",
98 )
99
100
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700101@nox.session(python="3.7")
102def cover(session):
Bu Sun Kima4cf9b12021-10-15 11:26:39 -0600103 session.install("-r", "testing/requirements.txt")
Tres Seaver560cf1e2021-08-03 16:35:54 -0400104 session.install("-e", ".")
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700105 session.run(
106 "pytest",
107 "--cov=google.auth",
108 "--cov=google.oauth2",
109 "--cov=tests",
Christopher Wilcox7e152582020-09-28 15:27:20 -0700110 "--cov=tests_async",
Tres Seaver1a6496a2021-05-25 11:57:22 -0400111 "--cov-report=term-missing",
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700112 "tests",
Christopher Wilcox7e152582020-09-28 15:27:20 -0700113 "tests_async",
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700114 )
115 session.run("coverage", "report", "--show-missing", "--fail-under=100")
116
117
118@nox.session(python="3.7")
119def docgen(session):
120 session.env["SPHINX_APIDOC_OPTIONS"] = "members,inherited-members,show-inheritance"
Bu Sun Kima4cf9b12021-10-15 11:26:39 -0600121 session.install("-r", "testing/requirements.txt")
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700122 session.install("sphinx")
Tres Seaver560cf1e2021-08-03 16:35:54 -0400123 session.install("-e", ".")
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700124 session.run("rm", "-r", "docs/reference")
125 session.run(
126 "sphinx-apidoc",
127 "--output-dir",
128 "docs/reference",
129 "--separate",
130 "--module-first",
131 "google",
132 )
133
134
Tres Seaverb76f1512021-08-13 18:37:08 -0400135@nox.session(python="3.8")
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700136def docs(session):
Bu Sun Kimb1a12d22021-02-26 11:50:02 -0700137 """Build the docs for this library."""
138
139 session.install("-e", ".[aiohttp]")
Bu Sun Kim642d7362021-10-26 10:02:29 -0600140 session.install("sphinx", "alabaster", "recommonmark", "sphinx-docstring-typing")
Bu Sun Kimb1a12d22021-02-26 11:50:02 -0700141
142 shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
143 session.run(
144 "sphinx-build",
145 "-T", # show full traceback on exception
146 "-W", # warnings as errors
147 "-N", # no colors
148 "-b",
149 "html",
150 "-d",
151 os.path.join("docs", "_build", "doctrees", ""),
152 os.path.join("docs", ""),
153 os.path.join("docs", "_build", "html", ""),
154 )
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700155
156
157@nox.session(python="pypy")
158def pypy(session):
Bu Sun Kima4cf9b12021-10-15 11:26:39 -0600159 session.install("-r", "test/requirements.txt")
Tres Seaver560cf1e2021-08-03 16:35:54 -0400160 session.install("-e", ".")
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700161 session.run(
Christopher Wilcox7e152582020-09-28 15:27:20 -0700162 "pytest",
Bu Sun Kime87b1ec2021-03-15 09:02:06 -0600163 f"--junitxml=unit_{session.python}_sponge_log.xml",
Christopher Wilcox7e152582020-09-28 15:27:20 -0700164 "--cov=google.auth",
165 "--cov=google.oauth2",
166 "--cov=tests",
167 "tests",
168 "tests_async",
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700169 )