-
Notifications
You must be signed in to change notification settings - Fork 11
/
setup.py
executable file
·234 lines (195 loc) · 7.37 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
#!/usr/bin/python
try:
from setuptools import setup, Extension, convert_path
except ImportError:
from distutils.core import setup
from distutils.util import convert_path
from distutils.extension import Extension
import sys
import subprocess
from sysconfig import get_config_var
import os.path
import numpy
def has_header(path):
INCLUDE = get_config_var('INCLUDEDIR')
if INCLUDE is None:
return False
else:
return os.path.exists(os.path.join(INCLUDE, *path))
include_dirs = [numpy.get_include()]
cflags=[]
ldflags=[]
define_macros=[]
cmd_class = {}
cmd_options = {}
if sys.platform == 'win32':
cflags+=['-static-libgcc', '-static-libstdc++']
ldflags+=['-lpthread']
# Use safe indexing to force bounds and type checks in our numpy array
# acceses.
#define_macros += [("TREP_SAFE_INDEXING", None)]
# If this is a debug build and the valgrind headers are available,
# enable calls to start and stop callgrind instrumentation.
#define_macros += [("USE_CALLGRIND", None)]
################################################################################
# Version management
# Tries to create trep/__version__.py from git describe.
VERSION_PY = """
# This file was generated by setup.py
__version__ = '%s'
"""
def update_version_file():
try:
version_git = get_version_from_git()
version_file = get_version_from_file()
if version_git == version_file:
return
except (GitDescribeError, IOError):
pass
version = get_version()
f = open(convert_path("trep/__version__.py"), "wt")
f.write(VERSION_PY % version)
f.close()
return version
class GitDescribeError(StandardError): pass
def get_version_from_git():
try:
p = subprocess.Popen(["git", "describe", "--dirty", "--always"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
except EnvironmentError as e:
raise GitDescribeError(e)
stdout, stderr = p.communicate()
if p.returncode != 0:
raise GitDescribeError("git describe failed: '%s'" % stderr)
return stdout.strip()
def get_version_from_file():
glob = {'__builtins__' : __builtins__ }
execfile('trep/__version__.py', glob)
return glob['__version__']
def get_version():
try:
return get_version_from_git()
except GitDescribeError:
pass
try:
return get_version_from_file()
except IOError:
pass
return '<unknown>'
def get_approx_version():
# Removes the extra information from the version to just get the
# most recent tag and a '-dev' suffix if appropriate. This is to
# keep distutils from creating .eggs for every minor version
# during development.
version = get_version()
if '-' in version:
version = version[:version.index('-')] + '.dev'
return version
update_version_file()
################################################################################
# Sphinx support
# Try to add support to build the documentation if Sphinx is
# installed.
try:
from sphinx.setup_command import BuildDoc
cmd_class['build_sphinx'] = BuildDoc
# See docstring for BuildDoc on how to set default options here.
except ImportError:
print "Note: Sphinx must be installed to build documentation"
ext_modules = []
_trep = Extension('trep._trep',
include_dirs=include_dirs,
define_macros=define_macros,
extra_compile_args=cflags,
extra_link_args=ldflags,
sources = [
'trep/_trep/midpointvi.c',
'trep/_trep/system.c',
'trep/_trep/math-code.c',
'trep/_trep/frame.c',
'trep/_trep/_trep.c',
'trep/_trep/config.c',
'trep/_trep/potential.c',
'trep/_trep/force.c',
'trep/_trep/input.c',
'trep/_trep/constraint.c',
'trep/_trep/frametransform.c',
'trep/_trep/spline.c',
'trep/_trep/tapemeasure.c',
# Constraints
'trep/_trep/constraints/distance.c',
'trep/_trep/constraints/plane.c',
'trep/_trep/constraints/point.c',
# Potentials
'trep/_trep/potentials/gravity.c',
'trep/_trep/potentials/linearspring.c',
'trep/_trep/potentials/configspring.c',
'trep/_trep/potentials/nonlinear_config_spring.c',
# Forces
'trep/_trep/forces/damping.c',
'trep/_trep/forces/lineardamper.c',
'trep/_trep/forces/configforce.c',
'trep/_trep/forces/bodywrench.c',
'trep/_trep/forces/hybridwrench.c',
'trep/_trep/forces/spatialwrench.c',
'trep/_trep/forces/pistonexample.c',
],
depends=[
'trep/_trep/trep.h',
'trep/_trep/c_api.h'
])
ext_modules += [_trep]
# Check for OpenGL headers. If we can't find anything, just don't
# build _polyobject. There is a python implementation to fallback on.
if sys.platform == 'darwin':
opengl_link=['/System/Library/Frameworks/OpenGL.framework/OpenGL']
elif sys.platform == 'win32' and os.path.exists('C:\Windows\System32\opengl32.dll'):
opengl_link=['-lopengl32']
elif has_header(['GL', 'gl.h']):
opengl_link=['-lGL']
else:
opengl_link=None
if opengl_link is not None:
_polyobject = Extension('trep.visual._polyobject',
include_dirs=include_dirs,
extra_compile_args=[],
extra_link_args=opengl_link,
sources = ['trep/visual/_polyobject.c'])
ext_modules += [_polyobject]
setup (name = 'trep',
version = get_approx_version()[1:],
description = 'trep is used to simulate mechanical systems.',
long_description="Trep is a Python module for modeling articulated rigid body mechanical systems in \
generalized coordinates. Trep supports basic simulation but it is primarily designed to serve as a \
calculation engine for analysis and optimal control algorithms that require 1st and 2nd derivatives \
of the system's dynamics.",
author = 'Elliot Johnson',
author_email = '[email protected]',
url = 'http://murpheylab.github.io/trep/',
license='GPLv3',
platforms='Linux, Mac, Windows',
packages=['trep',
'trep.constraints',
'trep.potentials',
'trep.forces',
'trep.visual',
'trep.puppets',
'trep.discopt',
'trep.ros'
],
package_data={
'trep.visual' : ['icons/*.svg'], 'trep' : ['_trep/*.h']
},
ext_modules=ext_modules,
cmdclass=cmd_class,
command_options=cmd_options,
zip_safe=False,
install_requires=[
'numpy',
'scipy',
],
headers=[
'trep/_trep/trep.h',
'trep/_trep/c_api.h'
])