-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
165 lines (137 loc) · 5.67 KB
/
setup.py
File metadata and controls
165 lines (137 loc) · 5.67 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
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
#!/usr/bin/env python3
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from distutils.sysconfig import get_config_vars
from distutils.command.clean import clean
from Cython.Build import cythonize
import numpy
import glob
import cdff_dev
import build_tools
from cdff_dev.path import load_cdffpath, CTYPESDIR
def strict_prototypes_workaround():
# Workaround to remove '-Wstrict-prototypes' from compiler invocation
opt = get_config_vars('OPT')[0]
os.environ['OPT'] = " ".join(flag for flag in opt.split()
if flag != '-Wstrict-prototypes')
# Custom clean command to remove build artifacts
class CleanCommand(clean):
description = "Remove build artifacts from the source tree"
def run(self):
clean.run(self)
print("removing Cython build artifacts")
cwd = os.path.abspath(os.path.dirname(__file__))
dirs = [cwd, os.path.join(cwd, "cdff_dev", "extensions", "*"),
os.path.join(cwd, "cdff_dev", "dfpcs"),
#os.path.join(cwd, "cdff_dev", "dfns")
]
for path in dirs:
filenames = (glob.glob(os.path.join(path, "*.cpp")) +
glob.glob(os.path.join(path, "*.so")) +
glob.glob(os.path.join(path, "*.pyd")))
for filename in filenames:
print(filename)
os.remove(filename)
def configuration(parent_package='', top_path=None):
if os.path.exists('MANIFEST'):
os.remove('MANIFEST')
from numpy.distutils.misc_util import Configuration
config = Configuration(None, parent_package, top_path)
# Avoid non-useful msg:
# "Ignoring attempt to set 'name' (from ... "
config.set_options(ignore_setup_xxx_py=True,
assume_default_configuration=True,
delegate_options_to_subpackages=True,
quiet=True)
config.add_subpackage("cdff_dev")
autoproj_available = build_tools.check_autoproj()
cdff_types_files = ["_cdff_types.pxd", "cdff_types.pxd", "cdff_types.pyx"]
cdff_envire_files = ["_cdff_envire.pxd", "cdff_envire.pxd",
"cdff_envire.pyx"]
cython_files = cdff_types_files
if autoproj_available:
cython_files += cdff_envire_files
cython_files = [(".", filename) for filename in cython_files]
config.add_data_files(*cython_files)
# uncomment to see more outputs from the linker
#os.environ["CFLAGS"] = "-Xlinker -v"
cdffpath = load_cdffpath()
typespath = os.path.join(cdffpath, "Common")
make_cdff_types(config, cdffpath, typespath)
if autoproj_available:
make_cdff_envire(config, typespath)
config.ext_modules = cythonize(config.ext_modules)
return config
def make_cdff_types(config, cdffpath, typespath):
config.add_extension(
"cdff_types",
sources=["cdff_types.pyx"],
include_dirs=[
".",
"cpp_helpers",
numpy.get_include(),
typespath,
os.path.join(cdffpath, "Common/Types/CPP")
],
library_dirs=[
os.path.join(cdffpath, "build", "Common", "Types"),
os.path.join(cdffpath, "build", "Common", "Loggers")
],
libraries=["cdff_logger", "cdff_types"],
define_macros=[("NDEBUG",)],
extra_compile_args=build_tools.extra_compile_args
)
def make_cdff_envire(config, typespath):
autoproj_current_root = os.environ.get("AUTOPROJ_CURRENT_ROOT", None)
install_dir = os.path.join(autoproj_current_root, "install")
# this path is currently only used in CI image:
eigen_include_dir = "/usr/local/include/eigen3"
if not os.path.exists(eigen_include_dir):
eigen_include_dir = os.path.join(install_dir, "include", "eigen3")
print("using Eigen 3 from autoproj installation")
if not os.path.exists(eigen_include_dir):
eigen_include_dir = "/usr/include/eigen3/"
print("using Eigen 3 from system path")
config.add_extension(
"cdff_envire",
sources=["cdff_envire.pyx"],
include_dirs=[
".",
"cpp_helpers",
numpy.get_include(),
os.path.join(install_dir, "include"),
eigen_include_dir,
typespath
] + build_tools.DEFAULT_INCLUDE_DIRS,
library_dirs=[
os.path.join(install_dir, "lib")
] + build_tools.DEFAULT_LIBRARY_DIRS,
libraries=["cdff_types", "base-types", "envire_core", "envire_urdf",
"urdfdom_model", "envire_visualizer_interface"],
define_macros=[("NDEBUG",)],
extra_compile_args=build_tools.extra_compile_args
)
if __name__ == "__main__":
from numpy.distutils.core import setup
strict_prototypes_workaround()
metadata = dict(
name="cdff_dev",
version=cdff_dev.__version__,
description=cdff_dev.__description__,
long_description=open("README.md").read(),
scripts=[os.path.join("bin", "dfn_template_generator"),
os.path.join("bin", "dfpc_template_generator"),
os.path.join("bin", "cdff_dev_loginfo"),
os.path.join("bin", "cdff_dev_logshow"),
os.path.join("bin", "cdff_dev_chunk"),
os.path.join("bin", "cdff_dev_build_log_index"),
os.path.join("bin", "pyspace_export"),
os.path.join("bin", "dfpc_diagram")],
packages=['cdff_dev'],
package_data={'cdff_dev': ['templates/*.template']},
requires=['pyyaml', 'cython', 'Jinja2', 'numpy', 'pydot'],
cmdclass = {'clean': CleanCommand},
configuration=configuration
)
setup(**metadata)