forked from bwhite/hadoopy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
95 lines (83 loc) · 2.8 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
#!/usr/bin/env python
import sys
import re
import subprocess
from setuptools import setup, find_packages
from setuptools.extension import Extension
import glob
import os
def get_cython_version():
"""
Returns:
Version as a pair of ints (major, minor)
Raises:
ImportError: Can't load cython or find version
"""
import Cython.Compiler.Main
match = re.search('^([0-9]+)\.([0-9]+)',
Cython.Compiler.Main.Version.version)
try:
return map(int, match.groups())
except AttributeError:
raise ImportError
# Only use Cython if it is available, else just use the pre-generated files
try:
cython_version = get_cython_version()
# Requires Cython version 0.13 and up
if cython_version[0] == 0 and cython_version[1] < 13:
raise ImportError
from Cython.Distutils import build_ext
source_ext = '.pyx'
cmdclass = {'build_ext': build_ext}
except ImportError:
source_ext = '.c'
cmdclass = {}
def get_glibc_version():
"""
Returns:
Version as a pair of ints (major, minor) or None
"""
# TODO: Look into a nicer way to get the version
try:
out = subprocess.Popen(['ldd', '--version'],
stdout=subprocess.PIPE).communicate()[0]
except OSError:
return
match = re.search('([0-9]+)\.([0-9]+)\.?[0-9]*', out)
try:
return map(int, match.groups())
except AttributeError:
return
def _glob_recursive(glob_path):
out = []
for path in glob.glob(glob_path):
if os.path.isdir(path):
out += _glob_recursive(path + '/*')
else:
out.append(path)
return out
def _remove_prefix(string, prefix='hadoopy/'):
if string.startswith(prefix):
return string[len(prefix):]
glibc_version = get_glibc_version()
tb_extra_args = []
if sys.byteorder != 'little':
tb_extra_args.append('-D BYTECONVERSION_ISBIGENDIAN')
if glibc_version and (glibc_version[0] == 2 and glibc_version[1] >= 9):
tb_extra_args.append('-D BYTECONVERSION_HASENDIAN_H')
# Since package_data doesn't handle directories, we find all of the files
thirdparty_paths = map(_remove_prefix, _glob_recursive('hadoopy/thirdparty/*'))
ext_modules = [Extension("_hadoopy_main", ["hadoopy/_main" + source_ext,
"hadoopy/getdelim.c"]),
Extension("_hadoopy_typedbytes", ["hadoopy/_typedbytes" + source_ext],
extra_compile_args=tb_extra_args)]
setup(name='hadoopy',
cmdclass=cmdclass,
version='0.6.0',
packages=find_packages(),
package_data={'hadoopy': thirdparty_paths},
author='Brandyn A. White',
author_email='[email protected]',
license='GPLv3',
url='https://github.com/bwhite/hadoopy',
ext_modules=ext_modules)