forked from ariddell/horizont
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
172 lines (145 loc) · 6.08 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
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
#-----------------------------------------------------------------------------
# Copyright (c) 2013-2014, Allen B. Riddell
#
# This file is licensed under Version 3.0 of the GNU General Public
# License. See LICENSE for a text of the license.
#-----------------------------------------------------------------------------
NAME = 'horizont'
DESCRIPTION = 'Topic models'
LONG_DESCRIPTION = open('README.rst').read()
MAINTAINER = 'Allen B. Riddell'
MAINTAINER_EMAIL = '[email protected]'
URL = 'https://github.com/ariddell/horizont'
LICENSE = 'GPLv3'
CLASSIFIERS = [
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Development Status :: 3 - Alpha',
'Environment :: Console',
'Operating System :: OS Independent',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Topic :: Scientific/Engineering',
'Topic :: Scientific/Engineering :: Information Analysis'
]
import ast
import codecs
import os
import sys
from setuptools import setup, find_packages # before distutils import
from distutils.command.sdist import sdist
from distutils.extension import Extension
REQUIRES = ['numpy', 'scipy', 'scikit-learn']
PY2 = sys.version_info[0] == 2
if PY2:
REQUIRES += ['futures']
# VersionFinder from from django-compressor
class VersionFinder(ast.NodeVisitor):
def __init__(self):
self.version = None
def visit_Assign(self, node):
if node.targets[0].id == '__version__':
self.version = node.value.s
def read(*parts):
filename = os.path.join(os.path.dirname(__file__), *parts)
with codecs.open(filename, encoding='utf-8') as fp:
return fp.read()
def find_version(*parts):
finder = VersionFinder()
finder.visit(ast.parse(read(*parts)))
return finder.version
try:
from Cython.Build import cythonize
cython = True
except ImportError:
cython = False
class CheckSDist(sdist):
"""Custom sdist that ensures Cython has compiled all pyx files to c."""
def initialize_options(self):
sdist.initialize_options(self)
self._pyxfiles = []
for root, dirs, files in os.walk('horizont'):
for f in files:
if f.endswith('.pyx'):
self._pyxfiles.append(os.path.join(root, f))
def run(self):
if 'cython' in cmdclass:
self.run_command('cython')
else:
for pyxfile in self._pyxfiles:
cfile = pyxfile[:-3] + 'c'
msg = "C-source file '%s' not found." % (cfile) + \
" Run 'setup.py cython' before sdist."
assert os.path.isfile(cfile), msg
sdist.run(self)
cmdclass = {'sdist': CheckSDist}
###########################################################################
# Cython extensions to compile
###########################################################################
random_sources = ["horizont/RNG/GRNG.cpp",
"horizont/RNG/RNG.cpp",
"horizont/BayesLogit/Code/C/PolyaGamma.cpp",
"horizont/BayesLogit/Code/C/PolyaGammaAlt.cpp",
"horizont/BayesLogit/Code/C/PolyaGammaSP.cpp",
"horizont/BayesLogit/Code/C/InvertY.cpp"]
include_gsl_dir = os.environ.get('GSL_INC_DIR', "/usr/include/")
lib_gsl_dir = os.environ.get('GSL_LIB_DIR', "/usr/lib/")
random_include_dirs = ["horizont/BayesLogit/Code/C", "horizont/RNG", include_gsl_dir]
random_library_dirs = [lib_gsl_dir]
random_libraries = ['gsl', 'gslcblas']
# FIXME: this could be simplified, c.f. pandas
# The build will not fail if GSL cannot be found, but extensions requiring GSL
# will not work.
if cython:
extensions = [Extension("horizont._lda", ["horizont/_lda.pyx"]),
Extension("horizont._random",
["horizont/_random.pyx"] + random_sources,
include_dirs=random_include_dirs,
library_dirs=random_library_dirs,
libraries=random_libraries,
optional=True),
Extension("horizont._utils", ["horizont/_utils.pyx"])]
extensions = cythonize(extensions)
else:
extensions = [Extension("horizont._lda", ["horizont/_lda.c"]),
Extension("horizont._random",
["horizont/_random.cpp"] + random_sources,
include_dirs=random_include_dirs,
library_dirs=random_library_dirs,
libraries=random_libraries,
optional=True),
Extension("horizont._utils", ["horizont/_utils.c"])]
import numpy
include_dirs = [numpy.get_include()]
# package data
package_data_pats = ['*.hpp', '*.pxd', '*.pyx', 'tests/*.dat', 'tests/*.ldac']
# get every file under horizont/BayesLogit/Code/C/", "horizont/RNG/"
package_data_pats += sum(
[[os.path.join(path.replace('horizont/', ''), fn) for fn in files]
for path, dirs, files in os.walk('horizont/BayesLogit/Code/C/')], [])
package_data_pats += sum(
[[os.path.join(path.replace('horizont/', ''), fn) for fn in files]
for path, dirs, files in os.walk('horizont/RNG/')], [])
###########################################################################
# Setup proper
###########################################################################
setup(install_requires=REQUIRES,
name=NAME,
version=find_version("horizont", "__init__.py"),
maintainer=MAINTAINER,
maintainer_email=MAINTAINER_EMAIL,
packages=find_packages(),
description=DESCRIPTION,
long_description=LONG_DESCRIPTION,
license=LICENSE,
url=URL,
classifiers=CLASSIFIERS,
ext_modules=extensions,
include_dirs=include_dirs,
package_data={'horizont' : package_data_pats},
platforms='any')