-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnoxfile.py
More file actions
202 lines (155 loc) · 5.92 KB
/
noxfile.py
File metadata and controls
202 lines (155 loc) · 5.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import os
import sys
import nox
nox.options.stop_on_first_error = True
nox.options.reuse_existing_virtualenvs = False
# Default sessions - all tests, but not packaging
nox.options.sessions = [
"black_lint",
"pytest",
"semgrep_src",
"mypy",
"pyflakes_src",
"pyflakes_examples",
"pyflakes_tests",
"pylint_src",
"pylint_examples",
"pylint_tests",
]
_DEFAULT_PYTHON = "3.13"
_ALL_PYTHON = ["3.10", "3.11", "3.12", "3.13", "3.14"]
@nox.session(python=_ALL_PYTHON)
def pytest(session):
"""Run Pytest test suites"""
session.install("-e", ".[test]")
options = session.posargs
if "-k" in options:
options.append("--no-cov")
# Default test set selection done in pyproject.toml
# session.run("pytest", "--log-cli-level=DEBUG", "-v", *options)
session.run("pytest", "-v", *options)
@nox.session(python=_DEFAULT_PYTHON)
def semgrep_src(session):
"""Scan the code for security problems with semgrep"""
session.install("-e", ".[testsecurity]")
# session.run("semgrep", "scan", "--strict", "--verbose", "--error", "--junit-xml", "--junit-xml-output=semgrep-src.xml", "src")
session.run("semgrep", "scan", "--strict", "--verbose", "--error", "src")
@nox.session(python=_DEFAULT_PYTHON)
def black_lint(session):
"""Check code formatting with Black"""
session.install("-e", ".[test]")
session.run("black", "--verbose", "--check", "--diff", "--color", ".")
@nox.session(python=_DEFAULT_PYTHON)
def black_format(session):
"""Fix code formatting with Black"""
session.install("-e", ".[test]")
session.run("black", "--verbose", ".")
@nox.session(python=_DEFAULT_PYTHON)
def mypy(session):
"""Lint all of the code with mypy"""
session.install("-e", ".[test, examples]")
session.run("mypy", "--install-type", "--non-interactive", "--junit-xml", "mypy.xml")
@nox.session(python=_DEFAULT_PYTHON)
def pyflakes_src(session):
"""Lint the library code with Pyflakes"""
session.install("-e", ".[test]")
session.run("pyflakes", "src")
@nox.session(python=_DEFAULT_PYTHON)
def pyflakes_examples(session):
"""Lint the example code with Pyflakes"""
session.install("-e", ".[test, examples]")
session.run("pyflakes", "docs/examples")
@nox.session(python=_DEFAULT_PYTHON)
def pyflakes_tests(session):
"""Lint the test code with Pyflakes"""
session.install("-e", ".[test]")
session.run("pyflakes", "tests")
@nox.session(python=_DEFAULT_PYTHON)
def pylint_src(session):
"""Lint the library code with Pylint"""
session.install("-e", ".[test]")
session.run("pylint", "src")
@nox.session(python=_DEFAULT_PYTHON)
def pylint_examples(session):
"""Lint the example code with Pylint"""
session.install("-e", ".[test, examples]")
session.run("pylint", "docs/examples")
@nox.session(python=_DEFAULT_PYTHON)
def pylint_tests(session):
"""Lint the test code with Pylint"""
session.install("-e", ".[test]")
session.run("pylint", "--disable", "protected-access", "--disable", "unused-variable", "tests")
@nox.session(python=_DEFAULT_PYTHON)
def pkg_build_wheel(session):
"""Build distribution package files"""
session.install("-e", ".[build]")
session.run("pyproject-build")
# session.run("simple503", "-B", "dist", "dist")
@nox.session(python=_DEFAULT_PYTHON)
def pkg_build_local_dist(session):
"""Build distribution package files, and build a local simple PyPi directory that can be used by pip for local testing."""
session.install("-e", ".[build]")
session.run("pyproject-build")
session.run("simple503", "-B", "dist", "dist")
@nox.session(python=_DEFAULT_PYTHON)
def pkg_check(session):
"""Check the built distribution files for errors"""
session.install("-e", ".[build]")
session.run("twine", "check", "--strict", "dist/*.whl", "dist/*.tar.gz")
def _publish_pypi(session, repo_url, token):
session.install("-e", ".[build]")
session.run(
"twine",
"upload",
"--non-interactive",
# "--verbose",
"--username",
"__token__",
"--password",
token,
"--repository-url",
repo_url,
# "--repository",
# repo_name,
"dist/*.whl",
"dist/*.tar.gz",
)
@nox.session(python=_DEFAULT_PYTHON)
def pkg_publish_pypi_prod(session):
"""Publish packages to the production PyPi server"""
token = os.getenv("NOX_PYPI_API_TOKEN")
if not token:
sys.exit("NOX_PYPI_API_TOKEN must be set in the environment with the PyPi access token")
_publish_pypi(session, "https://upload.pypi.org/legacy", token)
@nox.session(python=_DEFAULT_PYTHON)
def pkg_publish_pypi_test(session):
"""Publish packages to the test PyPi server"""
token = os.getenv("NOX_PYPI_API_TOKEN")
if not token:
sys.exit("NOX_PYPI_API_TOKEN must be set in the environment with the PyPi access token")
_publish_pypi(session, "https://test.pypi.org/legacy/", token)
@nox.session(python=_DEFAULT_PYTHON)
def mkdocs_build(session):
"""Build the documentation locally"""
session.install("-e", ".[docs]")
session.run("mkdocs", "-v", "build", "--clean")
@nox.session(python=_DEFAULT_PYTHON)
def mkdocs_checklinks(session):
"""Check links in the documentation"""
session.install("-e", ".[docs]")
session.run("mkdocs-linkcheck", "-v", "-r", "--sync", "docs")
@nox.session(python=_DEFAULT_PYTHON)
def mkdocs_serve(session):
"""Build the documentation and serve locally over HTTP. The server will watch for updates."""
session.install("-e", ".[docs]")
session.run("mkdocs", "-v", "serve")
@nox.session(python=_DEFAULT_PYTHON)
def mkdocs_publish_readthedocs(session):
"""(NOT IMPLEMENTED) Publish the documentation to ReadTheDocs.com"""
session.install("-e", ".[build, docs]")
# TODO - Manual doc publishing
print(
"ERROR: Read The Docs publishing not implemented in the noxfile."
" Documentation publishing is triggered via GitHub webhook."
)
assert False