-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
70 lines (53 loc) · 2.21 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from setuptools import setup
import subprocess, sys, os, logging
from setuptools.command.build import build, SubCommand
from setuptools import Command
from glob import glob
import setuptools.command.install as orig_install
## Handling for klipper's building of the C helper and hubctl
custom_cmdclass = {}
class BuildCHelperSubCommand(build):
def run(self):
build_env = dict(os.environ)
build_env['OVERRIDE_CHELPER_OUTPUT'] = os.path.join(os.getcwd(),f"{self.build_lib}/klippy/chelper/c_helper.so")
build_env['OVERRIDE_HUBCTRL_OUTPUT'] = os.path.join(os.getcwd(),f"{self.build_lib}/klippy/chelper/hub-ctrl")
build_dir=os.path.join(os.getcwd(), self.build_lib)
subprocess.run([sys.executable, os.path.join(os.getcwd(),"compile.py")], cwd=build_dir, check=True, env=build_env)
def get_source_files(self):
source_list = []
source_list += glob("klippy/chelper/*.[ch]")
source_list += glob("hub-ctrl/*.[ch]")
source_list.append("compile.py")
return source_list
def get_outputs(self):
return [
f"{self.build_lib}/klippy/chelper/c_helper.so",
f"{self.build_lib}/klippy/chelper/hub-ctrl"
]
custom_cmdclass['build_klipper_chelper'] = BuildCHelperSubCommand
class BuildKlipperCommand(build):
def __init__(self,dist):
super().__init__(dist)
self.sub_commands.append(('build_klipper_chelper', None))
custom_cmdclass['build'] = BuildKlipperCommand
## Because the above doesn't trigger bdist_wheel to treat this as non pure-python
try:
from wheel.bdist_wheel import bdist_wheel
class ImpureBdistWheel(bdist_wheel):
description = "create an explicitly nonportable wheel"
def finalize_options(self):
super().finalize_options()
self.root_is_pure = False
custom_cmdclass['bdist_wheel'] = ImpureBdistWheel
except:
pass
## Similar case with install
class ImpureInstall(orig_install.install):
description = "Install, but always into platlib"
def finalize_options(self):
super().finalize_options()
self.install_lib = self.install_platlib
custom_cmdclass['install'] = ImpureInstall
setup(
cmdclass=custom_cmdclass
)