forked from forrestfwilliams/zran
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
77 lines (64 loc) · 1.95 KB
/
setup.py
File metadata and controls
77 lines (64 loc) · 1.95 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
#!/usr/bin/env python
"""Setup script for zran package.
This script was modified from the setup.py file created by
Paul McCarthy for the indexed_gzip project. You can find the
project at this link: https://github.com/pauldmccarthy/indexed_gzip.
"""
import glob
import os
import os.path as op
from setuptools import Extension, setup
# compile ZLIB source?
ZLIB_HOME = os.environ.get("ZLIB_HOME", None)
# If cython is present, we'll compile
# the pyx files from scratch. Otherwise,
# we'll compile the pre-generated c
# files (which are assumed to be present).
have_cython = True
try:
from Cython.Build import cythonize
except Exception:
have_cython = False
print(
'''zran setup
have_cython: %s (if True, modules will be cythonized, else cythonized C files are assumed to be present)
ZLIB_HOME: %s (if set, ZLIB sources are compiled into the indexed_gzip extension)
''' % (have_cython, ZLIB_HOME)
)
# compile flags
include_dirs = []
lib_dirs = []
libs = []
extra_srcs = []
extra_compile_args = []
compiler_directives = {'language_level': 3}
define_macros = []
if ZLIB_HOME is not None:
include_dirs.append(ZLIB_HOME)
extra_srcs.extend(glob.glob(op.join(ZLIB_HOME, '*.c')))
else:
# if ZLIB_HOME is set, statically link,
# rather than use system-provided zlib
libs.append('z')
extra_compile_args += ['-Wall', '-Wno-unused-function']
# Compile from cython files if
# possible, or compile from c.
if have_cython:
pyx_ext = 'pyx'
else:
pyx_ext = 'c'
# The zran module
zran_ext = Extension(
'zran',
[op.join('src', 'zran', 'zranlib.{}'.format(pyx_ext)), op.join('src', 'zran', 'zran.c')] + extra_srcs,
libraries=libs,
library_dirs=lib_dirs,
include_dirs=include_dirs,
extra_compile_args=extra_compile_args,
define_macros=define_macros,
)
extensions = [zran_ext]
# Cythonize if we can
if have_cython:
extensions = cythonize(extensions, compiler_directives=compiler_directives)
setup(ext_modules=extensions)