forked from scikit-hep/awkward
-
Notifications
You must be signed in to change notification settings - Fork 0
/
noxfile.py
194 lines (153 loc) · 5.5 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE
from __future__ import annotations
import argparse
import os
import pathlib
import shutil
import nox
ALL_PYTHONS = ["3.8", "3.9", "3.10", "3.11", "3.12"]
nox.options.sessions = ["lint", "tests"]
requirements_dev = [
"build",
"numpy",
"packaging",
"PyYAML",
"requests",
"tomli",
]
def remove_if_found(*paths):
for path in paths:
if os.path.isdir(path):
shutil.rmtree(path)
elif os.path.exists(path):
os.unlink(path)
@nox.session(python=ALL_PYTHONS, reuse_venv=True)
def tests(session):
"""
Run the unit and regular tests.
"""
session.install("-r", "requirements-test-full.txt", "./awkward-cpp", ".")
session.run("pytest", *session.posargs if session.posargs else ["tests"])
@nox.session(reuse_venv=True)
def lint(session):
"""
Run the linter.
"""
session.install("pre-commit")
session.run("pre-commit", "run", "--all-files", *session.posargs)
@nox.session(reuse_venv=True)
def pylint(session):
"""
Run the pylint process.
"""
session.install("pylint==3.0.2")
session.run("pylint", "src", *session.posargs)
@nox.session(python=ALL_PYTHONS, reuse_venv=True)
def coverage(session):
"""
Run the unit and regular tests.
"""
session.install("-r", "requirements-test-full.txt", "./awkward-cpp", ".")
session.run(
"pytest", "tests", "--cov=awkward", "--cov-report=xml", *session.posargs
)
@nox.session(reuse_venv=True)
def docs(session):
"""
Build the docs.
"""
parser = argparse.ArgumentParser()
parser.add_argument("--serve", action="store_true")
args = parser.parse_args(session.posargs)
session.install(*requirements_dev)
# Generate C++ documentation
with session.chdir("awkward-cpp/docs"):
session.run("doxygen")
# Copy generated C++ docs to Sphinx
shutil.copytree("awkward-cpp/docs/html", "docs/_static/doxygen", dirs_exist_ok=True)
# Generate kernel documentation
session.run("python", "dev/generate-kernel-docs.py")
# Build Sphinx docs
with session.chdir("docs"):
session.install("-r", "requirements.txt")
session.run("sphinx-build", "-M", "html", ".", "_build")
if args.serve:
session.log("Launching docs at http://localhost:8000/ - use Ctrl-C to quit")
session.run("python", "-m", "http.server", "8000", "-d", "_build/html")
@nox.session(reuse_venv=True)
def clean(session):
"""
Clean generated artifacts.
"""
parser = argparse.ArgumentParser()
parser.add_argument("--headers", action="store_true")
parser.add_argument("--signatures", action="store_true")
parser.add_argument("--tests", action="store_true")
parser.add_argument("--docs", action="store_true")
args = parser.parse_args(session.posargs)
clean_all = not session.posargs
if args.headers or clean_all:
remove_if_found(
pathlib.Path("awkward-cpp", "header-only"),
pathlib.Path("src", "awkward", "_connect", "header-only"),
)
if args.signatures or clean_all:
remove_if_found(
pathlib.Path("awkward-cpp", "include", "awkward", "kernels.h"),
pathlib.Path("awkward-cpp", "src", "awkward_cpp", "_kernel_signatures.py"),
pathlib.Path("src", "awkward", "_connect", "cuda", "_kernel_signatures.py"),
)
if args.tests or clean_all:
remove_if_found(
pathlib.Path("awkward-cpp", "tests-spec"),
pathlib.Path("awkward-cpp", "tests-spec-explicit"),
pathlib.Path("awkward-cpp", "tests-cpu-kernels"),
pathlib.Path("awkward-cpp", "tests-cpu-kernels-explicit"),
pathlib.Path("tests-cuda-kernels"),
)
if args.docs or clean_all:
remove_if_found(pathlib.Path("docs", "reference", "generated", "kernels.rst"))
@nox.session(reuse_venv=True)
def prepare(session):
"""
Prepare for package building.
"""
parser = argparse.ArgumentParser()
parser.add_argument("--headers", action="store_true")
parser.add_argument("--signatures", action="store_true")
parser.add_argument("--tests", action="store_true")
parser.add_argument("--docs", action="store_true")
args = parser.parse_args(session.posargs)
session.install(*requirements_dev)
prepare_all = not session.posargs
if args.headers or prepare_all:
session.run("python", "dev/copy-cpp-headers.py")
if args.signatures or prepare_all:
session.run("python", "dev/generate-kernel-signatures.py")
if args.tests or prepare_all:
session.run("python", "dev/generate-tests.py")
if args.docs or prepare_all:
session.run("python", "dev/generate-kernel-docs.py")
@nox.session(reuse_venv=True)
def check_cpp_constraint(session):
"""
Check that the awkward-cpp version is compatible with awkward.
"""
session.install(*requirements_dev)
session.run("python", "dev/check-awkward-uses-awkward-cpp.py")
@nox.session(reuse_venv=True)
def check_cpp_sdist_released(session):
"""
Check that the awkward-cpp sdist is already on PyPI
"""
session.install(*requirements_dev)
session.run(
"python", "dev/check-awkward-cpp-sdist-matches-pypi.py", *session.posargs
)
@nox.session(reuse_venv=True)
def diagnostics(session):
"""
Check that the CPU kernels are defined correctly.
"""
session.install(*requirements_dev)
session.run("python", "dev/kernel-diagnostics.py", *session.posargs)