-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathsetup.py
96 lines (80 loc) · 3.65 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import os
import shutil
from setuptools import find_packages, setup, Extension
from setuptools.command.build_ext import build_ext
class CMakeExtension(Extension):
def __init__(self, name, cmake_path):
self.cmake_path = cmake_path
super().__init__(name, sources=[])
class cmake_build_ext(build_ext):
def run(self):
self.build_cmake(self.extensions)
# super().run()
def build_cmake(self, exts):
# This code assumes 'gtsam' & 'gtsam_quadrics' extensions are specified
# in that order...
gtsam_ext = exts[0]
gtsam_quadrics_ext = exts[1]
gtsam_so = self.get_ext_filename(gtsam_ext.name)
gtsam_quadrics_so = self.get_ext_filename(gtsam_quadrics_ext.name)
# Build our CPython shared objects
source_dir = os.getcwd()
build_dir = self.build_temp
build_lib_dir = self.build_lib
self.spawn([
'cmake', '-DBUILD_SHARED_LIBS=OFF', '-UCMAKE_MAKE_PROGRAM',
'-DCMAKE_POSITION_INDEPENDENT_CODE=ON', '-G', 'Ninja', '-B',
build_dir, '-S', source_dir
])
self.spawn(['cmake', '--build', build_dir])
# Move shared objects to the build lib location
# TODO probably should just output them there from CMake... but eh
print("MAKING %s" % build_lib_dir)
os.makedirs(build_lib_dir, exist_ok=True)
print("MOVING %s -> %s" % (os.path.join(build_dir, 'gtsam', 'python',
'gtsam'), build_lib_dir))
shutil.rmtree(os.path.join(build_lib_dir, 'gtsam'), ignore_errors=True)
shutil.copytree(os.path.join(build_dir, 'gtsam', 'python', 'gtsam'),
os.path.join(build_lib_dir, 'gtsam'))
print("MOVING %s -> %s" %
(os.path.join(build_dir, gtsam_quadrics_so),
os.path.join(build_lib_dir, gtsam_quadrics_so)))
shutil.copy(os.path.join(build_dir, gtsam_quadrics_so),
os.path.join(build_lib_dir, gtsam_quadrics_so))
# Move shared objects to the shared source location
# TODO probably should be behind an '--inplace' flag or something...
print("MOVING %s -> %s" %
(os.path.join(build_lib_dir, "gtsam",
gtsam_so), os.path.join(source_dir, gtsam_so)))
shutil.copy(os.path.join(build_lib_dir, "gtsam", gtsam_so),
os.path.join(source_dir, gtsam_so))
print("MOVING %s -> %s" %
(os.path.join(build_lib_dir, gtsam_quadrics_so),
os.path.join(source_dir, gtsam_quadrics_so)))
shutil.copy(os.path.join(build_lib_dir, gtsam_quadrics_so),
os.path.join(source_dir, gtsam_quadrics_so))
with open("README.md", 'r') as f:
long_description = f.read()
setup(name='gtsam_quadrics',
version='0.3.0',
author='Lachlan Nicholson',
author_email='[email protected]',
maintainer='Ben Talbot',
maintainer_email='[email protected]',
url='https://github.com/best-of-acrv/gtsam_quadrics',
description='Quadrics for GTSAM',
long_description=long_description,
long_description_content_type='text/markdown',
packages=find_packages(),
install_requires=[],
ext_modules=[
CMakeExtension('gtsam', './gtsam/CMakeLists.txt'),
CMakeExtension('gtsam_quadrics', './CMakeLists.txt')
],
cmdclass={'build_ext': cmake_build_ext},
classifiers=(
"Development Status :: 4 - Beta",
"Programming Language :: Python :: 3",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
))