-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup.py
75 lines (64 loc) · 1.83 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
71
72
73
74
75
import os
import pathlib
import shutil
import subprocess
import zipfile
from setuptools import Extension, setup
from setuptools.command import build_ext
cpp_libraries = {
'eigen': (
'https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.zip'
),
'pcg_random': 'https://www.pcg-random.org/downloads/pcg-cpp-0.98.zip',
}
_THIRD_PARTY = '_third_party_'
class BuildExtCommand(build_ext.build_ext):
def initialize_options(self):
if not os.path.exists(_THIRD_PARTY):
os.mkdir(_THIRD_PARTY)
for library, url in cpp_libraries.items():
subprocess.check_call(
f'wget -O {_THIRD_PARTY}/{library}.zip {url}'.split()
)
with zipfile.ZipFile(f'{_THIRD_PARTY}/{library}.zip', 'r') as f:
f.extractall(_THIRD_PARTY)
super().initialize_options()
def finalize_options(self):
from pybind11.setup_helpers import Pybind11Extension
self.distribution.ext_modules[:] = [
Pybind11Extension(
'hybrid_rcc',
[str(fname) for fname in pathlib.Path('src').rglob('*.cc')],
include_dirs=[
'src',
f'{_THIRD_PARTY}/eigen-3.4.0',
f'{_THIRD_PARTY}/pcg-cpp-0.98',
],
extra_compile_args=['-O3'],
)
]
super().finalize_options()
def build_extensions(self):
super().build_extensions()
shutil.rmtree(_THIRD_PARTY)
setup(
name='hybrid_rcc',
version=0.1,
author='Noureldin Yosri',
ext_modules=[Extension('', [])],
data_files=[('hybrid_rcc', ['src/py/hybrid_rcc.pyi'])],
include_package_data=True,
cmdclass={
'build_ext': BuildExtCommand,
},
setup_requires=[
'numpy',
'pybind11',
'setuptools-git',
],
install_requires=[
'numpy',
'scipy',
'setuptools-git',
],
)