-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
306 lines (263 loc) · 10.9 KB
/
setup.py
File metadata and controls
306 lines (263 loc) · 10.9 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
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# setup script for python-pninexus
from __future__ import print_function
import codecs
import sys
import os
import os.path
import numpy
import shutil
from setuptools import setup
from distutils.command.install import install
import sysconfig
from build_tools import (CppExtensionFactory,
ConanBuildInfoBuilder,
BuildConfiguration)
try:
from sphinx.setup_command import BuildDoc
except ImportError:
print('WARNING: sphinx is not available, not building docs')
BuildDoc = None
name = "pninexus"
version = "3.3.0"
# release = "3.3.0"
# documentation for release with one '.' is stored as v:latest
release = "3.3"
if release.count(".") == 1:
docs_release = '(latest)'
else:
docs_release = release
def read(fname):
""" read the file
:param fname: readme file name
:type fname: :obj:`str`
"""
with codecs.open(os.path.join('.', fname), encoding='utf-8') as f:
long_description = f.read()
return long_description
# -----------------------------------------------------------------------------
# set include directories, linker path and libraries
# we have two possibilities to configure the build:
# -> via pkg-config using locally installed libraries
# -> via Conan
# if a conanbuildinfo.txt file exists in the root directory of the package the
# conan variant will be used automatically.
# -----------------------------------------------------------------------------
h5cpp_extra_link_args = []
nexus_extra_link_args = []
if os.path.exists("conanbuildinfo.txt"):
builder = ConanBuildInfoBuilder()
nexus_config = builder.create("conanbuildinfo.txt")
nexus_config.add_linker_argument("-Wl,-rpath,'$ORIGIN'/../../libs")
print("linking with libraries:")
for lib in nexus_config.link_libraries:
print(lib)
else:
nexus_config = BuildConfiguration()
nexus_config.add_link_library('pninexus')
nexus_config.add_link_library('h5cpp')
nexus_config.add_link_library(
"boost_python{major}{minor}".format(major=sys.version_info.major,
minor=sys.version_info.minor))
nexus_config.add_include_directory('/usr/include/hdf5/serial')
hdf5_hl_path = os.environ.get('HDF5_HL_LOCAL_PATH')
if hdf5_hl_path:
# use when h5cpp compiled with --as-needed
nexus_config.add_link_library('hdf5_hl')
nexus_config.add_library_directory(
# '/usr/lib/x86_64-linux-gnu/hdf5/serial/'
hdf5_hl_path
)
h5cpp_path = os.environ.get('H5CPP_LOCAL_PATH')
if h5cpp_path:
# use when h5cpp locally installed
nexus_config.add_include_directory("%s/include" % h5cpp_path)
nexus_config.add_library_directory("%s/lib" % h5cpp_path)
nexus_config.add_linker_argument("-Wl,-rpath,/%s/lib" % h5cpp_path)
pninexus_path = os.environ.get('PNINEXUS_LOCAL_PATH')
if pninexus_path:
# use when libpnineuxs locally installed
nexus_config.add_include_directory("%s/include" % pninexus_path)
nexus_config.add_library_directory("%s/lib" % pninexus_path)
nexus_config.add_linker_argument("-Wl,-rpath,%s/lib" % pninexus_path)
packages = ['pninexus',
'pninexus.h5cpp',
'pninexus.h5cpp.attribute',
'pninexus.h5cpp.dataspace',
'pninexus.h5cpp.datatype',
'pninexus.h5cpp.file',
'pninexus.h5cpp.filter',
'pninexus.h5cpp.node',
'pninexus.h5cpp.property',
'pninexus.nexus']
package_data = {}
def add_filters(filters, pkgs, pkgs_data):
added = False
dst = "src/pninexus/filters"
filter_path = os.environ.get('HDF5_PLUGIN_PATH')
for flt in filters:
if os.path.exists(flt):
if 'pninexus.filters' not in pkgs_data:
pkgs_data['pninexus.filters'] = []
pkgs_data['pninexus.filters'].append(os.path.split(flt)[-1])
shutil.copy(flt, dst)
added = True
elif filter_path and os.path.exists(os.path.join(filter_path, flt)):
if 'pninexus.filters' not in pkgs_data:
pkgs_data['pninexus.filters'] = []
pkgs_data['pninexus.filters'].append(os.path.split(flt)[-1])
shutil.copy(os.path.join(filter_path, flt), dst)
added = True
else:
raise Exception("Filter %s cannot be found" % flt)
print("Copy %s to pninexus/filters" % flt)
if added:
pkgs.append('pninexus.filters')
return added
pninexus_filters = os.environ.get('PNINEXUS_FILTERS')
if pninexus_filters:
add_filters(pninexus_filters.split(','),
packages, package_data)
#
# adding include directories from numpy
#
nexus_config.add_include_directories([numpy.get_include()])
# ----------------------------------------------------------------------------
# set compiler options
# ----------------------------------------------------------------------------
if sys.platform == "win32":
pass
else:
# old version
# arguments = ['-std=c++17', '-Wall', '-Wextra',
# '-fdiagnostics-show-option']
# lto does not work
# arguments = ['-std=c++17', '-Wall', '-Wextra',
# '-fdiagnostics-show-option', '-flto=auto', '-ffat-lto-objects']
# no-lto to be on the save side
arguments = ['-std=c++17', '-Wall', '-Wextra', '-fdiagnostics-show-option',
'-fno-lto']
nexus_config.add_compiler_arguments(arguments)
# ----------------------------------------------------------------------------
# creating the extension factories
# ----------------------------------------------------------------------------
nexus_extension_factory = CppExtensionFactory(config=nexus_config)
# -----------------------------------------------------------------------------
# setup for the h5cpp and nexus extensions
# -----------------------------------------------------------------------------
h5cpp_common_sources = ['src/cpp/h5cpp/common/converters.cpp',
'src/cpp/h5cpp/numpy/dimensions.cpp',
'src/cpp/h5cpp/numpy/array_factory.cpp',
'src/cpp/h5cpp/numpy/array_adapter.cpp']
h5cpp_core_ext = nexus_extension_factory.create(
module_name="pninexus.h5cpp._h5cpp",
source_files=['src/cpp/h5cpp/_h5cpp.cpp',
'src/cpp/h5cpp/boost_filesystem_path_conversion.cpp',
'src/cpp/h5cpp/dimensions_conversion.cpp',
'src/cpp/h5cpp/errors.cpp'])
h5cpp_attribute_ext = nexus_extension_factory.create(
module_name='pninexus.h5cpp._attribute',
source_files=['src/cpp/h5cpp/attribute/attribute.cpp'] +
h5cpp_common_sources)
h5cpp_file_ext = nexus_extension_factory.create(
module_name='pninexus.h5cpp._file',
source_files=['src/cpp/h5cpp/file/file.cpp'] +
h5cpp_common_sources)
h5cpp_dataspace_ext = nexus_extension_factory.create(
module_name='pninexus.h5cpp._dataspace',
source_files=['src/cpp/h5cpp/dataspace/dataspace.cpp',
'src/cpp/h5cpp/dataspace/selections.cpp'])
h5cpp_datatype_ext = nexus_extension_factory.create(
module_name='pninexus.h5cpp._datatype',
source_files=['src/cpp/h5cpp/datatype/datatype.cpp'])
h5cpp_filter_ext = nexus_extension_factory.create(
module_name='pninexus.h5cpp._filter',
source_files=['src/cpp/h5cpp/filter/filter.cpp'])
h5cpp_property_ext = nexus_extension_factory.create(
module_name='pninexus.h5cpp._property',
source_files=['src/cpp/h5cpp/property/property.cpp',
'src/cpp/h5cpp/property/enumeration_wrappers.cpp',
'src/cpp/h5cpp/property/class_wrappers.cpp',
'src/cpp/h5cpp/property/copy_flag_wrapper.cpp',
'src/cpp/h5cpp/property/chunk_cache_parameters.cpp',
'src/cpp/h5cpp/property/creation_order.cpp'])
h5cpp_node_ext = nexus_extension_factory.create(
module_name='pninexus.h5cpp._node',
source_files=['src/cpp/h5cpp/node/nodes.cpp',
'src/cpp/h5cpp/node/dataset.cpp',
'src/cpp/h5cpp/node/functions.cpp'] + h5cpp_common_sources)
nexus_extension = nexus_extension_factory.create(
module_name='pninexus.nexus._nexus',
source_files=['src/cpp/nexus/nexus.cpp',
'src/cpp/nexus/factories.cpp',
'src/cpp/nexus/predicates.cpp',
'src/cpp/nexus/list_converters.cpp',
'src/cpp/nexus/path.cpp',
'src/cpp/nexus/element_dict_converter.cpp'])
# ----------------------------------------------------------------------------
# customized version of the `install` command. The original version shipped
# with distutils does not install header files even if they are mentioned
# in the project setup.
#
# We thus call `install_headers` manually.
# ----------------------------------------------------------------------------
class pni_install(install):
def run(self):
install.run(self)
# ----------------------------------------------------------------------------
# setup for the pnicore package
# ----------------------------------------------------------------------------
setup(
name="pninexus",
author="Eugen Wintersberger",
author_email="eugen.wintersberger@desy.de",
description="Python wrapper for the H5CPP and PNI libraries",
long_description=read('README.rst'),
maintainer="Eugen Wintersberger, Jan Kotanski",
maintainer_email="jan.kotanski@desy.de",
license="GPLv2",
version=release,
install_requires=["numpy"],
ext_modules=[
h5cpp_core_ext,
h5cpp_attribute_ext,
h5cpp_file_ext,
h5cpp_dataspace_ext,
h5cpp_datatype_ext,
h5cpp_property_ext,
h5cpp_filter_ext,
h5cpp_node_ext,
nexus_extension,
],
package_dir={'': 'src'},
packages=packages,
package_data=package_data,
url="https://github.com/pni-libraries/python-pninexus",
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Science/Research',
'Topic :: Scientific/Engineering :: Physics',
'Topic :: Software Development :: Libraries :: Python Modules',
'License :: OSI Approved :: GNU General Public License v2 (GPLv2)',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
],
test_suite="test",
test_loader="unittest:TestLoader",
cmdclass={
"install": pni_install,
'build_sphinx': BuildDoc,
},
keywords='h5cpp hdf5 python photon science detector',
command_options={
'build_sphinx': {
'project': ('setup.py', name),
'version': ('setup.py', version),
'release': ('setup.py', docs_release)
}
}
)