generated from aarnphm/bazix
-
Notifications
You must be signed in to change notification settings - Fork 63
/
setup.py
53 lines (40 loc) · 1.41 KB
/
setup.py
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
from os import path
from pathlib import Path
from subprocess import check_output
from setuptools import setup
from setuptools.dist import Distribution
from wheel.bdist_wheel import bdist_wheel
from setuptools.command.build_py import build_py
def update_submodules(directory: str):
check_output(["git", "init"])
check_output(["git", "submodule", "sync", "--recursive"], cwd=directory)
check_output(["git", "submodule", "update", "--init", "--recursive"], cwd=directory)
def compile_ext():
wd = path.dirname(path.abspath(__file__))
if not path.exists(path.join(wd, "src", "whispercpp", "api_cpp2py_export.so")):
update_submodules(wd)
print("Building pybind11 extension...")
bazel_script = Path(wd) / "tools" / "bazel"
check_output([bazel_script.__fspath__(), "run", "//:extensions"], cwd=wd)
class BdistWheel(bdist_wheel):
def run(self):
compile_ext()
print("Building wheel...")
bdist_wheel.run(self)
class BuildPy(build_py):
def run(self):
compile_ext()
print("Installing package...")
build_py.run(self)
class WhisperDistribution(Distribution):
def has_ext_modules(self):
return True
setup(
include_dirs=[
"./extern/whispercpp",
"./extern/pybind11/include",
"./src/whispercpp/",
],
cmdclass={"bdist_wheel": BdistWheel, "build_py": BuildPy},
distclass=WhisperDistribution,
)