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