-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathnoxfile.py
More file actions
201 lines (161 loc) · 4.72 KB
/
noxfile.py
File metadata and controls
201 lines (161 loc) · 4.72 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
# noxfile.py
import importlib
import os
import shutil
import nox
nox.options.sessions = []
@nox.session(name="cleanup", python=False)
def run_cleanup(session: nox.Session) -> None:
"""Use os/shutil to remove some files/directories"""
if os.path.exists(".coverage"):
os.remove(".coverage")
if os.path.exists("reports"):
shutil.rmtree("reports")
folders = [".pytest_cache"]
for f in folders:
if os.path.exists(f):
shutil.rmtree(f)
# Recursively delete all __pycache__ folders and .pyc files
session.run(
"find",
".",
"-type",
"d",
"-name",
"__pycache__",
"-exec",
"rm",
"-r",
"{}",
"+",
external=True,
)
session.run(
"find", ".", "-type", "f", "-name", "*.pyc", "-delete", external=True
)
@nox.session(name="lint", python=False)
@nox.session(name="linter", python=False)
def run_lint(session: nox.Session) -> None:
"""
Run black and isort with the github config file
"""
session.run("pip", "install", "--upgrade", "--quiet", "black")
session.run("pip", "install", "--upgrade", "--quiet", "isort")
black_command = [
"black",
"--line-length",
"79",
"--target-version",
"py314",
"--exclude",
".pixi",
"--exclude",
"pixi*",
".",
]
isort_command = [
"isort",
"--profile",
"black",
"--multi-line",
"3",
"--trailing-comma",
"--force-grid-wrap",
"0",
"--line-length",
"79",
"--use-parentheses",
"--skip",
".pixi",
"--skip",
"pixi*",
".",
]
if not "write" in session.posargs:
black_command.insert(1, "--check")
isort_command.insert(1, "--check-only")
isort_command.insert(2, "--diff")
session.run(*black_command)
session.run(*isort_command)
@nox.session(name="spell", python=False)
@nox.session(name="codespell", python=False)
def run_codespell(session: nox.Session) -> None:
"""
Run codespell with the github config file
Use the optional 'write' argument to write the corrections directly into
the files. Otherwise, you will only see a summary of the found errors.
"""
session.run("pip", "install", "--upgrade", "--quiet", "codespell")
command = ["codespell", "--config", ".github/linters/.codespellrc"]
if "write" in session.posargs:
command.append("-w")
session.run(*command)
@nox.session(name="pypi", python=False)
@nox.session(name="deploy", python=False)
def run_deploy(session: nox.Session) -> None:
"""
Deploy to pypi
"""
session.run("pip", "install", "build")
session.run("pip", "install", "twine")
session.run("python", "-m", "build")
session.run(
"python",
"-m",
"twine",
"upload",
"--verbose",
"--repository",
"pypi",
"dist/*",
)
@nox.session(name="tests", python=False)
@nox.session(name="test", python=False)
def run_pytest(session: nox.Session) -> None:
"""
Run pytest and generate test/coverage reports
Use the optional 'parallel' argument to run the tests in parallel. As just
a flag, the number of workers will be determined automatically. Otherwise,
you can specify the number of workers using an int, e.g., parallel=4.
"""
package = importlib.util.find_spec("bird")
if "no-reports" in session.posargs:
command = [
"pytest",
f"--cov=.", # for editable or site-packages
"tests/",
]
else:
command = [
"pytest",
"--cov=bird",
"--cov-report=html:reports/htmlcov",
"--cov-report=xml:reports/coverage.xml",
"--junitxml=reports/junit.xml",
"tests/",
]
for arg in session.posargs:
if arg.startswith("parallel="):
command[1:1] = ["-n", arg.split("=")[-1]]
elif arg.startswith("parallel"):
command[1:1] = ["-n", "auto"]
session.run(*command)
run_cleanup(session)
@nox.session(name="docs", python=False)
def run_sphinx(session: nox.Session) -> None:
"""
Run spellcheck and then use sphinx to build docs
"""
run_codespell(session)
os.chdir("docs")
session.run("make", "html")
os.chdir(" .. ".strip())
def run_pre_commit(session: nox.Session) -> None:
"""
Run all linters/tests and make new badges
Order of sessions: flake8, codespell, pytest, genbade. Using 'format' for
linter, 'write' for codespell, and/or 'parallel' for pytest is permitted.
"""
run_lint(session)
run_codespell(session)
run_pytest(session)