File: setup.py

package info (click to toggle)
pytest-codspeed 4.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,608 kB
  • sloc: ansic: 9,792; python: 2,066; sh: 41; makefile: 14
file content (60 lines) | stat: -rw-r--r-- 1,685 bytes parent folder | download
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
import importlib.util
import os
import platform
from pathlib import Path

from setuptools import setup

build_path = Path(__file__).parent / "src/pytest_codspeed/instruments/hooks/build.py"

spec = importlib.util.spec_from_file_location("build", build_path)
assert spec is not None, "The spec should be initialized"
build = importlib.util.module_from_spec(spec)
assert spec.loader is not None, "The loader should be initialized"
spec.loader.exec_module(build)

system = platform.system()
current_arch = platform.machine()

print(f"System: {system} ({current_arch})")

IS_EXTENSION_BUILDABLE = system == "Linux" and current_arch in [
    "x86_64",
    "aarch64",
]

IS_EXTENSION_REQUIRED = (
    os.environ.get("PYTEST_CODSPEED_FORCE_EXTENSION_BUILD") is not None
)

SKIP_EXTENSION_BUILD = (
    os.environ.get("PYTEST_CODSPEED_SKIP_EXTENSION_BUILD") is not None
)

if SKIP_EXTENSION_BUILD and IS_EXTENSION_REQUIRED:
    raise ValueError("Extension build required but the build requires to skip it")

if IS_EXTENSION_REQUIRED and not IS_EXTENSION_BUILDABLE:
    raise ValueError(
        "The extension is required but the current platform is not supported"
    )

ffi_extension = build.ffibuilder.distutils_extension()
ffi_extension.optional = not IS_EXTENSION_REQUIRED

print(
    "CodSpeed native extension is "
    + ("required" if IS_EXTENSION_REQUIRED else "optional")
)

setup(
    package_data={
        "pytest_codspeed": [
            "instruments/hooks/instrument-hooks/includes/*.h",
            "instruments/hooks/instrument-hooks/dist/*.c",
        ]
    },
    ext_modules=(
        [ffi_extension] if IS_EXTENSION_BUILDABLE and not SKIP_EXTENSION_BUILD else []
    ),
)