-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
52 lines (40 loc) · 1.47 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
import os
import pathlib
import shutil
import sys
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
class DubExtension(Extension):
def __init__(self, name):
# don't invoke the original build_ext for this special extension
super().__init__(name, [])
# self.source_dir = pathlib.Path(source_dir).resolve()
class DubBuildExt(build_ext):
def run(self):
print("Usage:")
for ext in self.extensions:
self.build_dub(ext)
super().run()
def build_dub(self, ext):
setup_folder = pathlib.Path(os.path.dirname(os.path.abspath(__file__)))
cwd = pathlib.Path().absolute()
extdir_real = setup_folder / ext.name
print(os.listdir(setup_folder))
extdir = pathlib.Path(self.get_ext_fullpath(ext.name))
extdir.parent.mkdir(parents=True, exist_ok=True)
os.chdir(extdir_real) # ext.source_dir)
major, minor = sys.version_info[:2]
assert minor <= 13, f"Unsupported Python version (max supported version is 3.13, you are on {major}.{minor})"
self.spawn(['dub', "build", "-c", f"python{major}{minor}" , "-b", "release"])
print(extdir)
os.chdir(str(cwd))
shutil.copyfile(extdir_real / "libpyprovision.so", extdir)
setup(
name='pyprovision',
version='0.0.1',
packages=['pyprovision'],
ext_modules=[DubExtension('pyprovision')],
cmdclass={
'build_ext': DubBuildExt,
}
)