forked from The-AI-Framework-and-Data-Tech-Lab-HK/MULLER
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
54 lines (42 loc) · 1.73 KB
/
setup.py
File metadata and controls
54 lines (42 loc) · 1.73 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
# SPDX-License-Identifier: MPL-2.0
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
# Copyright (c) 2026 Bingyu Liu
import logging
import os
import subprocess
from setuptools import setup
from setuptools.command.build_py import build_py
project_name = "muller"
this_directory = os.path.abspath(os.path.dirname(__file__))
def build_cpp_modules():
"""Function to build cpp modules."""
if os.getenv("BUILD_CPP", "true").lower() not in ("true", "1", "yes"):
logging.info("Skipping C++ build because BUILD_CPP environment variable is not set to true.")
return
build_script = os.path.join(this_directory, "muller/util/sparsehash/build_proj.sh")
if os.path.exists(build_script):
logging.info("Building custom_hash_map module...")
try:
subprocess.run([build_script, "-j", "8"], check=True)
logging.info("Successfully built custom_hash_map module")
except subprocess.CalledProcessError as e:
logging.error(f"Failed to build custom_hash_map module: {e}")
if e.returncode == 143:
logging.warning(
"Build terminated (possibly due to timeout). Continuing without custom_hash_map module.")
else:
logging.warning(f"Build failed with code {e.returncode}. Continuing without custom_hash_map module.")
class CustomBuildPy(build_py):
"""Custom build command that builds C++ modules before building Python package."""
def run(self):
build_cpp_modules()
super().run()
setup(
cmdclass={
'build_py': CustomBuildPy,
},
)