blob: e238c973ce2520dd1187f7d6c008ec003f1fbb2f [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
Bu Sun Kim65e33c02019-10-25 10:45:00 -070084@nox.session(python="3.7")
85def cover(session):
Bu Sun Kima4cf9b12021-10-15 11:26:39 -060086 session.install("-r", "testing/requirements.txt")
Tres Seaver560cf1e2021-08-03 16:35:54 -040087 session.install("-e", ".")
Bu Sun Kim65e33c02019-10-25 10:45:00 -070088 session.run(
89 "pytest",
90 "--cov=google.auth",
91 "--cov=google.oauth2",
92 "--cov=tests",
Christopher Wilcox7e152582020-09-28 15:27:20 -070093 "--cov=tests_async",
Tres Seaver1a6496a2021-05-25 11:57:22 -040094 "--cov-report=term-missing",
Bu Sun Kim65e33c02019-10-25 10:45:00 -070095 "tests",
Christopher Wilcox7e152582020-09-28 15:27:20 -070096 "tests_async",
Bu Sun Kim65e33c02019-10-25 10:45:00 -070097 )
98 session.run("coverage", "report", "--show-missing", "--fail-under=100")
99
100
101@nox.session(python="3.7")
102def docgen(session):
103 session.env["SPHINX_APIDOC_OPTIONS"] = "members,inherited-members,show-inheritance"
Bu Sun Kima4cf9b12021-10-15 11:26:39 -0600104 session.install("-r", "testing/requirements.txt")
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700105 session.install("sphinx")
Tres Seaver560cf1e2021-08-03 16:35:54 -0400106 session.install("-e", ".")
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700107 session.run("rm", "-r", "docs/reference")
108 session.run(
109 "sphinx-apidoc",
110 "--output-dir",
111 "docs/reference",
112 "--separate",
113 "--module-first",
114 "google",
115 )
116
117
Tres Seaverb76f1512021-08-13 18:37:08 -0400118@nox.session(python="3.8")
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700119def docs(session):
Bu Sun Kimb1a12d22021-02-26 11:50:02 -0700120 """Build the docs for this library."""
121
122 session.install("-e", ".[aiohttp]")
123 session.install(
124 "sphinx<3.0.0", "alabaster", "recommonmark", "sphinx-docstring-typing"
125 )
126
127 shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
128 session.run(
129 "sphinx-build",
130 "-T", # show full traceback on exception
131 "-W", # warnings as errors
132 "-N", # no colors
133 "-b",
134 "html",
135 "-d",
136 os.path.join("docs", "_build", "doctrees", ""),
137 os.path.join("docs", ""),
138 os.path.join("docs", "_build", "html", ""),
139 )
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700140
141
142@nox.session(python="pypy")
143def pypy(session):
Bu Sun Kima4cf9b12021-10-15 11:26:39 -0600144 session.install("-r", "test/requirements.txt")
Tres Seaver560cf1e2021-08-03 16:35:54 -0400145 session.install("-e", ".")
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700146 session.run(
Christopher Wilcox7e152582020-09-28 15:27:20 -0700147 "pytest",
Bu Sun Kime87b1ec2021-03-15 09:02:06 -0600148 f"--junitxml=unit_{session.python}_sponge_log.xml",
Christopher Wilcox7e152582020-09-28 15:27:20 -0700149 "--cov=google.auth",
150 "--cov=google.oauth2",
151 "--cov=tests",
152 "tests",
153 "tests_async",
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700154 )