-
Notifications
You must be signed in to change notification settings - Fork 5
/
setup.py
132 lines (119 loc) · 4.74 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
from setuptools import setup
from setuptools import find_packages
# from distutils.core import setup
# To use a consistent encoding
from codecs import open
from os import path
here = path.abspath(path.dirname(__file__))
requires_list = []
with open(path.join(here, 'requirements.txt'), encoding='utf-8') as f:
for line in f:
requires_list.append(str(line))
name = "UCRL"
#from distutils.extension import Extension
from setuptools.extension import Extension
from Cython.Build import cythonize
from distutils.command.clean import clean as Clean
import os
import numpy
import shutil
import UCRL
VERSION = UCRL.__version__
# Custom clean command to remove build artifacts
class CleanCommand(Clean):
description = "Remove build artifacts from the source tree"
def run(self):
Clean.run(self)
# Remove c files if we are not within a sdist package
cwd = os.path.abspath(os.path.dirname(__file__))
remove_c_files = not os.path.exists(os.path.join(cwd, 'PKG-INFO'))
if remove_c_files:
print('Will remove generated .c files')
if os.path.exists('build'):
shutil.rmtree('build')
for dirpath, dirnames, filenames in os.walk('UCRL'):
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 remove_c_files and 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))
cmdclass = {'clean': CleanCommand}
libraries = []
if os.name == 'posix':
libraries.append('m')
extra_compile_args = ["-O3", "-ffast-math", "-march=native", "-fopenmp"]
extra_link_args = ['-fopenmp']
extensions = [
Extension("UCRL.evi.evi",
["UCRL/evi/evi.pyx"],
include_dirs=[numpy.get_include()],
libraries=libraries,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args),
Extension("UCRL.evi._max_proba",
["UCRL/evi/_max_proba.pyx"],
include_dirs=[numpy.get_include()],
libraries=libraries,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args),
Extension("UCRL.evi._utils",
["UCRL/evi/_utils.pyx"],
include_dirs=[numpy.get_include()],
libraries=libraries,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args),
Extension("UCRL.evi.free_evi",
["UCRL/evi/free_evi.pyx"],
include_dirs=[numpy.get_include()],
libraries=libraries,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args),
Extension("UCRL.cython.ExtendedValueIteration",
["UCRL/cython/ExtendedValueIteration.pyx"],
include_dirs=[numpy.get_include()],
libraries=libraries,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args),
Extension("UCRL.cython.max_proba",
["UCRL/cython/max_proba.pyx"],
include_dirs=[numpy.get_include()],
libraries=libraries,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args),
Extension("UCRL.evi.prova",
["UCRL/evi/prova.pyx"],
include_dirs=[numpy.get_include()],
libraries=libraries,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args),
Extension("UCRL.evi._free_utils",
["UCRL/evi/_free_utils.pyx"],
include_dirs=[numpy.get_include()],
libraries=libraries,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args),
Extension("UCRL.evi.scevi",
["UCRL/evi/scevi.pyx"],
include_dirs=[numpy.get_include()],
libraries=libraries,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args)
]
setup(
name=name,
version=VERSION,
packages=[package for package in find_packages()
if package.startswith(name)],
license='BOOOOO',
install_requires=requires_list,
ext_modules=cythonize(extensions, gdb_debug=False),
cmdclass=cmdclass,
)