|
| 1 | +import importlib.util |
1 | 2 | import os
|
2 | 3 | import platform
|
| 4 | +from pathlib import Path |
3 | 5 |
|
4 | 6 | from setuptools import setup
|
5 | 7 |
|
| 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 | + |
6 | 18 | system = platform.system()
|
7 | 19 | current_arch = platform.machine()
|
8 | 20 |
|
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") |
17 | 39 | )
|
18 | 40 |
|
19 | 41 | setup(
|
|
23 | 45 | "instruments/valgrind/_wrapper/*.c",
|
24 | 46 | ]
|
25 | 47 | },
|
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 [], |
31 | 49 | )
|
0 commit comments