-
Notifications
You must be signed in to change notification settings - Fork 8
/
setup.py
126 lines (100 loc) · 3.51 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
import os
import shutil
from setuptools import setup, find_packages
from setuptools.extension import Extension
from setuptools.command.build_ext import build_ext
from distutils.command.clean import clean
from Cython.Build import cythonize
from lpsmap import config
AD3_FLAGS_UNIX = [
'-std=c++11',
'-O3',
'-Wall',
'-Wno-sign-compare',
'-Wno-overloaded-virtual',
'-c',
'-fmessage-length=0',
'-fPIC',
'-ffast-math',
'-march=native'
]
AD3_FLAGS_MSVC = [
'/O2',
'/fp:fast',
'/favor:INTEL64',
'/wd4267' # suppress sign-compare--like warning
]
AD3_CFLAGS = {
'cygwin': AD3_FLAGS_UNIX,
'mingw32': AD3_FLAGS_UNIX,
'unix': AD3_FLAGS_UNIX,
'msvc': AD3_FLAGS_MSVC
}
# support compiler-specific cflags in extensions and libs
class our_build_ext(build_ext):
def build_extensions(self):
# bug in distutils: flag not valid for c++
flag = '-Wstrict-prototypes'
if (hasattr(self.compiler, 'compiler_so')
and flag in self.compiler.compiler_so):
self.compiler.compiler_so.remove(flag)
compiler_type = self.compiler.compiler_type
compile_args = AD3_CFLAGS.get(compiler_type, [])
for e in self.extensions:
e.extra_compile_args.extend(compile_args)
build_ext.build_extensions(self)
class our_clean(clean):
def run(self):
if os.path.exists('build'):
shutil.rmtree('build')
for dirpath, dirnames, filenames in os.walk('.'):
for filename in filenames:
if any(filename.endswith(suffix) for suffix in
(".so", ".pyd", ".dll", ".pyc")):
os.unlink(os.path.join(dirpath, filename))
continue
extension = os.path.splitext(filename)[1]
if extension in ['.c', '.cpp']:
pyx_file = str.replace(filename, extension, '.pyx')
if os.path.exists(os.path.join(dirpath, pyx_file)):
os.unlink(os.path.join(dirpath, filename))
for dirname in dirnames:
if dirname == '__pycache__':
shutil.rmtree(os.path.join(dirpath, dirname))
clean.run(self)
# this is a backport of a workaround for a problem in distutils.
cmdclass = {'build_ext': our_build_ext,
'clean': our_clean}
extensions = [
Extension('lvmhelpers.pbinary_topk',
["lvmhelpers/pbinary_topk.pyx"]),
Extension('lvmhelpers.pbernoulli',
["lvmhelpers/pbernoulli.pyx"],
libraries=['ad3'],
library_dirs=[config.get_libdir()],
include_dirs=[config.get_include()]),
Extension('lvmhelpers.pbudget',
["lvmhelpers/pbudget.pyx"],
libraries=['ad3'],
library_dirs=[config.get_libdir()],
include_dirs=[config.get_include()]),
Extension('lvmhelpers.psequence',
["lvmhelpers/psequence.pyx"],
libraries=['ad3'],
library_dirs=[config.get_libdir()],
include_dirs=[config.get_include()]),
]
with open('requirements.txt') as f:
requirements = f.read().splitlines()
setup(
name='lvmhelpers',
version='0.3',
url='https://github.com/goncalomcorreia/explicit-sparse-marginalization',
author='Gonçalo Correia',
author_email='goncalommac@gmail.com',
packages=find_packages(),
install_requires=requirements,
cmdclass=cmdclass,
include_package_data=True,
ext_modules=cythonize(extensions)
)