-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.py
More file actions
81 lines (63 loc) · 2.08 KB
/
setup.py
File metadata and controls
81 lines (63 loc) · 2.08 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
"""
setup.py — custom build step for the pzp Python package.
The C library (libpzp.so) is compiled via the project Makefile and then
copied into the package source tree so that it is included in the wheel
and found at runtime next to pzp/__init__.py.
For an editable install (pip install -e .) the library is left at the repo
root, and pzp/_find_lib() falls back to searching there.
"""
import os
import shutil
import subprocess
import sys
from pathlib import Path
from setuptools import setup
from setuptools.command.build_py import build_py
from setuptools.command.develop import develop
# Platform-specific library filename
_LIB_NAME = {
"linux": "libpzp.so",
"darwin": "libpzp.dylib",
"win32": "pzp.dll",
}.get(sys.platform, "libpzp.so")
_ROOT = Path(__file__).parent.resolve()
_PKG_DIR = _ROOT / "src" / "pzp"
_LIB_SRC = _ROOT / _LIB_NAME # built by make
_LIB_DST = _PKG_DIR / _LIB_NAME # inside the package (for wheels)
def _build_c_library():
"""Run make to produce libpzp.so in the repo root."""
print(f"[pzp] Building {_LIB_NAME} via Makefile …")
subprocess.run(
["make", _LIB_NAME],
cwd=str(_ROOT),
check=True,
)
def _copy_lib_into_package():
"""Copy the compiled library into src/pzp/ for wheel inclusion."""
if not _LIB_SRC.exists():
raise FileNotFoundError(
f"{_LIB_SRC} not found after make. "
"Ensure gcc and libzstd-dev are installed."
)
shutil.copy2(str(_LIB_SRC), str(_LIB_DST))
print(f"[pzp] Copied {_LIB_NAME} → {_LIB_DST}")
class BuildPy(build_py):
"""Compile libpzp.so then run the normal build_py step."""
def run(self):
_build_c_library()
_copy_lib_into_package()
super().run()
class Develop(develop):
"""
For editable installs (pip install -e .) compile the library in-place.
The .so stays at the repo root; _find_lib() in __init__.py will find it.
"""
def run(self):
_build_c_library()
super().run()
setup(
cmdclass={
"build_py": BuildPy,
"develop": Develop,
},
)