-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathnoxfile.py
More file actions
141 lines (117 loc) · 4.1 KB
/
noxfile.py
File metadata and controls
141 lines (117 loc) · 4.1 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
import os
import shutil
import sys
from pathlib import Path
import nox
DIR = Path(__file__).parent.resolve()
PYTHON_ALL_VERSIONS = ["3.10", "3.11", "3.12", "3.13"]
PYTHON_DEFAULT_VERSION = "3.10"
# Platform logic
if sys.platform == "darwin":
PLATFORM = "macos"
elif sys.platform == "win32":
PLATFORM = "win"
else:
PLATFORM = "unix"
# Some platform specific actions
if PLATFORM == "macos":
if os.environ.get("NPX_MACOS_INSTALL_DEPENDENCIES", False):
os.system("brew install llvm libomp")
@nox.session(python=PYTHON_ALL_VERSIONS)
def build_wheel(session: nox.Session) -> None:
"""Build a wheel"""
session.install("build")
temp_path = session.create_tmp()
session.run("pip", "wheel", "--no-deps", "--wheel-dir", temp_path, ".")
wheel_name = [
name for name in os.listdir(temp_path) if name.endswith(".whl")
][0]
if PLATFORM == "unix" and os.environ.get("NPX_LINUX_FIX_WHEELS", False):
session.install("auditwheel")
session.run(
"auditwheel",
"repair",
os.path.join(temp_path, wheel_name),
"-w",
DIR / "wheelhouse",
)
elif PLATFORM == "macos":
session.install("delocate==0.10.4")
session.run(
"delocate-wheel",
"-v",
os.path.join(temp_path, wheel_name),
"-w",
DIR / "wheelhouse",
)
else:
os.makedirs(DIR / "wheelhouse", exist_ok=True)
for file in os.listdir(temp_path):
if file.endswith(".whl"):
shutil.copy(os.path.join(temp_path, file), DIR / "wheelhouse")
@nox.session(python=PYTHON_DEFAULT_VERSION)
def build_sdist(session: nox.Session) -> None:
"""Build an SDist"""
session.install("build")
session.run("python", "-m", "build", "--sdist", "-o", "wheelhouse")
@nox.session(python=PYTHON_DEFAULT_VERSION)
def clear_wheelhouse(session: nox.Session) -> None:
"""Clear the wheelhouse"""
shutil.rmtree(DIR / "wheelhouse", ignore_errors=True)
def _run_pytest(session, *extra_args):
"""Helper to enforce sequential pytest execution"""
args = [str(DIR / "tests")]
if extra_args:
args.extend(extra_args)
# 🚫 Force sequential pytest, even if xdist is installed
session.run("pytest", "-n", "0", *args)
session.run("coverage", "xml")
@nox.session(python=PYTHON_ALL_VERSIONS)
def test_source(session):
"""Run tests from source"""
extra_args = os.environ.get("NPX_PYTEST_ARGS", "").split()
session.run("pip", "install", "-e", ".[test]")
_run_pytest(session, *extra_args)
@nox.session(python=PYTHON_ALL_VERSIONS)
def test_wheel(session):
"""Run tests from wheel"""
python_version_str = f"cp{session.python.replace('.', '')}"
wheel_names = [
wheel
for wheel in os.listdir("wheelhouse")
if wheel.endswith(".whl") and python_version_str in wheel
]
wheel_names.sort()
wheel_name = wheel_names[-1]
session.run(
"pip", "install", "-U", DIR / "wheelhouse" / f"{wheel_name}[test]"
)
with session.chdir(".nox"):
extra_args = os.environ.get("NPX_PYTEST_ARGS", "").split()
_run_pytest(session, *extra_args)
@nox.session(python=PYTHON_ALL_VERSIONS)
def test_testpypi(session):
"""Run tests against TestPyPI"""
session.run(
"pip",
"install",
"-U",
"--extra-index-url",
"https://testpypi.python.org/pypi",
"nanopyx[all]",
)
with session.chdir(".nox"):
extra_args = os.environ.get("NPX_PYTEST_ARGS", "").split()
_run_pytest(session, *extra_args)
@nox.session(python=PYTHON_ALL_VERSIONS)
def test_pypi(session):
"""Run tests against PyPI"""
session.run("pip", "install", "-U", "nanopyx[all]")
with session.chdir(".nox"):
extra_args = os.environ.get("NPX_PYTEST_ARGS", "").split()
_run_pytest(session, *extra_args)
@nox.session(python=PYTHON_DEFAULT_VERSION)
def generate_docs(session: nox.Session) -> None:
"""Generate the docs"""
session.run("pip", "install", "-e", ".[doc, optional]")
session.run("pdoc", DIR / "src" / "nanopyx", "-o", DIR / "docs")