-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhatch_build_libmseed.py
More file actions
74 lines (60 loc) · 2.85 KB
/
hatch_build_libmseed.py
File metadata and controls
74 lines (60 loc) · 2.85 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
import os
import sys
import shutil
import subprocess
from packaging.tags import sys_tags
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
class CustomBuildHook(BuildHookInterface):
here = os.path.abspath(os.path.dirname(__file__))
package_path = os.path.join(here, "src", "mseedlib")
libmseed_path = os.path.join(package_path, "libmseed")
def initialize(self, version, build_data):
# Set wheel tag, e.g. py3-none-macosx_14_0_x86_64
python_tag = f"py{sys.version_info.major}"
abi_tag = "none"
platform_tag = next(sys_tags()).platform
build_data["tag"] = f"{python_tag}-{abi_tag}-{platform_tag}"
build_data["pure_python"] = False
print(f"Building libmseed via Makefile in {self.libmseed_path}")
if sys.platform.lower().startswith("win"):
cmd = f"nmake /f Makefile.win dll"
else:
cmd = f"CFLAGS='-O3' make -j shared"
subprocess.check_call(cmd, cwd=self.libmseed_path, shell=True)
# Copy shared library to root package location
if os.path.exists(os.path.join(self.libmseed_path, "libmseed.so")):
shutil.copy(
os.path.join(self.libmseed_path, "libmseed.so"),
os.path.join(self.package_path),
)
elif os.path.exists(os.path.join(self.libmseed_path, "libmseed.dylib")):
shutil.copy(
os.path.join(self.libmseed_path, "libmseed.dylib"),
os.path.join(self.package_path),
)
elif os.path.exists(os.path.join(self.libmseed_path, "libmseed.dll")):
shutil.copy(
os.path.join(self.libmseed_path, "libmseed.dll"),
os.path.join(self.package_path),
)
# Copy libmseed.h to root package location
shutil.copy(
os.path.join(self.libmseed_path, "libmseed.h"),
os.path.join(self.package_path),
)
def clean(self, versions):
if sys.platform.lower().startswith("win"):
cmd = f"pushd {self.libmseed_path} && nmake /f Makefile.win clean & popd"
else:
cmd = f"make -C {self.libmseed_path} clean"
subprocess.check_call(cmd, shell=True)
if os.path.exists(os.path.join(self.package_path, "libmseed.so")):
os.remove(os.path.join(self.package_path, "libmseed.so"))
if os.path.exists(os.path.join(self.package_path, "libmseed.dylib")):
os.remove(os.path.join(self.package_path, "libmseed.dylib"))
if os.path.exists(os.path.join(self.package_path, "libmseed.dll")):
os.remove(os.path.join(self.package_path, "libmseed.dll"))
if os.path.exists(os.path.join(self.package_path, "libmseed.h")):
os.remove(os.path.join(self.package_path, "libmseed.h"))
def finalize(self, version, build_data, artifact_path):
pass