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