-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
63 lines (53 loc) · 1.9 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
import os
import pathlib
import setuptools
import setuptools.command.build_ext
class CMakeExtension(setuptools.Extension):
def __init__(self, name, sources=[]):
super().__init__(name=name, sources=sources)
class BuildCMakeExt(setuptools.command.build_ext.build_ext):
def run(self):
for extension in self.extensions:
if extension.name == 'PyCompiledNN':
self.build_cmake(extension)
super().run()
def build_cmake(self, extension: setuptools.Extension):
source_directory = pathlib.Path().absolute()
self.announce('Preparing the build environment', level=3)
build_temp = pathlib.Path(self.build_temp)
build_temp.mkdir(parents=True, exist_ok=True)
extension_path = pathlib.Path(self.get_ext_fullpath(extension.name))
extension_path.mkdir(parents=True, exist_ok=True)
self.announce('Configuring CMake project', level=3)
self.spawn(
[
'cmake',
f'-H{source_directory}',
f'-B{self.build_temp}',
f'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extension_path.parent.absolute()}',
f'-DCMAKE_BUILD_TYPE={"Debug" if self.debug else "Release"}',
]
)
if not self.dry_run:
self.announce('Building binaries', level=3)
self.spawn(
[
'cmake',
'--build',
self.build_temp,
]
)
setuptools.setup(
name='PyCompiledNN',
use_scm_version=True,
setup_requires=['setuptools_scm'],
packages=[],
description='Python Bindings for CompiledNN',
long_description=open('./README.md', 'r').read(),
long_description_content_type='text/markdown',
license='MIT',
ext_modules=[CMakeExtension(name='PyCompiledNN')],
cmdclass={
'build_ext': BuildCMakeExt,
},
)