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