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 shutil |
| 16 | import os |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 17 | import nox |
| 18 | |
| 19 | TEST_DEPENDENCIES = [ |
| 20 | "flask", |
Peter Lamut | d86d7b8 | 2019-12-12 01:33:45 +0100 | [diff] [blame] | 21 | "freezegun", |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 22 | "mock", |
| 23 | "oauth2client", |
arithmetic1728 | bb9215a | 2020-03-20 09:49:44 -0700 | [diff] [blame] | 24 | "pyopenssl", |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 25 | "pytest", |
| 26 | "pytest-cov", |
| 27 | "pytest-localserver", |
| 28 | "requests", |
| 29 | "urllib3", |
| 30 | "cryptography", |
Brent Shaffer | bc0ec93 | 2020-02-13 14:11:34 -0800 | [diff] [blame] | 31 | "responses", |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 32 | "grpcio", |
| 33 | ] |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 34 | |
Bu Sun Kim | d7c6300 | 2021-03-08 14:17:54 -0700 | [diff] [blame] | 35 | ASYNC_DEPENDENCIES = [ |
| 36 | "pytest-asyncio", |
| 37 | "aioresponses", |
| 38 | "asynctest", |
| 39 | "aiohttp!=3.7.4.post0", |
| 40 | ] |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 41 | |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 42 | BLACK_VERSION = "black==19.3b0" |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 43 | BLACK_PATHS = [ |
| 44 | "google", |
| 45 | "tests", |
| 46 | "tests_async", |
| 47 | "noxfile.py", |
| 48 | "setup.py", |
| 49 | "docs/conf.py", |
| 50 | ] |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 51 | |
| 52 | |
| 53 | @nox.session(python="3.7") |
| 54 | def lint(session): |
| 55 | session.install("flake8", "flake8-import-order", "docutils", BLACK_VERSION) |
| 56 | session.install(".") |
| 57 | session.run("black", "--check", *BLACK_PATHS) |
| 58 | session.run( |
| 59 | "flake8", |
| 60 | "--import-order-style=google", |
| 61 | "--application-import-names=google,tests,system_tests", |
| 62 | "google", |
| 63 | "tests", |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 64 | "tests_async", |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 65 | ) |
| 66 | session.run( |
| 67 | "python", "setup.py", "check", "--metadata", "--restructuredtext", "--strict" |
| 68 | ) |
| 69 | |
| 70 | |
| 71 | @nox.session(python="3.6") |
| 72 | def blacken(session): |
| 73 | """Run black. |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 74 | Format code to uniform standard. |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 75 | This currently uses Python 3.6 due to the automated Kokoro run of synthtool. |
| 76 | That run uses an image that doesn't have 3.6 installed. Before updating this |
| 77 | check the state of the `gcp_ubuntu_config` we use for that Kokoro run. |
| 78 | """ |
| 79 | session.install(BLACK_VERSION) |
| 80 | session.run("black", *BLACK_PATHS) |
| 81 | |
| 82 | |
Tres Seaver | 6de753d | 2020-12-11 13:20:39 -0500 | [diff] [blame] | 83 | @nox.session(python=["3.6", "3.7", "3.8", "3.9"]) |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 84 | def unit(session): |
| 85 | session.install(*TEST_DEPENDENCIES) |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 86 | session.install(*(ASYNC_DEPENDENCIES)) |
| 87 | session.install(".") |
| 88 | session.run( |
| 89 | "pytest", |
Bu Sun Kim | e87b1ec | 2021-03-15 09:02:06 -0600 | [diff] [blame^] | 90 | f"--junitxml=unit_{session.python}_sponge_log.xml", |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 91 | "--cov=google.auth", |
| 92 | "--cov=google.oauth2", |
| 93 | "--cov=tests", |
| 94 | "tests", |
| 95 | "tests_async", |
| 96 | ) |
| 97 | |
| 98 | |
Tres Seaver | 6de753d | 2020-12-11 13:20:39 -0500 | [diff] [blame] | 99 | @nox.session(python=["2.7"]) |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 100 | def unit_prev_versions(session): |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 101 | session.install(".") |
Bu Sun Kim | 882d0ff | 2021-02-16 13:10:11 -0700 | [diff] [blame] | 102 | session.install(*TEST_DEPENDENCIES) |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 103 | session.run( |
Bu Sun Kim | e87b1ec | 2021-03-15 09:02:06 -0600 | [diff] [blame^] | 104 | "pytest", |
| 105 | f"--junitxml=unit_{session.python}_sponge_log.xml", |
| 106 | "--cov=google.auth", |
| 107 | "--cov=google.oauth2", |
| 108 | "--cov=tests", |
| 109 | "tests", |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 110 | ) |
| 111 | |
| 112 | |
| 113 | @nox.session(python="3.7") |
| 114 | def cover(session): |
| 115 | session.install(*TEST_DEPENDENCIES) |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 116 | session.install(*(ASYNC_DEPENDENCIES)) |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 117 | session.install(".") |
| 118 | session.run( |
| 119 | "pytest", |
| 120 | "--cov=google.auth", |
| 121 | "--cov=google.oauth2", |
| 122 | "--cov=tests", |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 123 | "--cov=tests_async", |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 124 | "--cov-report=", |
| 125 | "tests", |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 126 | "tests_async", |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 127 | ) |
| 128 | session.run("coverage", "report", "--show-missing", "--fail-under=100") |
| 129 | |
| 130 | |
| 131 | @nox.session(python="3.7") |
| 132 | def docgen(session): |
| 133 | session.env["SPHINX_APIDOC_OPTIONS"] = "members,inherited-members,show-inheritance" |
| 134 | session.install(*TEST_DEPENDENCIES) |
| 135 | session.install("sphinx") |
| 136 | session.install(".") |
| 137 | session.run("rm", "-r", "docs/reference") |
| 138 | session.run( |
| 139 | "sphinx-apidoc", |
| 140 | "--output-dir", |
| 141 | "docs/reference", |
| 142 | "--separate", |
| 143 | "--module-first", |
| 144 | "google", |
| 145 | ) |
| 146 | |
| 147 | |
| 148 | @nox.session(python="3.7") |
| 149 | def docs(session): |
Bu Sun Kim | b1a12d2 | 2021-02-26 11:50:02 -0700 | [diff] [blame] | 150 | """Build the docs for this library.""" |
| 151 | |
| 152 | session.install("-e", ".[aiohttp]") |
| 153 | session.install( |
| 154 | "sphinx<3.0.0", "alabaster", "recommonmark", "sphinx-docstring-typing" |
| 155 | ) |
| 156 | |
| 157 | shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) |
| 158 | session.run( |
| 159 | "sphinx-build", |
| 160 | "-T", # show full traceback on exception |
| 161 | "-W", # warnings as errors |
| 162 | "-N", # no colors |
| 163 | "-b", |
| 164 | "html", |
| 165 | "-d", |
| 166 | os.path.join("docs", "_build", "doctrees", ""), |
| 167 | os.path.join("docs", ""), |
| 168 | os.path.join("docs", "_build", "html", ""), |
| 169 | ) |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 170 | |
| 171 | |
| 172 | @nox.session(python="pypy") |
| 173 | def pypy(session): |
| 174 | session.install(*TEST_DEPENDENCIES) |
Tres Seaver | 3b3172e | 2020-10-22 16:05:20 -0400 | [diff] [blame] | 175 | session.install(*ASYNC_DEPENDENCIES) |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 176 | session.install(".") |
| 177 | session.run( |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 178 | "pytest", |
Bu Sun Kim | e87b1ec | 2021-03-15 09:02:06 -0600 | [diff] [blame^] | 179 | f"--junitxml=unit_{session.python}_sponge_log.xml", |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 180 | "--cov=google.auth", |
| 181 | "--cov=google.oauth2", |
| 182 | "--cov=tests", |
| 183 | "tests", |
| 184 | "tests_async", |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 185 | ) |