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