Skip to content

Commit b03d88a

Browse files
committed
feat: check buildability and fallback when build doesn't work
1 parent ccd2997 commit b03d88a

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,12 @@ jobs:
5454
run: sudo apt-get install valgrind -y
5555
- name: Install dependencies with pytest${{ matrix.pytest-version }}
5656
run: |
57-
uv sync --all-extras --dev --locked
57+
if [ "${{ matrix.config }}" == "valgrind" ]; then
58+
export PYTEST_CODSPEED_FORCE_EXTENSION=1
59+
fi
60+
uv sync --all-extras --dev --locked --verbose
5861
uv pip install "pytest${{ matrix.pytest-version }}"
59-
uv pip uninstall -y pytest-benchmark
62+
uv pip uninstall pytest-benchmark
6063
- if: matrix.config == 'pytest-benchmark-4'
6164
name: Install pytest-benchmark 4.0.0
6265
run: uv pip install pytest-benchmark~=4.0.0

setup.py

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,41 @@
1+
import importlib.util
12
import os
23
import platform
4+
from pathlib import Path
35

46
from setuptools import setup
57

8+
build_path = (
9+
Path(__file__).parent / "src/pytest_codspeed/instruments/valgrind/_wrapper/build.py"
10+
)
11+
12+
spec = importlib.util.spec_from_file_location("build", build_path)
13+
assert spec is not None, "The spec should be initialized"
14+
build = importlib.util.module_from_spec(spec)
15+
assert spec.loader is not None, "The loader should be initialized"
16+
spec.loader.exec_module(build)
17+
618
system = platform.system()
719
current_arch = platform.machine()
820

9-
IS_EXTENSION_REQUIRED = (
10-
system == "Linux"
11-
and current_arch
12-
in [
13-
"x86_64",
14-
"arm64",
15-
]
16-
or os.environ.get("PYTEST_CODSPEED_FORCE_EXTENSION") is not None
21+
IS_EXTENSION_BUILDABLE = system == "Linux" and current_arch in [
22+
"x86_64",
23+
"arm64",
24+
]
25+
26+
IS_EXTENSION_REQUIRED = os.environ.get("PYTEST_CODSPEED_FORCE_EXTENSION") is not None
27+
if IS_EXTENSION_REQUIRED and not IS_EXTENSION_BUILDABLE:
28+
raise ValueError(
29+
"The extension is required but the current platform is not supported"
30+
)
31+
32+
33+
ffi_extension = build.ffibuilder.distutils_extension()
34+
ffi_extension.optional = not IS_EXTENSION_REQUIRED
35+
36+
print(
37+
"CodSpeed native extension is "
38+
+ ("required" if IS_EXTENSION_REQUIRED else "optional")
1739
)
1840

1941
setup(
@@ -23,9 +45,5 @@
2345
"instruments/valgrind/_wrapper/*.c",
2446
]
2547
},
26-
cffi_modules=[
27-
"src/pytest_codspeed/instruments/valgrind/_wrapper/build.py:ffibuilder"
28-
]
29-
if IS_EXTENSION_REQUIRED
30-
else [],
48+
ext_modules=[ffi_extension] if IS_EXTENSION_BUILDABLE else [],
3149
)

0 commit comments

Comments
 (0)