-
Notifications
You must be signed in to change notification settings - Fork 125
Expand file tree
/
Copy pathpyproject.toml
More file actions
310 lines (278 loc) Β· 12.5 KB
/
Copy pathpyproject.toml
File metadata and controls
310 lines (278 loc) Β· 12.5 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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# This file configures wheels compilation for `cibuilwheel` for NumKong CPython bindings.
# On a good day it will produce:
# - `manylinux` and `musllinux` vectorized wheels for Linux on x86_64, aarch64;
# - `manylinux` and `musllinux` wheels for Linux on i686, ppc64le, s390x;
# - `macos` wheels for x86_64, arm64;
# - `windows` wheels for AMD64, ARM64.
# * for 5 Python versions from 3.10 to 3.14.
# * for 2 free-threading Python versions from 3.13 to 3.14.
# * running thousands of fuzzy tests on each wheel.
# = meaning 12 platforms * 7 Python versions = 84 builds.
[build-system]
build-backend = "setuptools.build_meta"
requires = ["setuptools>=42"]
[tool.pyright]
extraPaths = ["test"]
stubPath = "python"
[tool.pytest.ini_options]
addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"]
filterwarnings = ["error"]
minversion = "6.0"
xfail_strict = true
[tool.cibuildwheel]
build-verbosity = 0
test-requires = ["pytest", "pytest-repeat", "pytest-randomly", "tabulate"]
# Assuming NumPy and SciPy aren't available precompiled for some platforms,
# we will end up compiling them from source on emulated hardware...
# To avoid that use `--only-binary=:all:` to only fetch precompiled wheels.
# For better compatibility, we use (&&) to chain commands instead of (;).
test-command = """
python -m pip install numpy --only-binary=:all: || (echo "Failed to install NumPy" && exit 0) &&
python -m pip install scipy --only-binary=:all: || (echo "Failed to install SciPy" && exit 0) &&
python -m pip install ml_dtypes --only-binary=:all: || (echo "Failed to install ml_dtypes" && exit 0) &&
python -c "import numkong; print(numkong.get_capabilities())" &&
PYTHONMALLOC=debug pytest {project}/test/ -s -x -Wd
"""
# We need to build for all platforms:
# - on Linux: x86_64, aarch64, i686
# - on macOS: x86_64, arm64
# - on Windows: AMD64, ARM64
# https://cibuildwheel.readthedocs.io/en/stable/options/#archs
#
# Important to note, not all those platforms have recent images.
# The `manylinux_2_28` seems to be missing for `i686`.
# The `i686` is 32-bit x86, and `x86_64` is 64-bit x86.
archs = ["all"]
# Add "pp*" to skip PyPy builds, but they should work fine these days :)
# https://cibuildwheel.readthedocs.io/en/stable/options/#build-skip
# https://cibuildwheel.readthedocs.io/en/stable/#what-does-it-do
enable = [] # don't enable PyPy
skip = [] # we also don't use any SIMD on: ["*s390x*", "*ppc64le*"]
# Testing half-precision math in QEMU is unreliable!
environment-pass = [
"NK_IN_QEMU",
"NK_SEED",
"NK_FILTER",
"NK_BUDGET_SECS",
"NK_REPETITIONS",
"NK_DENSE_DIMENSIONS",
"NK_CURVED_DIMENSIONS",
"NK_SPARSE_DIMENSIONS",
"NK_MESH_POINTS",
"NK_MATRIX_HEIGHT",
"NK_MATRIX_WIDTH",
"NK_MATRIX_DEPTH",
"NK_MAX_COORD_ANGLE",
"NK_RANDOM_DISTRIBUTION",
"NK_TEST_ASSERT",
"NK_TEST_VERBOSE",
]
[tool.cibuildwheel.environment]
NK_BUILD_PARALLEL = "2"
NK_IN_QEMU = "1"
[tool.cibuildwheel.linux]
before-build = ["rm -rf {project}/build"]
repair-wheel-command = "auditwheel repair -w {dest_dir} {wheel}"
# Pin the platform tag on manylinux_2_28 architectures to avoid verbose
# triple-tagged filenames (e.g., manylinux2014.manylinux_2_17.manylinux_2_28).
# Other architectures (i686, ppc64le, s390x) use older images and keep the default.
[[tool.cibuildwheel.overrides]]
repair-wheel-command = "auditwheel repair --plat manylinux_2_28_x86_64 --only-plat -w {dest_dir} {wheel}"
select = "*-manylinux*_x86_64"
[[tool.cibuildwheel.overrides]]
repair-wheel-command = "auditwheel repair --plat manylinux_2_28_aarch64 --only-plat -w {dest_dir} {wheel}"
select = "*-manylinux*_aarch64"
# Use more recent images for the most popular SIMD-capable CPU architectures, to have access to newer compilers.
# Otherwise, prepare yourself to all kinds of AVX-512 issues and other SIMD-related pain.
# You can keep track of the most recent images on Quay:
# - for `manylinux`: https://quay.io/search?q=manylinux
# - for `musllinux`: https://quay.io/search?q=musllinux
manylinux-aarch64-image = "manylinux_2_28"
manylinux-x86_64-image = "manylinux_2_28"
musllinux-aarch64-image = "musllinux_1_2"
musllinux-x86_64-image = "musllinux_1_2"
# RISC-V wheel uploads are temporarily disabled.
# The official PyPA riscv64 images currently provide LLVM 20 packages, while the
# portable `rv64gcv` baseline plus richer RISC-V kernels now requires Clang 23.
# Keep the image names here as comments until we have either custom images or a
# packaged LLVM 23 path for both manylinux and musllinux.
# manylinux-riscv64-image = "manylinux_2_39"
# musllinux-riscv64-image = "musllinux_1_2"
# On CentOS we have to use `yum`.
# The healthy version would be: `apt-get update && apt-get install -y libc6-dev wget python3-dev`.
# We can't even use direct YUM variant: `yum update -y && yum install -y glibc-devel wget python3-devel`
# as downloading from `extras` fails on Arm instances!
before-all = [
"yum update -y --disablerepo=extras --setopt=install_weak_deps=0 && yum install -y --disablerepo=extras glibc-devel wget python3-devel",
]
# With `musl` builds, we obviously don't need the `glibc` and can't use `yum`.
# This may also be handy for using custom dependencies for different Python versions:
# https://cibuildwheel.readthedocs.io/en/stable/options/#overrides
[[tool.cibuildwheel.overrides]]
before-all = "apk add --update wget python3-dev"
select = "*-musllinux*"
[tool.cibuildwheel.macos]
# Apple Clang ships no `omp.h` / `libomp`. `brew install libomp` alone is not
# enough: the Homebrew bottle targets the runner's OS (e.g. macOS 26 on the
# `macos-26` runner image), while the wheel targets `MACOSX_DEPLOYMENT_TARGET`
# (typically 11.0), so `delocate-wheel` refuses to bundle it:
#
# delocate.libsana.DelocationError: Library dependencies do not satisfy
# target MacOS version 11.0: libomp.dylib has a minimum target of 26.0
#
# So we install the brew keg first (for the symlinks `setup.py:darwin_settings`
# reads via `brew --prefix libomp`), then overwrite `lib/` and `include/`
# with a CMake build of LLVM's `openmp` pinned to the wheel's deployment
# target. Once `delocate` bundles that into the wheel,
# `python/numkong/__init__.py` sets `KMP_DUPLICATE_LIB_OK=TRUE` so the
# bundled runtime coexists with NumPy/SciPy's OpenMP in the same process.
before-all = [
"""
set -euo pipefail
LLVM_VERSION=${LIBOMP_LLVM_VERSION:-20.1.0}
TARGET=${MACOSX_DEPLOYMENT_TARGET:-11.0}
brew install libomp
PREFIX=$(brew --prefix libomp)
work=$(mktemp -d)
cd "$work"
base=https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}
curl -fsSL -o openmp.tar.xz "${base}/openmp-${LLVM_VERSION}.src.tar.xz"
curl -fsSL -o cmake.tar.xz "${base}/cmake-${LLVM_VERSION}.src.tar.xz"
tar -xf openmp.tar.xz
tar -xf cmake.tar.xz
mv "cmake-${LLVM_VERSION}.src" cmake
cd "openmp-${LLVM_VERSION}.src"
cmake -S . -B build \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_OSX_DEPLOYMENT_TARGET="${TARGET}" \
-DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \
-DCMAKE_INSTALL_PREFIX="${PREFIX}" \
-DCMAKE_INSTALL_NAME_DIR="${PREFIX}/lib" \
-DLIBOMP_INSTALL_ALIASES=OFF \
-DOPENMP_ENABLE_LIBOMPTARGET=OFF
cmake --build build --parallel
cmake --install build
""",
]
before-build = ["rm -rf {project}/build"]
repair-wheel-command = "delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel}"
[tool.cibuildwheel.windows]
before-build = ["rd /s /q {project}\\build || echo Done"]
# Windows-based OSes and PowerShell don't support the logical operators
# In PowerShell we could write something like:
# python -m pip install numpy; if ($LASTEXITCODE -ne 0) { echo "Failed to install NumPy... Nothing can stop me, I'm all the way up!" }
# but its safer to use the CMD syntax
[[tool.cibuildwheel.overrides]]
select = "*win*"
test-command = """
cmd /c "python -m pip install numpy & if errorlevel 1 echo Failed to install NumPy... Nothing can stop me, I'm all the way up! &
python -m pip install scipy & if errorlevel 1 echo Failed to install SciPy... Nothing can stop me, I'm all the way up! &
python -m pip install ml_dtypes & if errorlevel 1 echo Failed to install ml_dtypes... Nothing can stop me, I'm all the way up! &
set PYTHONMALLOC=debug && pytest {project}/test/ -s -x -Wd"
"""
# These environment variables allow setup.py to detect the target architecture
# during cross-compilation (e.g., building ARM64 wheels on x64 host).
# The NK_TARGET_* variables override platform.machine() detection.
# x86-64 builds
[[tool.cibuildwheel.overrides]]
environment.NK_TARGET_ARM64_ = "0"
environment.NK_TARGET_X8664_ = "1"
inherit.environment = "append"
select = "*-win_amd64"
[[tool.cibuildwheel.overrides]]
environment.NK_TARGET_ARM64_ = "0"
environment.NK_TARGET_X8664_ = "1"
inherit.environment = "append"
select = "*-manylinux*_x86_64"
[[tool.cibuildwheel.overrides]]
environment.NK_TARGET_ARM64_ = "0"
environment.NK_TARGET_X8664_ = "1"
inherit.environment = "append"
select = "*-musllinux*_x86_64"
[[tool.cibuildwheel.overrides]]
environment.NK_TARGET_ARM64_ = "0"
environment.NK_TARGET_X8664_ = "1"
inherit.environment = "append"
select = "*-macos*_x86_64"
# ARM64 builds
[[tool.cibuildwheel.overrides]]
environment.NK_TARGET_ARM64_ = "1"
environment.NK_TARGET_X8664_ = "0"
inherit.environment = "append"
select = "*-win_arm64"
[[tool.cibuildwheel.overrides]]
environment.NK_TARGET_ARM64_ = "1"
environment.NK_TARGET_X8664_ = "0"
inherit.environment = "append"
select = "*-manylinux*_aarch64"
[[tool.cibuildwheel.overrides]]
environment.NK_TARGET_ARM64_ = "1"
environment.NK_TARGET_X8664_ = "0"
inherit.environment = "append"
select = "*-musllinux*_aarch64"
[[tool.cibuildwheel.overrides]]
environment.NK_TARGET_ARM64_ = "1"
environment.NK_TARGET_X8664_ = "0"
inherit.environment = "append"
select = "*-macos*_arm64"
# RISC-V 64-bit wheels are temporarily disabled.
# Keep the old overrides commented out as a breadcrumb for re-enabling the
# release path once an official LLVM 23 package source is available inside the
# PyPA riscv64 images, or once we switch to custom images with LLVM 23 baked in.
#
# [[tool.cibuildwheel.overrides]]
# before-all = "dnf update -y && dnf install -y glibc-devel wget python3-devel clang lld"
# environment.CC = "clang"
# environment.CXX = "clang++"
# environment.LDFLAGS = "-fuse-ld=lld"
# environment.NK_TARGET_ARM64_ = "0"
# environment.NK_TARGET_RISCV64_ = "1"
# environment.NK_TARGET_X8664_ = "0"
# inherit.environment = "append"
# select = "*-manylinux*_riscv64"
#
# [[tool.cibuildwheel.overrides]]
# before-all = "apk add --update wget python3-dev clang lld"
# environment.CC = "clang"
# environment.CXX = "clang++"
# environment.LDFLAGS = "-fuse-ld=lld"
# environment.NK_TARGET_ARM64_ = "0"
# environment.NK_TARGET_RISCV64_ = "1"
# environment.NK_TARGET_X8664_ = "0"
# inherit.environment = "append"
# select = "*-musllinux*_riscv64"
# Pyodide / Emscripten WASM builds
# The Pyodide venv creates Python-script entry points (like `pytest`) that can't
# be executed directly as shell commands, so we must use `python -m pytest`.
# Also, `ml_dtypes` has no Pyodide wheel, so we skip it.
[[tool.cibuildwheel.overrides]]
before-build = ["rm -rf {project}/build"]
select = "*-pyodide*"
test-command = """
python -m pip install numpy --only-binary=:all: || (echo "Failed to install NumPy" && exit 0) &&
python -m pip install scipy --only-binary=:all: || (echo "Failed to install SciPy" && exit 0) &&
python -c "import numkong; print(numkong.get_capabilities())" &&
PYTHONMALLOC=debug python -m pytest {project}/test/ -s -x -Wd
"""
[tool.ruff]
line-length = 120
target-version = "py310"
[tool.ruff.lint]
ignore = [
"E712", # == True/False: intentional for testing scalar __bool__ return values
"E731", # lambda assignments: clearer for one-liner baselines
"B905", # zip-without-strict: not safety-critical in test code
"SIM105", # contextlib.suppress: explicit try/except is clearer here
"B028", # stacklevel in warnings.warn: not important in test code
"RUF002", # ambiguous unicode in docstrings: intentional math symbols
"RUF003", # ambiguous unicode in comments: intentional math symbols
"RUF043", # pytest.raises regex patterns: the metacharacters are intentional
]
select = ["E", "F", "W", "I", "UP", "B", "SIM", "RUF"]
[tool.ruff.lint.per-file-ignores]
"test/*" = ["E501", "F811"]
# Configuration options for the Black formatter:
# https://black.readthedocs.io/en/latest/usage_and_configuration/the_basics.html#where-black-looks-for-the-file
[tool.black]
line-length = 120 # Set line length to the same value as in `.clang-format` for modern wide screens
target-version = ['py310', 'py314']