forked from blaze/blaze
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
288 lines (232 loc) · 8.09 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
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
#!/usr/bin/env python
#------------------------------------------------------------------------
from __future__ import absolute_import
import os
import sys
import shutil
import textwrap
from os.path import join
from distutils.core import Command, setup
from distutils.sysconfig import get_python_inc, get_config_var
from distutils.command.build import build
from distutils.command.build_ext import build_ext
#------------------------------------------------------------------------
# Top Level Packages
#------------------------------------------------------------------------
packages = [
'blaze',
'blaze.blz',
'blaze.blz.tests',
'blaze.bkernel',
'blaze.bkernel.tests',
'blaze.ckernel',
'blaze.ckernel.tests',
'blaze.datadescriptor',
'blaze.datadescriptor.tests',
'blaze.datashape',
'blaze.datashape.tests',
'blaze.executive',
'blaze.tests',
'blaze._printing',
]
#------------------------------------------------------------------------
# Minimum Versions
#------------------------------------------------------------------------
min_cython_version = '0.16'
min_numpy_version = '1.5'
min_llvmpy_version = '0.11.1'
#------------------------------------------------------------------------
# Utilities
#------------------------------------------------------------------------
# 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 Blaze!"
% {'pkgname': pkgname, 'pkgver': pkgver} )
else:
if mod.__version__ < pkgver:
exit_with_error(
"You need %(pkgname)s %(pkgver)s or greater to run Blaze!"
% {'pkgname': pkgname, 'pkgver': pkgver} )
print("* Found %(pkgname)s %(pkgver)s package installed."
% {'pkgname': pkgname, 'pkgver': mod.__version__} )
globals()[pkgname] = mod
#------------------------------------------------------------------------
# Cython Sanity Check
#------------------------------------------------------------------------
try:
from Cython.Distutils import Extension, build_ext
from Cython.Compiler.Main import Version
except:
exit_with_error(
"You need %(pkgname)s %(pkgver)s or greater to compile Blaze!"
% {'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} )
#------------------------------------------------------------------------
# Numpy Sanity Check
#------------------------------------------------------------------------
check_import('numpy', min_numpy_version)
#------------------------------------------------------------------------
# LLVM Sanity Check
#------------------------------------------------------------------------
#check_import('llvmpy', min_llvmpy_version)
#------------------------------------------------------------------------
# C Compiler Environment
#------------------------------------------------------------------------
# Global variables
CFLAGS = os.environ.get('CFLAGS', '').split()
LFLAGS = os.environ.get('LFLAGS', '').split()
lib_dirs = []
libs = []
# Include NumPy header dirs
from numpy.distutils.misc_util import get_numpy_include_dirs
optional_libs = []
# Handle --lflags=[FLAGS] --cflags=[FLAGS]
args = sys.argv[:]
for arg in args:
if arg.find('--lflags=') == 0:
LFLAGS = arg.split('=')[1].split()
sys.argv.remove(arg)
elif arg.find('--cflags=') == 0:
CFLAGS = arg.split('=')[1].split()
sys.argv.remove(arg)
# Add -msse2 flag for optimizing shuffle in include Blosc
if os.name == 'posix':
CFLAGS.append("-msse2")
# Add some macros here for debugging purposes, if needed
def_macros = [('DEBUG', 0)]
#------------------------------------------------------------------------
# Extension
#------------------------------------------------------------------------
numpy_path = get_numpy_include_dirs()[0]
blosc_path = 'blaze/blz/include/blosc/'
blz_source = [
"blaze/blz/blz_ext.pyx"
]
blz_depends = [
]
blosc_source = [
blosc_path + "blosc.c",
blosc_path + "blosclz.c",
blosc_path + "shuffle.c"
]
blosc_depends = [
blosc_path + "blosc.h",
blosc_path + "blosclz.h",
blosc_path + "shuffle.h"
]
extensions = [
Extension(
"blaze.blz.blz_ext",
include_dirs=[
blosc_path,
numpy_path,
],
sources = list(blz_source + blosc_source),
depends = list(blz_depends + blosc_depends),
library_dirs=lib_dirs,
libraries=libs,
extra_link_args=LFLAGS,
extra_compile_args=CFLAGS,
define_macros=def_macros,
),
]
#------------------------------------------------------------------------
# Commands
#------------------------------------------------------------------------
class CleanCommand(Command):
"""Custom distutils command to clean the .so and .pyc files."""
user_options = []
def initialize_options(self):
self._clean_me = []
self._clean_trees = []
for toplevel in packages:
for root, dirs, files in list(os.walk(toplevel)):
for f in files:
if os.path.splitext(f)[-1] in ('.pyc', '.so', '.o', '.pyd'):
self._clean_me.append(join(root, f))
for d in ('build',):
if os.path.exists(d):
self._clean_trees.append(d)
def finalize_options(self):
pass
def run(self):
for clean_me in self._clean_me:
try:
print('flushing', clean_me)
os.unlink(clean_me)
except Exception:
pass
for clean_tree in self._clean_trees:
try:
print('flushing', clean_tree)
shutil.rmtree(clean_tree)
except Exception:
pass
#------------------------------------------------------------------------
# Parser
#------------------------------------------------------------------------
class BuildParser(build):
""" Build the parse tables for datashape """
def run(self):
# run the default build command first
build.run(self)
print('Rebuilding the datashape parser...')
# add the build destination to the module path so we can load it
sys.path.insert(0, self.build_lib)
from blaze.datashape.parser import rebuild
rebuild()
#------------------------------------------------------------------------
# Setup
#------------------------------------------------------------------------
longdesc = open('README.md').read()
setup(
name='blaze',
version='0.2dev',
author='Continuum Analytics',
author_email='blaze-dev@continuum.io',
description='Blaze',
long_description=longdesc,
data_files=[],
license='BSD',
platforms = ['any'],
classifiers=[
'Development Status :: 2 - Pre-Alpha',
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'Intended Audience :: Education',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Topic :: Scientific/Engineering',
'Topic :: Utilities',
],
packages=packages,
ext_modules=extensions,
cmdclass = {
'build_ext' : build_ext,
'clean' : CleanCommand,
'build' : BuildParser
}
)