-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.py
More file actions
78 lines (65 loc) · 2.13 KB
/
Copy pathsetup.py
File metadata and controls
78 lines (65 loc) · 2.13 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
import os
import subprocess
import sys
import warnings
from setuptools import setup
from setuptools.command.build_py import build_py
from setuptools.command.develop import develop
TARGET_PKG_NAME = "npuslim"
OPS_DIR = os.path.join("src", TARGET_PKG_NAME, "ops")
def _build_custom_ops():
"""Discover and build all ops/*/build.py via subprocess."""
if os.environ.get("NPUSLIM_SKIP_OPS"):
print("\n--- Custom Operator Build ---")
print(" Skipped (NPUSLIM_SKIP_OPS is set)")
print("------------------------------\n")
return
if not os.path.isdir(OPS_DIR):
return
print("\n--- Custom Operator Build ---")
for entry in sorted(os.listdir(OPS_DIR)):
op_dir = os.path.abspath(os.path.join(OPS_DIR, entry))
build_file = os.path.join(op_dir, "build.py")
if not os.path.isfile(build_file):
continue
print(f" [{entry}] building ...")
try:
result = subprocess.run(
[sys.executable, build_file],
capture_output=True,
text=True,
)
if result.stdout:
print(result.stdout)
if result.returncode == 0:
print(f" [{entry}] OK")
else:
print(f" [{entry}] FAILED (exit {result.returncode})")
if result.stderr:
print(result.stderr)
except Exception as e:
warnings.warn(
f"[{entry}] build failed: {e}. "
"Other npuslim features remain usable.",
stacklevel=2,
)
print("------------------------------\n")
class NpuSlimBuildPy(build_py):
def run(self):
self.execute(_build_custom_ops, (), msg="Building custom operators...")
super().run()
class NpuSlimDevelop(develop):
def run(self):
self.execute(_build_custom_ops, (), msg="Building custom operators...")
super().run()
setup(
cmdclass={
"build_py": NpuSlimBuildPy,
"develop": NpuSlimDevelop,
},
package_data={
TARGET_PKG_NAME: [
"ops/**/*.so",
],
},
)