|
20 | 20 | import pathlib |
21 | 21 | import shutil |
22 | 22 | from pathlib import Path |
23 | | -from typing import Optional |
24 | 23 |
|
25 | 24 | import nox |
26 | 25 |
|
27 | 26 | DEFAULT_PYTHON_VERSION = "3.10" |
28 | 27 | CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() |
| 28 | +LINT_PATHS = ["src", "tests", "noxfile.py"] |
| 29 | + |
29 | 30 |
|
30 | 31 | nox.options.sessions = [ |
31 | | - "docs", |
| 32 | + "blacken", |
32 | 33 | "docfx", |
| 34 | + "docs", |
| 35 | + "format", |
| 36 | + "lint", |
| 37 | + "unit", |
33 | 38 | ] |
34 | 39 |
|
35 | 40 | # Error if a python version is missing |
36 | 41 | nox.options.error_on_missing_interpreters = True |
37 | 42 |
|
38 | 43 |
|
39 | | -@nox.session(python="3.10") |
| 44 | +@nox.session(python=DEFAULT_PYTHON_VERSION) |
40 | 45 | def docs(session): |
41 | 46 | """Build the docs for this library.""" |
42 | 47 |
|
@@ -71,7 +76,7 @@ def docs(session): |
71 | 76 | ) |
72 | 77 |
|
73 | 78 |
|
74 | | -@nox.session(python="3.10") |
| 79 | +@nox.session(python=DEFAULT_PYTHON_VERSION) |
75 | 80 | def docfx(session): |
76 | 81 | """Build the docfx yaml files for this library.""" |
77 | 82 |
|
@@ -115,3 +120,99 @@ def docfx(session): |
115 | 120 | os.path.join("docs", ""), |
116 | 121 | os.path.join("docs", "_build", "html", ""), |
117 | 122 | ) |
| 123 | + |
| 124 | + |
| 125 | +@nox.session(python=DEFAULT_PYTHON_VERSION) |
| 126 | +def lint(session): |
| 127 | + """Run linters. |
| 128 | +
|
| 129 | + Returns a failure if the linters find linting errors or |
| 130 | + sufficiently serious code quality issues. |
| 131 | + """ |
| 132 | + session.install(".[lint]") |
| 133 | + session.run( |
| 134 | + "black", |
| 135 | + "--check", |
| 136 | + *LINT_PATHS, |
| 137 | + ) |
| 138 | + session.run("flake8", "src", "tests") |
| 139 | + |
| 140 | + |
| 141 | +@nox.session(python=DEFAULT_PYTHON_VERSION) |
| 142 | +def lint_setup_py(session): |
| 143 | + """Verify that setup.py is valid (including an RST check).""" |
| 144 | + session.install("docutils", "pygments") |
| 145 | + session.run("python", "setup.py", "check", "--restructuredtext", "--strict") |
| 146 | + |
| 147 | + |
| 148 | +@nox.session(python=DEFAULT_PYTHON_VERSION) |
| 149 | +def blacken(session): |
| 150 | + session.install(".[lint]") |
| 151 | + session.run( |
| 152 | + "black", |
| 153 | + *LINT_PATHS, |
| 154 | + ) |
| 155 | + |
| 156 | + |
| 157 | +@nox.session(python=DEFAULT_PYTHON_VERSION) |
| 158 | +def format(session): |
| 159 | + session.install(".[lint]") |
| 160 | + # Sort imports in strict alphabetical order. |
| 161 | + session.run( |
| 162 | + "isort", |
| 163 | + *LINT_PATHS, |
| 164 | + ) |
| 165 | + session.run( |
| 166 | + "black", |
| 167 | + *LINT_PATHS, |
| 168 | + ) |
| 169 | + |
| 170 | + |
| 171 | +@nox.session(python=DEFAULT_PYTHON_VERSION) |
| 172 | +def unit(session): |
| 173 | + install_unittest_dependencies(session) |
| 174 | + session.run( |
| 175 | + "py.test", |
| 176 | + "--quiet", |
| 177 | + os.path.join("tests", "unit"), |
| 178 | + *session.posargs, |
| 179 | + ) |
| 180 | + |
| 181 | + |
| 182 | +def install_unittest_dependencies(session, *constraints): |
| 183 | + session.install(".[test]") |
| 184 | + session.run( |
| 185 | + "pip", |
| 186 | + "install", |
| 187 | + "--no-compile", # To ensure no byte recompliation which is usually super slow |
| 188 | + "-q", |
| 189 | + "--disable-pip-version-check", # Avoid the slow version check |
| 190 | + ".", |
| 191 | + "-r", |
| 192 | + "requirements.txt", |
| 193 | + ) |
| 194 | + |
| 195 | + |
| 196 | +@nox.session(python=DEFAULT_PYTHON_VERSION) |
| 197 | +def integration(session): |
| 198 | + install_integrationtest_dependencies(session) |
| 199 | + session.run( |
| 200 | + "py.test", |
| 201 | + "--quiet", |
| 202 | + os.path.join("tests", "integration"), |
| 203 | + *session.posargs, |
| 204 | + ) |
| 205 | + |
| 206 | + |
| 207 | +def install_integrationtest_dependencies(session): |
| 208 | + session.install(".[test]") |
| 209 | + session.run( |
| 210 | + "pip", |
| 211 | + "install", |
| 212 | + "--no-compile", # To ensure no byte recompliation which is usually super slow |
| 213 | + "-q", |
| 214 | + "--disable-pip-version-check", # Avoid the slow version check |
| 215 | + ".", |
| 216 | + "-r", |
| 217 | + "requirements.txt", |
| 218 | + ) |
0 commit comments