Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 1 | # 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 Kim | b1a12d2 | 2021-02-26 11:50:02 -0700 | [diff] [blame] | 15 | import os |
Tres Seaver | 1a6496a | 2021-05-25 11:57:22 -0400 | [diff] [blame] | 16 | import pathlib |
| 17 | import shutil |
| 18 | |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 19 | import nox |
| 20 | |
Tres Seaver | 1a6496a | 2021-05-25 11:57:22 -0400 | [diff] [blame] | 21 | CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() |
| 22 | |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 23 | BLACK_VERSION = "black==19.3b0" |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 24 | BLACK_PATHS = [ |
| 25 | "google", |
| 26 | "tests", |
| 27 | "tests_async", |
| 28 | "noxfile.py", |
| 29 | "setup.py", |
| 30 | "docs/conf.py", |
| 31 | ] |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 32 | |
| 33 | |
| 34 | @nox.session(python="3.7") |
| 35 | def lint(session): |
| 36 | session.install("flake8", "flake8-import-order", "docutils", BLACK_VERSION) |
Tres Seaver | 560cf1e | 2021-08-03 16:35:54 -0400 | [diff] [blame] | 37 | session.install("-e", ".") |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 38 | 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 Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 45 | "tests_async", |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 46 | ) |
| 47 | session.run( |
| 48 | "python", "setup.py", "check", "--metadata", "--restructuredtext", "--strict" |
| 49 | ) |
| 50 | |
| 51 | |
Bu Sun Kim | a923442 | 2021-05-24 18:16:01 -0600 | [diff] [blame] | 52 | @nox.session(python="3.8") |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 53 | def blacken(session): |
| 54 | """Run black. |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 55 | Format code to uniform standard. |
Bu Sun Kim | a923442 | 2021-05-24 18:16:01 -0600 | [diff] [blame] | 56 | 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 Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 60 | """ |
| 61 | session.install(BLACK_VERSION) |
| 62 | session.run("black", *BLACK_PATHS) |
| 63 | |
| 64 | |
Tres Seaver | 19d41f8 | 2021-10-07 13:05:19 -0400 | [diff] [blame] | 65 | @nox.session(python=["3.6", "3.7", "3.8", "3.9", "3.10"]) |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 66 | def unit(session): |
Tres Seaver | 1a6496a | 2021-05-25 11:57:22 -0400 | [diff] [blame] | 67 | constraints_path = str( |
| 68 | CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" |
| 69 | ) |
Bu Sun Kim | a4cf9b1 | 2021-10-15 11:26:39 -0600 | [diff] [blame] | 70 | session.install("-r", "testing/requirements.txt", "-c", constraints_path) |
| 71 | session.install("-e", ".", "-c", constraints_path) |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 72 | session.run( |
| 73 | "pytest", |
Bu Sun Kim | e87b1ec | 2021-03-15 09:02:06 -0600 | [diff] [blame] | 74 | f"--junitxml=unit_{session.python}_sponge_log.xml", |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 75 | "--cov=google.auth", |
| 76 | "--cov=google.oauth2", |
| 77 | "--cov=tests", |
Tres Seaver | 1a6496a | 2021-05-25 11:57:22 -0400 | [diff] [blame] | 78 | "--cov-report=term-missing", |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 79 | "tests", |
| 80 | "tests_async", |
| 81 | ) |
| 82 | |
| 83 | |
arithmetic1728 | 5bd5ccf | 2021-10-21 15:25:46 -0700 | [diff] [blame] | 84 | @nox.session(python=["2.7"]) |
| 85 | def 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 Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 101 | @nox.session(python="3.7") |
| 102 | def cover(session): |
Bu Sun Kim | a4cf9b1 | 2021-10-15 11:26:39 -0600 | [diff] [blame] | 103 | session.install("-r", "testing/requirements.txt") |
Tres Seaver | 560cf1e | 2021-08-03 16:35:54 -0400 | [diff] [blame] | 104 | session.install("-e", ".") |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 105 | session.run( |
| 106 | "pytest", |
| 107 | "--cov=google.auth", |
| 108 | "--cov=google.oauth2", |
| 109 | "--cov=tests", |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 110 | "--cov=tests_async", |
Tres Seaver | 1a6496a | 2021-05-25 11:57:22 -0400 | [diff] [blame] | 111 | "--cov-report=term-missing", |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 112 | "tests", |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 113 | "tests_async", |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 114 | ) |
| 115 | session.run("coverage", "report", "--show-missing", "--fail-under=100") |
| 116 | |
| 117 | |
| 118 | @nox.session(python="3.7") |
| 119 | def docgen(session): |
| 120 | session.env["SPHINX_APIDOC_OPTIONS"] = "members,inherited-members,show-inheritance" |
Bu Sun Kim | a4cf9b1 | 2021-10-15 11:26:39 -0600 | [diff] [blame] | 121 | session.install("-r", "testing/requirements.txt") |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 122 | session.install("sphinx") |
Tres Seaver | 560cf1e | 2021-08-03 16:35:54 -0400 | [diff] [blame] | 123 | session.install("-e", ".") |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 124 | 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 Seaver | b76f151 | 2021-08-13 18:37:08 -0400 | [diff] [blame] | 135 | @nox.session(python="3.8") |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 136 | def docs(session): |
Bu Sun Kim | b1a12d2 | 2021-02-26 11:50:02 -0700 | [diff] [blame] | 137 | """Build the docs for this library.""" |
| 138 | |
| 139 | session.install("-e", ".[aiohttp]") |
Bu Sun Kim | 642d736 | 2021-10-26 10:02:29 -0600 | [diff] [blame] | 140 | session.install("sphinx", "alabaster", "recommonmark", "sphinx-docstring-typing") |
Bu Sun Kim | b1a12d2 | 2021-02-26 11:50:02 -0700 | [diff] [blame] | 141 | |
| 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 Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 155 | |
| 156 | |
| 157 | @nox.session(python="pypy") |
| 158 | def pypy(session): |
Bu Sun Kim | a4cf9b1 | 2021-10-15 11:26:39 -0600 | [diff] [blame] | 159 | session.install("-r", "test/requirements.txt") |
Tres Seaver | 560cf1e | 2021-08-03 16:35:54 -0400 | [diff] [blame] | 160 | session.install("-e", ".") |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 161 | session.run( |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 162 | "pytest", |
Bu Sun Kim | e87b1ec | 2021-03-15 09:02:06 -0600 | [diff] [blame] | 163 | f"--junitxml=unit_{session.python}_sponge_log.xml", |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 164 | "--cov=google.auth", |
| 165 | "--cov=google.oauth2", |
| 166 | "--cov=tests", |
| 167 | "tests", |
| 168 | "tests_async", |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 169 | ) |