-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoxfile.py
175 lines (130 loc) · 4.63 KB
/
noxfile.py
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
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.9", "3.10", "3.11", "3.12", "3.13"]
@nox.session(python=_ALL_PYTHON)
def pytest(session):
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", "-v", *options)
@nox.session(python=_DEFAULT_PYTHON)
def semgrep_src(session):
session.install("-e", ".[test]")
# 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):
session.install("-e", ".[test]")
session.run("black", "--verbose", "--check", "--diff", "--color", ".")
@nox.session(python=_DEFAULT_PYTHON)
def black_format(session):
session.install("-e", ".[test]")
session.run("black", "--verbose", ".")
@nox.session(python=_DEFAULT_PYTHON)
def mypy(session):
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):
session.install("-e", ".[test]")
session.run("pyflakes", "src")
@nox.session(python=_DEFAULT_PYTHON)
def pyflakes_examples(session):
session.install("-e", ".[test, examples]")
session.run("pyflakes", "docs/examples")
@nox.session(python=_DEFAULT_PYTHON)
def pyflakes_tests(session):
session.install("-e", ".[test]")
session.run("pyflakes", "tests")
@nox.session(python=_DEFAULT_PYTHON)
def pylint_src(session):
session.install("-e", ".[test]")
session.run("pylint", "src")
@nox.session(python=_DEFAULT_PYTHON)
def pylint_examples(session):
session.install("-e", ".[test, examples]")
session.run("pylint", "docs/examples")
@nox.session(python=_DEFAULT_PYTHON)
def pylint_tests(session):
session.install("-e", ".[test]")
session.run("pylint", "--disable", "protected-access", "--disable", "unused-variable", "tests")
@nox.session(python=_DEFAULT_PYTHON)
def pkg_build_wheel(session):
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):
session.install("-e", ".[build]")
session.run("pyproject-build")
session.run("simple503", "-B", "dist", "dist")
@nox.session(python=_DEFAULT_PYTHON)
def pkg_check(session):
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):
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):
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):
session.install("-e", ".[docs]")
session.run("mkdocs", "-v", "build", "--clean")
@nox.session(python=_DEFAULT_PYTHON)
def mkdocs_serve(session):
session.install("-e", ".[docs]")
session.run("mkdocs", "-v", "serve")
@nox.session(python=_DEFAULT_PYTHON)
def mkdocs_publish_readthedocs(session):
session.install("-e", ".[build, docs]")
# TODO - Manual doc publushing
print(
"ERROR: Read The Docs publishing not implemented in the noxfile."
" Documentation publishing is triggered via GitHub webhook."
)
assert False