-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
199 lines (163 loc) · 6.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
from distutils.core import setup
from distutils.extension import Extension
from distutils.cmd import Command
import sys, os
import os.path as op
from functools import reduce
try:
import Cython.Compiler.Version
s = Cython.Compiler.Version.version
if '-' in s:
s = s[:s.find('-')]
vers = tuple(int(x.rstrip('+')) for x in s.split('.'))
if vers < (0,13):
raise ImportError
from Cython.Distutils import build_ext
SUFFIX = '.pyx'
except ImportError:
from distutils.command.build_ext import build_ext
SUFFIX = '.c'
import numpy
import configure
VERSION = '2.1.2'
def localpath(*args):
return op.abspath(reduce(op.join, (op.dirname(__file__),)+args))
if sys.version_info[0] >= 3:
# Shamelessly stolen from Cython 0.14
import lib2to3.refactor
from distutils.command.build_py \
import build_py_2to3 as build_py
else:
from distutils.command.build_py import build_py
# --- Determine HDF5 location -------------------------------------------------
settings = configure.scrape_eargs() # lowest priority
settings.update(configure.scrape_cargs()) # highest priority
HDF5 = settings.get('hdf5')
# --- Create extensions -------------------------------------------------------
if sys.platform.startswith('win'):
COMPILER_SETTINGS = {
'libraries' : ['hdf5dll18','hdf5_hldll'],
'include_dirs' : [numpy.get_include(), localpath('lzf'),
localpath('win_include')],
'library_dirs' : [],
'define_macros' : [('H5_USE_16_API', None), ('_HDF5USEDLL_', None)]
}
if HDF5 is not None:
COMPILER_SETTINGS['include_dirs'] += [op.join(HDF5, 'include')]
COMPILER_SETTINGS['library_dirs'] += [op.join(HDF5, 'dll')]
else:
COMPILER_SETTINGS = {
'libraries' : ['hdf5', 'hdf5_hl'],
'include_dirs' : [numpy.get_include(), localpath('lzf')],
'library_dirs' : [],
'define_macros' : [('H5_USE_16_API', None)]
}
if HDF5 is not None:
COMPILER_SETTINGS['include_dirs'] += [op.join(HDF5, 'include')]
COMPILER_SETTINGS['library_dirs'] += [op.join(HDF5, 'lib')]
elif sys.platform == 'darwin':
COMPILER_SETTINGS['include_dirs'] += ['/opt/local/include']
COMPILER_SETTINGS['library_dirs'] += ['/opt/local/lib']
COMPILER_SETTINGS['runtime_library_dirs'] = [op.abspath(x) for x in COMPILER_SETTINGS['library_dirs']]
MODULES = ['defs','_errors','_objects','_proxy', 'h5fd', 'h5z',
'h5','h5i','h5r','utils',
'_conv', 'h5t','h5s',
'h5p',
'h5d', 'h5a', 'h5f', 'h5g',
'h5l', 'h5o',
'h5ds']
EXTRA_SRC = {'h5z': [ localpath("lzf/lzf_filter.c"),
localpath("lzf/lzf/lzf_c.c"),
localpath("lzf/lzf/lzf_d.c")]}
def make_extension(module):
sources = [op.join('h5py', module+SUFFIX)] + EXTRA_SRC.get(module, [])
return Extension('h5py.'+module, sources, **COMPILER_SETTINGS)
EXTENSIONS = [make_extension(m) for m in MODULES]
# --- Custom distutils commands -----------------------------------------------
class test(Command):
"""Run the test suite."""
description = "Run the test suite"
user_options = [('verbosity=', 'V', 'set test report verbosity')]
def initialize_options(self):
self.verbosity = 0
def finalize_options(self):
try:
self.verbosity = int(self.verbosity)
except ValueError:
raise ValueError('verbosity must be an integer.')
def run(self):
import sys
py_version = sys.version_info[:2]
if py_version == (2,7) or py_version >= (3,2):
import unittest
else:
try:
import unittest2 as unittest
except ImportError:
raise ImportError(
"unittest2 is required to run tests with python-%d.%d"
% py_version
)
buildobj = self.distribution.get_command_obj('build')
buildobj.run()
oldpath = sys.path
try:
sys.path = [op.abspath(buildobj.build_lib)] + oldpath
suite = unittest.TestLoader().discover(op.join(buildobj.build_lib,'h5py'))
result = unittest.TextTestRunner(verbosity=self.verbosity+1).run(suite)
if not result.wasSuccessful():
sys.exit(1)
finally:
sys.path = oldpath
# --- Distutils setup and metadata --------------------------------------------
cls_txt = \
"""
Development Status :: 5 - Production/Stable
Intended Audience :: Developers
Intended Audience :: Information Technology
Intended Audience :: Science/Research
License :: OSI Approved :: BSD License
Programming Language :: Python
Topic :: Scientific/Engineering
Topic :: Database
Topic :: Software Development :: Libraries :: Python Modules
Operating System :: Unix
Operating System :: POSIX :: Linux
Operating System :: MacOS :: MacOS X
Operating System :: Microsoft :: Windows
"""
short_desc = "Read and write HDF5 files from Python"
long_desc = \
"""
The h5py package provides both a high- and low-level interface to the HDF5
library from Python. The low-level interface is intended to be a complete
wrapping of the HDF5 API, while the high-level component supports access to
HDF5 files, datasets and groups using established Python and NumPy concepts.
A strong emphasis on automatic conversion between Python (Numpy) datatypes and
data structures and their HDF5 equivalents vastly simplifies the process of
reading and writing data from Python.
Supports HDF5 versions 1.8.3 and higher. On Windows, HDF5 is included with
the installer.
"""
if os.name == 'nt':
package_data = {'h5py': ['*.pyx', '*.dll']}
else:
package_data = {'h5py': ['*.pyx']}
setup(
name = 'h5py',
version = VERSION,
description = short_desc,
long_description = long_desc,
classifiers = [x for x in cls_txt.split("\n") if x],
author = 'Andrew Collette',
author_email = 'andrew dot collette at gmail dot com',
maintainer = 'Andrew Collette',
maintainer_email = 'andrew dot collette at gmail dot com',
url = 'http://www.h5py.org',
download_url = 'http://code.google.com/p/h5py/downloads/list',
packages = ['h5py', 'h5py._hl', 'h5py._hl.tests', 'h5py.lowtest'],
package_data = package_data,
ext_modules = EXTENSIONS,
requires = ['numpy (>=1.0.1)'],
cmdclass = {'build_ext': build_ext, 'test': test, 'build_py':build_py}
)