-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
94 lines (78 loc) · 2.82 KB
/
Copy pathsetup.py
File metadata and controls
94 lines (78 loc) · 2.82 KB
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
#!/usr/bin/env python2
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import sys
import os
import numpy
EXCLUDE_DIRS = ['.git', 'build'] # Directories to exclude when searching for cython files (.pyx)
CLEAN_EXTENSIONS = [".c", ".so"]
KEEP_FILES = ["gjkHPN.c"] # gjkHPN.c is needed to compile gjk.
########################################
def get_files():
for root, dirs, files in os.walk(os.getcwd(), topdown=True):
reduxPath = root.replace(os.getcwd(), '')
if not any(exclude_dir in reduxPath for exclude_dir in EXCLUDE_DIRS):
for f in files:
yield (f, root)
def convert(filename, path, i):
# this defines the path where the .so files end up
rootPath = path.replace(os.getcwd() + '/', '')
modulePath = rootPath.replace('/','.') + '.'
name = filename[:i]
setup(
cmdclass = {'build_ext': build_ext},
ext_modules=[
Extension(modulePath + name,
sources=[path + '/' + filename],
include_dirs = ['.', numpy.get_include()],
extra_compile_args=["-O3"])])
########################################
def build_all():
setup(
name = "gjk2",
ext_modules=[
Extension("PyR2.gjk2",
sources=["./PyR2/gjk2.pyx", "./PyR2/gjk/gjkHPN.c"],
include_dirs = ['.', numpy.get_include()],
language="c")],
cmdclass={"build_ext": build_ext})
setup(
name = "ik2",
ext_modules=[
Extension("PyR2.pr2.ik2",
sources=["./PyR2/pr2/pr2InvKin2.pyx",
"./PyR2/pr2/IK/ikfastApr18Left.cpp",
"./PyR2/pr2/IK/ikfastApr18Right.cpp"],
include_dirs = ['.', numpy.get_include()],
language="c++")],
cmdclass={"build_ext": build_ext})
for fname, path in get_files():
if any(name in fname for name in ("gjk_def2", "pr2InvKin2")):
continue
i = fname.find(".pyx")
if i != -1 and fname.find("~") == -1:
convert(fname, path, i)
########################################
def clear_all():
for fname, path in get_files():
if any(fname.endswith(ext) for ext in CLEAN_EXTENSIONS) and \
not any(keep in fname for keep in KEEP_FILES):
filePath = path + '/' + fname
os.remove(filePath)
print 'Cleaned', filePath
########################################
HELP = 'python setup.py [build | clean]'
def main():
if len(sys.argv) != 2:
print HELP
return
if sys.argv[1] == "build":
sys.argv = sys.argv[:1] + ['build_ext', '--inplace']
build_all()
elif sys.argv[1] == "clean":
clear_all()
else:
print HELP
if __name__ == '__main__':
main()