-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.py
180 lines (160 loc) · 5.62 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
173
174
175
176
177
178
179
180
import re
import numpy
import itertools
import distutils.sysconfig
from glob import glob
from setuptools import setup, find_packages, Extension
from setuptools.dist import Distribution
from Cython.Distutils import build_ext
from pkg_resources import resource_string
# remove the "-Wstrict-prototypes" compiler option (not valid for C++)
CFG_VARS = distutils.sysconfig.get_config_vars()
for key, value in CFG_VARS.items():
if isinstance(value, basestring):
CFG_VARS[key] = value.replace("-Wstrict-prototypes", "")
class BinaryDistribution(Distribution):
"""
Subclass the setuptools Distribution to flip the purity flag to false.
See http://lucumr.pocoo.org/2014/1/27/python-on-wheels/
"""
def is_pure(self):
return False
# dependency links
SKIP_RE = re.compile(r'^\s*(?:-\S+)\s+(.*)$')
# Regex groups: 0: URL part, 1: package name, 2: package version
EGG_RE = re.compile(r'^(git\+https?://[^#]+)(?:#egg=([a-z0-9_.]+)(?:-([a-z0-9_.-]+))?)?$')
# Regex groups: 0: URL part, 1: package name, 2: branch name
URL_RE = re.compile(r'^\s*(https?://[\w\.]+.*/([^\/]+)/archive/)([^\/]+).zip$')
# our custom way of specifying extra requirements in separate text files
EXTRAS_RE = re.compile(r'^extras\-(\w+)\-requirements\.txt$')
def parse_reqs(reqs):
"""Parse requirements.txt files into lists of requirements and dependencies
"""
pkg_reqs = []
dep_links = []
for req in reqs:
# find things like `--find-links <URL>`
dep_link_info = SKIP_RE.match(req)
if dep_link_info is not None:
url = dep_link_info.group(1)
dep_links.append(url)
continue
# add packages of form:
# git+https://github.com/Livefyre/pymaptools#egg=pymaptools-0.0.3
egg_info = EGG_RE.match(req)
if egg_info is not None:
url, _, _ = egg_info.group(0, 2, 3)
# if version is None:
# pkg_reqs.append(egg)
# else:
# pkg_reqs.append(egg + '==' + version)
dep_links.append(url)
continue
# add packages of form:
# https://github.com/escherba/matplotlib/archive/qs_fix_build.zip
zip_info = URL_RE.match(req)
if zip_info is not None:
url, pkg = zip_info.group(0, 2)
pkg_reqs.append(pkg)
dep_links.append(url)
continue
pkg_reqs.append(req)
return pkg_reqs, dep_links
def build_extras(glob_pattern):
"""Generate extras_require mapping
"""
fnames = glob(glob_pattern)
result = dict()
dep_links = []
for fname in fnames:
extras_match = re.search(EXTRAS_RE, fname)
if extras_match is not None:
extras_file = extras_match.group(0)
extras_name = extras_match.group(1)
with open(extras_file, 'r') as fhandle:
result[extras_name], deps = parse_reqs(fhandle.readlines())
dep_links.extend(deps)
return result, dep_links
INSTALL_REQUIRES, INSTALL_DEPS = parse_reqs(
resource_string(__name__, 'requirements.txt').splitlines())
TESTS_REQUIRE, TESTS_DEPS = parse_reqs(
resource_string(__name__, 'dev-requirements.txt').splitlines())
EXTRAS_REQUIRE, EXTRAS_DEPS = build_extras('extras-*-requirements.txt')
DEPENDENCY_LINKS = list(set(itertools.chain(
INSTALL_DEPS,
TESTS_DEPS,
EXTRAS_DEPS
)))
CXXFLAGS = u"""
-O3
-msse4.2
-Wno-unused-value
-Wno-unused-function
""".split()
VERSION = '0.0.2'
URL = 'https://github.com/escherba/clustering-metrics'
setup(
name="clustering-metrics",
version=VERSION,
author="Eugene Scherba",
license="BSD",
author_email="[email protected]",
description=("Algorithms for locality-sensitive hashing on text data"),
url=URL,
download_url=URL + "/tarball/master/" + VERSION,
packages=find_packages(exclude=['tests', 'scripts']),
install_requires=INSTALL_REQUIRES,
tests_require=TESTS_REQUIRE,
dependency_links=DEPENDENCY_LINKS,
zip_safe=False,
test_suite='nose.collector',
cmdclass={'build_ext': build_ext},
keywords=['clustering', 'evaluation', 'metrics', 'validation', 'analysis'],
ext_modules=[
Extension(
"clustering_metrics.ext",
[
"clustering_metrics/ext.pyx",
],
depends=[
],
language="c++",
extra_compile_args=CXXFLAGS,
include_dirs=[
"include",
]),
Extension(
"clustering_metrics.entropy",
[
"clustering_metrics/entropy.pyx",
"clustering_metrics/gamma.c",
"clustering_metrics/assignmentoptimal_dbl.c",
"clustering_metrics/assignmentoptimal_lng.c"
],
depends=[
"include/gamma.h",
"include/assignmentoptimal.h",
],
language="c",
extra_compile_args=CXXFLAGS,
include_dirs=[
numpy.get_include(),
"include",
])
],
classifiers=[
'Development Status :: 4 - Beta',
'License :: OSI Approved :: BSD License',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'Operating System :: OS Independent',
'Programming Language :: Cython',
'Programming Language :: Python :: 2.7',
'Topic :: Internet',
'Topic :: Scientific/Engineering',
'Topic :: Scientific/Engineering :: Information Analysis',
'Topic :: Text Processing :: Filters',
],
long_description=resource_string(__name__, 'README.rst'),
distclass=BinaryDistribution,
)