-
Notifications
You must be signed in to change notification settings - Fork 43
/
setup.py
247 lines (208 loc) · 10.6 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
import os
import re
import sys
import platform
import subprocess
import socket
import time
import shutil
import argparse
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
parser = argparse.ArgumentParser()
parser.add_argument('--debug', action='store_true')
parser.add_argument('--profile', action='store_true')
parser.add_argument('--no-kuafu', action='store_true')
args, unknown = parser.parse_known_args()
sys.argv = [sys.argv[0]] + unknown
class CMakeExtension(Extension):
def __init__(self, name, sourcedir='./'):
Extension.__init__(self, name, sources=[])
self.sourcedir = os.path.abspath(sourcedir)
class CMakeBuild(build_ext):
def run(self):
try:
out = subprocess.check_output(['cmake', '--version'])
except OSError:
raise RuntimeError("CMake must be installed to build the following extensions: " +
", ".join(e.name for e in self.extensions))
for ext in self.extensions:
self.build_extension(ext)
def build_extension(self, ext):
original_full_path = self.get_ext_fullpath(ext.name)
extdir = os.path.abspath(os.path.dirname(original_full_path))
extdir = os.path.join(extdir, self.distribution.get_name(), "core")
cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir, '-DPYTHON_EXECUTABLE=' + sys.executable]
if args.debug:
cfg = 'Debug'
else:
cfg = 'Release'
build_args = ['--config', cfg]
if args.profile:
cmake_args += ['-DSAPIEN_PROFILE=ON']
else:
cmake_args += ['-DSAPIEN_PROFILE=OFF']
if args.no_kuafu:
cmake_args += ['-DSAPIEN_KUAFU=OFF']
else:
cmake_args += ['-DSAPIEN_KUAFU=ON']
if os.environ.get("CUDA_PATH") is not None:
cmake_args += ['-DSAPIEN_CUDA=ON']
else:
cmake_args += ['-DSAPIEN_CUDA=OFF']
cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg]
build_args += ['--', '-j4']
env = os.environ.copy()
env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(env.get('CXXFLAGS', ''),
self.distribution.get_version())
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env)
subprocess.check_call(['cmake', '--build', '.', "--target", "pysapien"] + build_args, cwd=self.build_temp)
vulkan_shader_path = os.path.join(self.build_lib, 'sapien', 'vulkan_shader')
source_path = os.path.join(ext.sourcedir, 'vulkan_shader')
if os.path.exists(vulkan_shader_path):
shutil.rmtree(vulkan_shader_path)
assert os.path.exists(source_path)
shutil.copytree(source_path, vulkan_shader_path)
if not args.no_kuafu:
kuafu_shader_path = os.path.join(self.build_lib, 'sapien', 'kuafu_assets', 'shaders')
source_path = os.path.join(ext.sourcedir, '3rd_party/kuafu/resources/shaders')
if os.path.exists(kuafu_shader_path):
shutil.rmtree(kuafu_shader_path)
assert os.path.exists(source_path)
shutil.copytree(source_path, kuafu_shader_path)
sensor_assets_path = os.path.join(self.build_lib, 'sapien', 'sensor', 'assets')
source_patterns_path = os.path.join(ext.sourcedir, 'python', 'py_package', 'sensor', 'assets', 'patterns')
if os.path.exists(sensor_assets_path):
shutil.rmtree(sensor_assets_path)
os.makedirs(sensor_assets_path)
shutil.copytree(source_patterns_path, os.path.join(sensor_assets_path, 'patterns'))
include_path = os.path.join(self.build_lib, 'sapien', 'include')
source_include_path = os.path.join(ext.sourcedir, 'include')
if os.path.exists(include_path):
shutil.rmtree(include_path)
shutil.copytree(source_include_path, include_path)
include_path = os.path.join(self.build_lib, 'sapien', 'include', 'pybind11')
source_include_path = os.path.join(ext.sourcedir, '3rd_party', 'pybind11', 'include', 'pybind11')
if os.path.exists(include_path):
shutil.rmtree(include_path)
shutil.copytree(source_include_path, include_path)
include_path = os.path.join(self.build_lib, 'sapien', 'include', 'dlpack')
source_include_path = os.path.join(ext.sourcedir, '3rd_party', 'dlpack', 'include', 'dlpack')
if os.path.exists(include_path):
shutil.rmtree(include_path)
shutil.copytree(source_include_path, include_path)
include_path = os.path.join(self.build_lib, 'sapien', 'include', 'svulkan2')
source_include_path = os.path.join(ext.sourcedir, '3rd_party', 'sapien-vulkan-2', 'include', 'svulkan2')
if os.path.exists(include_path):
shutil.rmtree(include_path)
shutil.copytree(source_include_path, include_path)
if not args.no_kuafu:
include_path = os.path.join(self.build_lib, 'sapien', 'include', 'kuafu')
source_include_path = os.path.join(ext.sourcedir, '3rd_party', 'kuafu', 'include')
if os.path.exists(include_path):
shutil.rmtree(include_path)
shutil.copytree(source_include_path, include_path)
shutil.copy(os.path.join(ext.sourcedir, '3rd_party', 'tinyxml2', 'tinyxml2.h'),
os.path.join(self.build_lib, 'sapien', 'include', 'tinyxml2.h'))
include_path = os.path.join(self.build_lib, 'sapien', 'include', 'physx')
source_include_path = os.path.join(ext.sourcedir, '..', 'PhysX', 'physx', 'include')
if os.path.exists(include_path):
shutil.rmtree(include_path)
shutil.copytree(source_include_path, include_path)
include_path = os.path.join(self.build_lib, 'sapien', 'include', 'pxshared')
source_include_path = os.path.join(ext.sourcedir, '..', 'PhysX', 'pxshared', 'include')
if os.path.exists(include_path):
shutil.rmtree(include_path)
shutil.copytree(source_include_path, include_path)
include_path = os.path.join(self.build_lib, 'sapien', 'include', 'simsense')
source_include_path = os.path.join(ext.sourcedir, '3rd_party', 'simsense', 'include')
if os.path.exists(include_path):
shutil.rmtree(include_path)
shutil.copytree(source_include_path, include_path)
def copy_system_header(name):
system_include_path = ['/usr/local/include', '/usr/include']
for p in system_include_path:
source_include_path = os.path.join(p, name)
if os.path.isdir(p):
break
else:
raise ValueError(f'cannot find library {name}')
include_path = os.path.join(self.build_lib, 'sapien', 'include', 'spdlog')
if os.path.exists(include_path):
shutil.rmtree(include_path)
shutil.copytree(source_include_path, include_path)
copy_system_header('spdlog')
def check_version_info():
try:
git_revision = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("utf-8").split("\n")[0]
git_branch = subprocess.check_output(["git", "rev-parse", "--abbrev-ref",
"HEAD"]).decode("utf-8").split("\n")[0]
except (subprocess.CalledProcessError, OSError):
git_revision = ""
git_branch = "non-git"
build_datetime = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())
with open("python/VERSION") as f:
version_number = f.readline().strip()
hostname = socket.gethostname()
sys.stdout.write("====================Version Data====================\n"
"Git Revision Number: {}\n"
"Git Branch: {}\n"
"Build Datetime: {}\n"
"Version Number: {}\n"
"Host Name: {}\n"
"====================================================\n\n".format(git_revision, git_branch,
build_datetime, version_number,
hostname))
return git_revision, git_branch, build_datetime, version_number, hostname
# Read requirements.txt
def read_requirements():
with open('python/requirements.txt', 'r') as f:
lines = f.readlines()
install_requires = [line.strip() for line in lines if line]
return install_requires
# Data files for packaging
project_python_home_dir = os.path.join("python", "py_package")
package_data = {
"sapien.core": ["__init__.pyi", "pysapien/__init__.pyi", "pysapien/renderer/__init__.pyi", "pysapien/dlpack/__init__.pyi", "pysapien/coacd/__init__.pyi"]
}
setup(name="sapien",
version=check_version_info()[3],
author='Sapien',
python_requires='>=3.7',
author_email='[email protected]',
description=['SAPIEN: A SimulAted Parted based Interactive ENvironment'],
classifiers=[
"Operating System :: POSIX :: Linux",
"Intended Audience :: Developers",
"Intended Audience :: Education",
"Intended Audience :: Other Audience",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Framework :: Robot Framework :: Tool",
"Topic :: Games/Entertainment :: Simulation",
"Programming Language :: C++",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Topic :: Education",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Utilities",
],
license="MIT",
ext_modules=[CMakeExtension('sapien')],
install_requires=read_requirements(),
long_description=open("readme.md").read(),
long_description_content_type="text/markdown",
cmdclass=dict(build_ext=CMakeBuild),
zip_safe=False,
packages=["sapien", "sapien.core", "sapien.asset", "sapien.example", "sapien.utils", "sapien.sensor"],
keywords="robotics simulator dataset articulation partnet",
url="https://sapien.ucsd.edu",
project_urls={"Documentation": "https://sapien.ucsd.edu/docs"},
package_data=package_data,
package_dir={"sapien": project_python_home_dir},
scripts=["python/py_package/bin/coacd"])