-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsetup.py
More file actions
189 lines (157 loc) · 6.2 KB
/
Copy pathsetup.py
File metadata and controls
189 lines (157 loc) · 6.2 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
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
from __future__ import division, absolute_import, print_function
import os
import sys
import subprocess
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
from numpy.distutils.core import Extension
import argparse
import numpy as np
## Numpy header files
numpy_lib = os.path.split(np.__file__)[0]
numpy_include = os.path.join(numpy_lib, 'core/include')
#
# Make the git revision visible. Most of this is copied from scipy
#
# Return the git revision as a string
def git_version():
def _minimal_ext_cmd(cmd):
# construct minimal environment
env = {}
for k in ['SYSTEMROOT', 'PATH']:
v = os.environ.get(k)
if v is not None:
env[k] = v
# LANGUAGE is used on win32
env['LANGUAGE'] = 'C'
env['LANG'] = 'C'
env['LC_ALL'] = 'C'
out = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=env).communicate()[0]
return out
try:
out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
GIT_REVISION = out.strip().decode('ascii')
except OSError:
GIT_REVISION = "Unknown"
return GIT_REVISION
def write_version_py(filename='version.py'):
cnt = """
# THIS FILE IS GENERATED FROM SCIPY SETUP.PY
git_revision = '%(git_revision)s'
"""
GIT_REVISION = git_version()
a = open(filename, 'w+')
try:
a.write(cnt % dict(git_revision=GIT_REVISION))
finally:
a.close()
write_version_py()
cython_flags = ["-I"] + ["-v"] + ["-X embedsignature=True"]
def generate_cython():
cwd = os.path.abspath(os.path.dirname(__file__))
print("Cythonizing sources")
p = subprocess.call([sys.executable,
os.path.join(cwd, 'cythonize.py'),
'sweetsourcod'] + cython_flags,
cwd=cwd)
if p != 0:
raise RuntimeError("Running cythonize failed!")
if os.name == 'posix':
os.environ["CC"] = "g++"
os.environ["CXX"] = "g++"
generate_cython()
class ModuleList:
def __init__(self, **kwargs):
self.module_list = []
self.kwargs = kwargs
def add_module(self, filename):
modname = filename.replace("/", ".")
modname, ext = os.path.splitext(modname)
self.module_list.append(Extension(modname, [filename], **self.kwargs))
setup(name='sweetsourcod',
version='0.1',
author='Stefano Martiniani',
description="sweetsourcod: The `sweet source coding' library implements universal lossless coding (data compression)"
"algorithms, with a particular focus on estimating complexity measures and entropies of generic procsses",
install_requires=["numpy", "cython", "numba", "zstd", "brotli", "zopfli", "backports.lzma"],
packages=["sweetsourcod"
],
)
#
# build the c++ files
#
include_sources_sweetsourcod = ["source/" + f
for f in os.listdir("source")
if f.endswith(".cpp") or f.endswith(".c")]
include_dirs = [numpy_include, "source"]
depends_sweetsourcod = [os.path.join("source/sweetsourcod", f) for f in os.listdir("source/sweetsourcod/")
if f.endswith(".cpp") or f.endswith(".c") or f.endswith(".h") or f.endswith(".hpp")]
# extract -c flag to set compiler
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument("-j", type=int, default=1)
parser.add_argument("-c", "--compiler", type=str, default=None)
jargs, remaining_args = parser.parse_known_args(sys.argv)
# record c compiler choice. use unix (gcc) by default
# Add it back into remaining_args so distutils can see it also
idcompiler = None
if not jargs.compiler or jargs.compiler in ("unix", "gnu", "gcc"):
idcompiler = "unix"
elif jargs.compiler in ("intel", "icc", "icpc"):
idcompiler = "intel"
extra_compile_args = ["-std=c++11", "-Wall", "-Wextra", "-pedantic", "-O3", "-fPIC"]
if idcompiler.lower() == 'unix':
extra_compile_args += ['-march=native', '-flto'] # , '-fopenmp'
#extra_compile_args += ['-flto'] # , '-fopenmp'
else:
extra_compile_args += ['-axCORE-AVX2', '-ipo', '-ip', '-unroll',
'-qopt-report-stdout', '-qopt-report-phase=openmp'] # '-qopenmp',
include_sources_all = include_sources_sweetsourcod
depends_all = depends_sweetsourcod
print(depends_all)
cxx_modules = [
Extension("sweetsourcod.lempel_ziv",
["sweetsourcod/lempel_ziv.cxx"] + include_sources_all,
include_dirs=include_dirs,
extra_compile_args=extra_compile_args,
libraries=['m'],
extra_link_args=["-std=c++11"],
language="c++", depends=depends_all,
),
Extension("sweetsourcod.block_entropy",
["sweetsourcod/block_entropy.cxx"] + include_sources_all,
include_dirs=include_dirs,
extra_compile_args=extra_compile_args,
libraries=['m'],
extra_link_args=["-std=c++11"],
language="c++", depends=depends_all,
),
Extension("sweetsourcod.block_sorting",
["sweetsourcod/block_sorting.cxx"] + include_sources_all,
include_dirs=include_dirs,
extra_compile_args=extra_compile_args,
libraries=['m'],
extra_link_args=["-std=c++11"],
language="c++", depends=depends_all,
),
Extension("sweetsourcod.hilbert",
["sweetsourcod/hilbert.cxx"] + include_sources_all,
include_dirs=include_dirs,
extra_compile_args=extra_compile_args,
libraries=['m'],
extra_link_args=["-std=c++11"],
language="c++", depends=depends_all,
),
Extension("sweetsourcod.gosper",
["sweetsourcod/gosper.cxx"] + include_sources_all,
include_dirs=include_dirs,
extra_compile_args=extra_compile_args,
libraries=['m'],
extra_link_args=["-std=c++11"],
language="c++", depends=depends_all,
)
]
setup(
ext_modules=cxx_modules,
)