-
Notifications
You must be signed in to change notification settings - Fork 8
443 lines (402 loc) · 15.9 KB
/
python_PR.yml
File metadata and controls
443 lines (402 loc) · 15.9 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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
name: Build, test
on:
[pull_request,workflow_dispatch,push,workflow_call]
jobs:
create_sources:
name: Create source dist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
submodules: recursive
- uses: mamba-org/setup-micromamba@v2
with:
micromamba-version: "latest"
init-shell: bash
condarc: |
channels:
- conda-forge
- name: Build source distribution
shell: bash -el {0}
run: |
micromamba create -n sources python=3.13 pip cython numpy python-build wheel scikit-build-core nanobind
micromamba activate sources
python -m build --sdist --no-isolation
- name: Upload sources
uses: actions/upload-artifact@v6
with:
name: sources-sdist
path: dist
- name: test archive
shell: bash -el {0}
run: |
tar -tf dist/*.tar.gz
build:
name: Build
needs: create_sources
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
os: ["ubuntu-latest", "macos-26-intel", "macos-latest", "windows-latest"]
# https://docs.github.com/en/actions/reference/github-hosted-runners-reference
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- uses: actions/download-artifact@v6
with:
name: sources-sdist
- name: (windows) install tar stuff and extract
if: ${{ matrix.os == 'windows-latest' }}
shell: pwsh
run: |
choco install bzip2 7zip
7z x multipers-*.tar.gz
7z x multipers-*.tar
Move-Item -Path multipers-*/* -Destination .
dir
- name: (unix) extract sources
if: ${{ matrix.os != 'windows-latest' }}
run: |
tar -xvf multipers-*.tar.gz
mv multipers-*/* .
ls
- uses: mamba-org/setup-micromamba@v2
with:
micromamba-version: "latest"
init-shell: >-
bash
powershell
condarc: |
channels:
- conda-forge
- name: dependencies
shell: bash -el {0}
run: |
# conda install mamba -c conda-forge
micromamba create -n build python=${{matrix.python-version}} pip wheel 'gudhi>=3.11' 'numpy>=2' pot 'cython>=3' pytest scikit-learn matplotlib joblib tqdm scipy tbb tbb-devel libboost libboost-devel python-build scikit-build-core llvm-openmp llvm cgal-cpp gmp mpfr eigen cmake c-compiler cxx-compiler clang clangxx ninja nanobind -c conda-forge
micromamba activate build
pip install pykeops filtration-domination --upgrade
- name: tree
if: ${{ matrix.os != 'windows-latest' }}
shell: bash -el {0}
run: |
micromamba activate build
micromamba install tree -c conda-forge
tree
- name: (windows) add dlls
if: ${{ matrix.os == 'windows-latest' }}
shell: pwsh
run: |
micromamba activate build
cp "$env:CONDA_PREFIX\Library\bin\tbb*.dll" multipers
cp "$env:CONDA_PREFIX\Library\bin\libgmp*.dll" multipers
cp "$env:CONDA_PREFIX\Library\bin\libmpfr*.dll" multipers
cp "$env:CONDA_PREFIX\Library\bin\libgcc_s_seh-1.dll" multipers
cp "$env:CONDA_PREFIX\Library\bin\hwloc*.dll" multipers
dir multipers
- name: Build package
shell: bash -el {0}
run: |
ls
micromamba activate build
if [[ ${{ matrix.os }} =~ "macos-".* ]]; then
export MACOSX_DEPLOYMENT_TARGET=11.0
# export cxxflags="-fno-aligned-new" # macos workaround
# export cflags="-fno-aligned-new" # macos workaround
# export macosx_deployment_target="13.0"
fi
if [[ ${{ matrix.os }} =~ "ubuntu-".* ]]; then
export CXXFLAGS="-march=x86-64-v3" # post haswell, for avx
export CFLAGS="-march=x86-64-v3"
export CPPFLAGS="-isystem $CONDA_PREFIX/include"
fi
export CMAKE_BUILD_PARALLEL_LEVEL="$(python -c 'import os; print(os.cpu_count() or 1)')"
python -m build . --no-isolation --wheel -v
- name: Check wheel payload
shell: bash -el {0}
run: |
micromamba activate build
python - <<'PY'
import zipfile
from pathlib import Path
bad_suffixes = {".pyx", ".pxd", ".tp", ".cpp", ".hpp", ".h"}
for wheel in Path("dist").glob("*.whl"):
with zipfile.ZipFile(wheel) as zf:
bad = [
name
for name in zf.namelist()
if name.startswith("multipers/") and Path(name).suffix in bad_suffixes
]
if bad:
raise RuntimeError(f"Found forbidden source files in {wheel}: {bad[:10]}")
print(f"{wheel.name}: OK")
PY
- name: Check Windows wheel DLL dependencies
if: ${{ matrix.os == 'windows-latest' }}
shell: bash -el {0}
run: |
micromamba activate build
python - <<'PY'
import re
import subprocess
import zipfile
from pathlib import Path
system_dlls = {
"kernel32.dll",
"msvcp140.dll",
"python" + "${{ matrix.python-version }}".replace(".", "") + ".dll",
"vcruntime140.dll",
"vcruntime140_1.dll",
}
for wheel in Path("dist").glob("*.whl"):
with zipfile.ZipFile(wheel) as zf:
binaries = [
name
for name in zf.namelist()
if name.startswith("multipers/")
and name.lower().endswith((".pyd", ".dll"))
]
present = {Path(name).name.lower() for name in binaries}
missing = {}
for name in binaries:
with zf.open(name) as src:
path = Path(src.name).name
Path(path).write_bytes(src.read())
out = subprocess.check_output(
["llvm-objdump", "-p", path], text=True, errors="ignore"
)
deps = set(re.findall(r"DLL Name: ([^\s]+)", out))
unresolved = sorted(
dep
for dep in deps
if dep.lower() not in present
and dep.lower() not in system_dlls
and not dep.lower().startswith("api-ms-win-")
)
if unresolved:
missing[name] = unresolved
Path(path).unlink()
if missing:
detail = "\n".join(
f"{binary}: {', '.join(deps)}"
for binary, deps in sorted(missing.items())
)
raise RuntimeError(f"Missing Windows DLL dependencies in {wheel}:\n{detail}")
print(f"{wheel.name}: Windows DLL dependencies OK")
PY
- name: Fix wheels on Linux and Macos
shell: bash -el {0}
if: ${{ matrix.os != 'windows-latest' }}
run: |
micromamba activate build
cd dist
if [[ ${{ matrix.os }} =~ "ubuntu-".* ]]; then
micromamba install auditwheel patchelf -c conda-forge
for wheel_file in multipers*linux*.whl; do
auditwheel show $wheel_file
auditwheel repair $wheel_file --plat manylinux_2_39_x86_64
rm $wheel_file
done
mv wheelhouse/*.whl . # retrieves repaired wheels
fi
if [[ ${{ matrix.os }} == "macos-".*"-intel" ]]; then
micromamba install delocate -c conda-forge
for wheel_file in multipers*macosx*x86*.whl; do
delocate-listdeps $wheel_file
delocate-wheel --require-archs x86_64 -w wheelhouse -v $wheel_file
rm $wheel_file
done
mv wheelhouse/*.whl . # retrieves repaired wheels
fi
if [[ ${{ matrix.os }} == "macos-latest" ]]; then
pip install delocate --upgrade
for wheel_file in multipers*macosx*arm64*.whl; do
delocate-listdeps $wheel_file
delocate-wheel --require-archs arm64 -w wheelhouse -v $wheel_file
rm $wheel_file
done
mv wheelhouse/*.whl . # retrieves repaired wheels
fi
cd ..
- name: Upload sources and wheel
uses: actions/upload-artifact@v6
with:
name: sources-${{ matrix.os }}-${{ matrix.python-version }}
path: dist
- name: Checkout tests
uses: actions/checkout@v6
with:
path: repo
- name: clean install
shell: bash -el {0}
run: |
micromamba create -n test python=${{matrix.python-version}} pip pytest pytest-timeout pytest-rerunfailures -c conda-forge
micromamba activate test
if ! pip install --dry-run --only-binary=:all: gudhi >/dev/null 2>&1; then
echo "SKIP_PYTEST=1" >> "$GITHUB_ENV"
echo "Skipping tests: no pip wheel available for gudhi on Python ${{ matrix.python-version }}"
else
pip install dist/*.whl
fi
- name: Verify core template ownership (unix)
if: ${{ env.SKIP_PYTEST != '1' && matrix.os != 'windows-latest' }}
shell: bash -el {0}
run: |
micromamba activate test
cd "$(mktemp -d)"
python - <<'PY'
import importlib.util
import re
import shutil
import subprocess
import sys
from pathlib import Path
def parse_nm_output(out: str):
rows = []
for line in out.splitlines():
m = re.match(r"^\s*([0-9A-Fa-f]+)?\s*([A-Za-z])\s+(.+)$", line)
if m:
rows.append((m.group(2), m.group(3)))
return rows
def parse_readelf_output(out: str):
rows = []
for line in out.splitlines():
parts = line.split()
if len(parts) < 8 or not parts[0].rstrip(":").isdigit():
continue
ndx = parts[6]
name = parts[7]
rows.append(("U" if ndx == "UND" else "T", name))
return rows
def parse_symbols(path: Path):
commands = []
if sys.platform.startswith("linux"):
commands = [
(["nm", "-D", str(path)], parse_nm_output),
(["readelf", "-Ws", str(path)], parse_readelf_output),
]
else:
commands = [(["nm", "-g", str(path)], parse_nm_output)]
errors = []
for command, parser in commands:
if shutil.which(command[0]) is None:
errors.append(f"{command[0]} not available")
continue
proc = subprocess.run(command, text=True, capture_output=True)
parsed = parser(proc.stdout)
if parsed:
return parsed
stderr = proc.stderr.strip()
if stderr:
errors.append(f"{' '.join(command)} -> {stderr}")
else:
errors.append(f"{' '.join(command)} -> no parseable symbols")
raise RuntimeError(
f"Unable to inspect symbols in {path}: " + " ; ".join(errors)
)
def locate_installed_package_dir(package_name: str) -> Path:
spec = importlib.util.find_spec(package_name)
if spec is None or not spec.submodule_search_locations:
raise RuntimeError(f"Unable to locate installed {package_name} package")
return Path(next(iter(spec.submodule_search_locations))).resolve()
if not any(shutil.which(tool) is not None for tool in ("nm", "readelf")):
raise RuntimeError("nm or readelf is required for symbol ownership checks")
pkg = locate_installed_package_dir("multipers")
core_candidates = sorted(pkg.glob("libmultipers_core*.so"))
if not core_candidates:
raise RuntimeError(f"Missing libmultipers_core shared library in {pkg}")
core = core_candidates[0]
core_defs = {sym for typ, sym in parse_symbols(core) if typ != "U"}
if not core_defs:
raise RuntimeError("libmultipers_core exports no global symbols")
module_prefixes = {
"slicer": {
"pattern": "_slicer_nanobind*.so",
"prefixes": (
"_ZN5Gudhi17multi_persistence6Slicer",
"__ZN5Gudhi17multi_persistence6Slicer",
"_ZN5Gudhi17multi_persistence18Thread_safe_slicer",
"__ZN5Gudhi17multi_persistence18Thread_safe_slicer",
),
"allow_fully_local": True,
},
"simplex_tree_multi": {
"pattern": "_simplex_tree_multi_nanobind*.so",
"prefixes": (
"_ZN5Gudhi14multiparameter16python_interface28Simplex_tree_multi_interface",
"__ZN5Gudhi14multiparameter16python_interface28Simplex_tree_multi_interface",
),
"allow_fully_local": False,
},
}
dep_command = None
if sys.platform == "darwin":
dep_command = ["otool", "-L"]
elif sys.platform.startswith("linux"):
dep_command = ["ldd"]
for module_name, module_info in module_prefixes.items():
prefixes = module_info["prefixes"]
matches = sorted(pkg.glob(module_info["pattern"]))
if not matches:
raise RuntimeError(f"Missing compiled module for {module_name}")
module_path = matches[0]
module_rows = parse_symbols(module_path)
undef = {
sym
for typ, sym in module_rows
if typ == "U" and any(sym.startswith(prefix) for prefix in prefixes)
}
if not undef:
if module_info.get("allow_fully_local", False):
continue
raise RuntimeError(f"No unresolved owned templates found in {module_path.name}")
missing = sorted(undef - core_defs)
if missing:
preview = "\n".join(missing[:5])
raise RuntimeError(
f"{module_path.name} has unresolved templates not provided by {core.name}:\n{preview}"
)
if dep_command is not None:
dep_output = subprocess.check_output(dep_command + [str(module_path)], text=True)
if "multipers_core" not in dep_output:
raise RuntimeError(f"{module_path.name} does not link against multipers core libraries")
print("core template ownership checks passed")
PY
- name: Verify core template ownership (windows)
if: ${{ env.SKIP_PYTEST != '1' && matrix.os == 'windows-latest' }}
shell: bash -el {0}
run: |
micromamba activate test
cd "$(mktemp -d)"
python - <<'PY'
import importlib.util
from importlib import import_module
from pathlib import Path
def locate_installed_package_dir(package_name: str) -> Path:
spec = importlib.util.find_spec(package_name)
if spec is None or not spec.submodule_search_locations:
raise RuntimeError(f"Unable to locate installed {package_name} package")
return Path(next(iter(spec.submodule_search_locations))).resolve()
pkg = locate_installed_package_dir("multipers")
core_dlls = sorted(pkg.glob("*multipers_core*.dll"))
if not core_dlls:
raise RuntimeError(f"Missing multipers core DLL in {pkg}")
import_module("multipers.slicer")
import_module("multipers.simplex_tree_multi")
print("windows core ownership checks passed")
PY
- name: Run pytest
shell: bash -el {0}
run: |
if [ "${SKIP_PYTEST:-0}" = "1" ]; then
echo "Skipping pytest because gudhi pip wheel is unavailable for this Python version."
else
micromamba activate test
if [ "$RUNNER_OS" == "macOS" ]; then
# pykeops workaround
brew install llvm libomp
export CXX=$(brew --prefix llvm)/bin/clang++
fi
cd repo/tests
pytest -rv . --reruns 1 --reruns-delay 2 --timeout=120 --timeout-method=thread
fi