-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnoxfile.py
More file actions
252 lines (204 loc) · 7.57 KB
/
Copy pathnoxfile.py
File metadata and controls
252 lines (204 loc) · 7.57 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
"""Nox sessions for building, testing, and development of pointprocess."""
import nox
import platform
from pathlib import Path
# Python versions to test
nox.options.default_venv_backend = "venv"
DEFAULT_PYTHON = "3.11"
PYTHON_VERSIONS = ["3.9", "3.10", "3.11", "3.12", "3.13"]
@nox.session
def build(session: nox.Session) -> None:
"""Build the project in Release mode."""
session.log("Building pointprocess in Release mode...")
session.run("cmake", "--preset", "release", external=True)
session.run("cmake", "--build", "--preset", "release", external=True)
session.log("✓ Build complete. Output in 'build/' directory")
@nox.session
def test(session: nox.Session) -> None:
"""Run the test suite."""
session.log("Running test suite...")
# Install dependencies
session.install("pytest", "pytest-cov")
# Build tests
session.run("cmake", "--preset", "tests-with-coverage", external=True)
session.run(
"cmake",
"--build",
"--preset",
"tests-with-coverage",
external=True,
)
# Run tests
test_exe = Path("build-tests") / "tests" / "RunTests"
if platform.system() == "Windows":
test_exe = test_exe.with_suffix(".exe")
session.run(str(test_exe), external=True)
session.log("✓ All tests passed!")
@nox.session
def coverage(session: nox.Session) -> None:
"""Generate code coverage report."""
session.log("Generating coverage report...")
# Requires lcov, gcov on Unix systems
if platform.system() == "Windows":
session.log("⚠ Coverage report generation requires lcov (Unix-only)")
return
# Build tests with coverage instrumentation
session.log("Building tests with coverage instrumentation...")
session.run("cmake", "--preset", "tests-with-coverage", external=True)
session.run("cmake", "--build", "--preset", "tests-with-coverage", external=True)
build_dir = Path("build-tests")
# Zero coverage counters
session.log("Zeroing coverage counters...")
session.run("lcov", "--zerocounters", "--directory", str(build_dir), external=True)
# Run tests
session.log("Running tests...")
test_exe = build_dir / "tests" / "RunTests"
if not test_exe.exists():
session.log(f"⚠ Test executable not found at {test_exe}")
return
session.run(str(test_exe), external=True)
# Capture coverage information
session.log("Capturing coverage information...")
coverage_file = build_dir / "coverage.info"
session.run(
"lcov",
"--capture",
"--directory", str(build_dir / "tests"),
"-o", str(coverage_file),
"--include", f"{Path.cwd()}/src/pointprocess/*",
"--gcov-tool", "gcov",
external=True,
)
# Generate HTML report
session.log("Generating HTML coverage report...")
out_dir = build_dir / "out"
session.run("genhtml", str(coverage_file), "--output-directory", str(out_dir), external=True)
index_file = out_dir / "index.html"
if index_file.exists():
session.log(f"✓ Coverage report generated: {index_file}")
else:
session.log("⚠ Coverage report may not have been generated")
@nox.session(name="lint")
def lint(session: nox.Session) -> None:
"""Run code formatting checks."""
session.log("Running code quality checks...")
session.install("clang-tools")
# Check formatting using glob expansion
session.log("Checking code formatting with clang-format...")
cpp_files = list(Path("src/pointprocess").glob("*.cpp"))
h_files = list(Path("src/pointprocess").glob("*.h"))
if cpp_files or h_files:
format_files = [str(f) for f in cpp_files + h_files]
session.run(
"clang-format",
"--dry-run",
"-i",
"-ferror-limit=0",
*format_files,
external=True,
success_codes=[0, 1], # clang-format returns 0 if no changes, 1 if changes needed
)
session.log("✓ Code formatting check complete")
else:
session.log("⚠ No source files found to check")
@nox.session(name="dev")
def dev(session: nox.Session) -> None:
"""Set up an interactive development environment."""
session.log("Setting up development environment...")
# Install Python dev dependencies
session.install(
"pytest",
"pytest-cov",
"black",
"isort",
"mypy",
"numpy",
"scipy",
"matplotlib",
)
# Build C++ extension using CMake
session.log("Building C++ extension with CMake...")
session.run("cmake", "--preset", "release", external=True)
session.run("cmake", "--build", "--preset", "release", external=True)
# Add built library to PYTHONPATH so it can be imported
build_lib = Path("build/src").resolve()
session.log(f"✓ Built library at: {build_lib}")
session.log("✓ Development environment ready!")
session.log("\nTo import pointprocess, set PYTHONPATH:")
session.log(f" export PYTHONPATH={build_lib}:$PYTHONPATH")
session.log("\nOr use the following in Python:")
session.log(f" import sys; sys.path.insert(0, '{build_lib}')")
session.log("\nTips for development:")
session.log(" - Build: nox -s build")
session.log(" - Test: nox -s test")
session.log(" - Lint: nox -s lint")
session.log(" - Wheel: nox -s wheel")
session.log(" - Docs: nox -s docs")
@nox.session
def wheel(session: nox.Session) -> None:
"""Build a wheel for the current platform."""
session.log("Building wheel for current platform...")
session.install("build", "scikit-build-core", "cmake", "ninja", "pybind11")
env = {}
if platform.system() == "Darwin":
# Use Apple Clang for wheel builds to ensure ABI compatibility with
# system Python. Homebrew LLVM's libc++ is ABI-incompatible with
# the system libc++ that CPython links against.
env["CC"] = "/usr/bin/cc"
env["CXX"] = "/usr/bin/c++"
session.run(
"python",
"-m",
"build",
"--wheel",
"--outdir",
"dist",
env=env,
)
wheels = list(Path("dist").glob("*.whl"))
if wheels:
session.log(f"✓ Wheel created: {wheels[-1].name}")
else:
session.log("⚠ Wheel build completed but files not found")
@nox.session
def docs(session: nox.Session) -> None:
"""Build Sphinx documentation."""
session.log("Building documentation...")
session.install("-r", "docs/requirements.txt")
session.run(
"python",
"-m",
"sphinx",
"-W",
"-a",
"-n",
"docs/source",
"docs/_build/html",
external=True,
)
index_file = Path("docs/_build/html/index.html")
if index_file.exists():
session.log(f"✓ Documentation built: {index_file}")
else:
session.log("⚠ Documentation build may have encountered issues")
@nox.session(name="clean")
def clean(session: nox.Session) -> None:
"""Clean build artifacts."""
session.log("Cleaning build artifacts...")
import shutil
dirs_to_remove = [
Path("build"),
Path("build-tests"),
Path("dist"),
Path("docs/_build"),
Path(".eggs"),
Path(".nox"),
]
for dir_path in dirs_to_remove:
if dir_path.exists():
shutil.rmtree(dir_path)
session.log(f" Removed {dir_path}")
# Remove Python cache
for pycache in Path(".").rglob("__pycache__"):
shutil.rmtree(pycache)
session.log("✓ Cleanup complete")