forked from ContinuumIO/blz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
230 lines (196 loc) · 7.27 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
########################################################################
#
# License: BSD
# Created: August 16, 2012
# Author: Francesc Alted - francesc@continuum.io
#
########################################################################
from __future__ import absolute_import
import sys, os
import glob
from distutils.core import Extension
from distutils.core import setup
import textwrap
########### Some utils for version checking ################
# Some functions for showing errors and warnings.
def _print_admonition(kind, head, body):
tw = textwrap.TextWrapper(
initial_indent=' ', subsequent_indent=' ')
print(".. %s:: %s" % (kind.upper(), head))
for line in tw.wrap(body):
print(line)
def exit_with_error(head, body=''):
_print_admonition('error', head, body)
sys.exit(1)
def print_warning(head, body=''):
_print_admonition('warning', head, body)
def check_import(pkgname, pkgver):
try:
mod = __import__(pkgname)
except ImportError:
exit_with_error(
"You need %(pkgname)s %(pkgver)s or greater to run blz!"
% {'pkgname': pkgname, 'pkgver': pkgver} )
else:
if mod.__version__ < pkgver:
exit_with_error(
"You need %(pkgname)s %(pkgver)s or greater to run blz!"
% {'pkgname': pkgname, 'pkgver': pkgver} )
print ( "* Found %(pkgname)s %(pkgver)s package installed."
% {'pkgname': pkgname, 'pkgver': mod.__version__} )
globals()[pkgname] = mod
########### Check versions ##########
# The minimum version of Cython required for generating extensions
min_cython_version = '0.19'
# The minimum version of NumPy required
min_numpy_version = '1.7'
# The minimum version of Numexpr (optional)
min_numexpr_version = '2.2'
# Check for Python
if sys.version_info[0] == 2:
if sys.version_info[1] < 6:
exit_with_error("You need Python 2.6 or greater to run blz!")
if sys.version_info[1] < 7:
try:
import unittest2
except ImportError:
exit_with_error(
"You need unittest2 for running blz tests with Python 2.6!")
elif sys.version_info[0] == 3:
if sys.version_info[1] < 1:
exit_with_error("You need Python 3.3 or greater to run blz!")
else:
exit_with_error("You need Python 2.6/3.3 or greater to run blz!")
# Check if Cython is installed or not (requisite)
try:
from Cython.Distutils import build_ext
from Cython.Compiler.Main import Version
except:
exit_with_error(
"You need %(pkgname)s %(pkgver)s or greater to compile blz!"
% {'pkgname': 'Cython', 'pkgver': min_cython_version} )
if Version.version < min_cython_version:
exit_with_error(
"At least Cython %s is needed so as to generate extensions!"
% (min_cython_version) )
else:
print ( "* Found %(pkgname)s %(pkgver)s package installed."
% {'pkgname': 'Cython', 'pkgver': Version.version} )
# Check for NumPy
check_import('numpy', min_numpy_version)
# Check for Numexpr
numexpr_here = False
try:
import numexpr
except ImportError:
print_warning(
"Numexpr is not installed. For faster blz operation, "
"please consider installing it.")
else:
if numexpr.__version__ >= min_numexpr_version:
numexpr_here = True
print ( "* Found %(pkgname)s %(pkgver)s package installed."
% {'pkgname': 'numexpr', 'pkgver': numexpr.__version__} )
else:
print_warning(
"Numexpr %s installed, but version is not >= %s. "
"Disabling support for it." % (
numexpr.__version__, min_numexpr_version))
########### End of checks ##########
# blz version
VERSION = open('VERSION').read().strip()
# Create the version.py file
open('blz/version.py', 'w').write('__version__ = "%s"\n' % VERSION)
# Global variables
CFLAGS = os.environ.get('CFLAGS', '').split()
LFLAGS = os.environ.get('LFLAGS', '').split()
# Allow setting the Blosc dir if installed in the system
BLOSC_DIR = os.environ.get('BLOSC_DIR', '')
# Sources & libraries
inc_dirs = []
lib_dirs = []
libs = []
def_macros = []
sources = ["blz/blz_ext.pyx"]
# Include NumPy header dirs
from numpy.distutils.misc_util import get_numpy_include_dirs
inc_dirs += get_numpy_include_dirs()
optional_libs = []
# Handle --blosc=[PATH] --lflags=[FLAGS] --cflags=[FLAGS]
args = sys.argv[:]
for arg in args:
if arg.find('--blosc=') == 0:
BLOSC_DIR = os.path.expanduser(arg.split('=')[1])
sys.argv.remove(arg)
if arg.find('--lflags=') == 0:
LFLAGS = arg.split('=')[1].split()
sys.argv.remove(arg)
if arg.find('--cflags=') == 0:
CFLAGS = arg.split('=')[1].split()
sys.argv.remove(arg)
if not BLOSC_DIR:
# Compiling everything from sources
# Blosc + BloscLZ sources
sources += glob.glob('c-blosc/blosc/*.c')
# LZ4 sources
sources += glob.glob('c-blosc/internal-complibs/lz4*/*.c')
# Snappy sources
sources += glob.glob('c-blosc/internal-complibs/snappy*/*.cc')
# Zlib sources
sources += glob.glob('c-blosc/internal-complibs/zlib*/*.c')
# Finally, add all the include dirs...
inc_dirs += [os.path.join('c-blosc', 'blosc')]
inc_dirs += glob.glob('c-blosc/internal-complibs/*')
# ...and the macros for all the compressors supported
def_macros += [('HAVE_LZ4', 1), ('HAVE_SNAPPY', 1), ('HAVE_ZLIB', 1)]
else:
inc_dirs += [os.path.join(BLOSC_DIR, 'include')]
lib_dirs += [os.path.join(BLOSC_DIR, 'lib')]
libs += ['blosc']
# Add -msse2 flag for optimizing shuffle in include Blosc
if os.name == 'posix':
CFLAGS.append("-msse2")
classifiers = """\
Development Status :: 4 - Beta
Intended Audience :: Developers
Intended Audience :: Information Technology
Intended Audience :: Science/Research
License :: OSI Approved :: BSD License
Programming Language :: Python
Topic :: Software Development :: Libraries :: Python Modules
Operating System :: Microsoft :: Windows
Operating System :: Unix
"""
setup(name = "blz",
version = VERSION,
description = 'blz: a compressed data container',
long_description = """\
BLZ is a chunked container for numerical data. Chunking allows for
efficient enlarging/shrinking of data container. In addition, it can
also be compressed for reducing memory/disk needs. The compression
process is carried out internally by Blosc, a high-performance
compressor that is optimized for binary data.
""",
classifiers = filter(None, classifiers.split("\n")),
author = 'Francesc Alted, Mark Wiebe, Oscar Villellas',
author_email = 'francesc@continuum.io',
maintainer = 'Francesc Alted',
maintainer_email = 'francesc@continuum.io',
url = 'https://github.com/ContinuumIO/blz',
license = 'http://www.opensource.org/licenses/bsd-license.php',
# It is better to upload manually to PyPI
download_url = None,
platforms = ['any'],
cmdclass = {'build_ext': build_ext},
ext_modules = [
Extension( "blz.blz_ext",
include_dirs=inc_dirs,
define_macros=def_macros,
sources=sources,
library_dirs=lib_dirs,
libraries=libs,
extra_link_args=LFLAGS,
extra_compile_args=CFLAGS ),
],
packages = ['blz', 'blz.tests'],
)