forked from maciejkula/glove-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
155 lines (118 loc) · 4.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
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
import glob
import os
import platform
import subprocess
import sys
from setuptools import Command, Extension, setup
from setuptools.command.test import test as TestCommand
def define_extensions(cythonize=False):
compile_args = ['-ffast-math']
# There are problems with illegal ASM instructions
# when using the Anaconda distribution (at least on OSX).
# This could be because Anaconda uses its own assembler?
# To work around this we do not add -march=native if we
# know we're dealing with Anaconda
if 'anaconda' not in sys.version.lower():
compile_args.append('-march=native')
if cythonize:
glove_cython = "glove/glove_cython.pyx"
glove_metrics = "glove/metrics/accuracy_cython.pyx"
glove_corpus = "glove/corpus_cython.pyx"
else:
glove_cython = "glove/glove_cython.c"
glove_metrics = "glove/metrics/accuracy_cython.c"
glove_corpus = "glove/corpus_cython.cpp"
return [Extension("glove.glove_cython", [glove_cython],
extra_link_args=[],
extra_compile_args=compile_args),
Extension("glove.metrics.accuracy_cython",
[glove_metrics],
extra_link_args=[],
extra_compile_args=compile_args),
Extension("glove.corpus_cython", [glove_corpus],
language='C++',
libraries=["stdc++"],
extra_link_args=compile_args,
extra_compile_args=compile_args)]
def set_gcc():
"""
Try to find and use GCC on OSX for OpenMP support.
"""
# For macports and homebrew
patterns = ['/opt/local/bin/gcc-mp-[0-9].[0-9]',
'/opt/local/bin/gcc-mp-[0-9]',
'/usr/local/bin/gcc-[0-9].[0-9]',
'/usr/local/bin/gcc-[0-9]']
if 'darwin' in platform.platform().lower():
gcc_binaries = []
for pattern in patterns:
gcc_binaries += glob.glob(pattern)
gcc_binaries.sort()
if gcc_binaries:
_, gcc = os.path.split(gcc_binaries[-1])
os.environ["CC"] = gcc
else:
raise Exception('No GCC available. Install gcc from Homebrew '
'using brew install gcc.')
class Cythonize(Command):
"""
Compile the extension .pyx files.
"""
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
import Cython
from Cython.Build import cythonize
cythonize(define_extensions(cythonize=True))
class Clean(Command):
"""
Clean build files.
"""
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
pth = os.path.dirname(os.path.abspath(__file__))
subprocess.call(['rm', '-rf', os.path.join(pth, 'build')])
subprocess.call(['rm', '-rf', os.path.join(pth, '*.egg-info')])
subprocess.call(['find', pth, '-name', '*.pyc', '-type', 'f', '-delete'])
subprocess.call(['rm', os.path.join(pth, 'glove', 'corpus_cython.so')])
subprocess.call(['rm', os.path.join(pth, 'glove', 'glove_cython.so')])
class PyTest(TestCommand):
user_options = [('pytest-args=', 'a', "Arguments to pass to py.test")]
def initialize_options(self):
TestCommand.initialize_options(self)
self.pytest_args = ['tests/']
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True
def run_tests(self):
# import here, cause outside the eggs aren't loaded
import pytest
errno = pytest.main(self.pytest_args)
sys.exit(errno)
setup(
name='glove_python',
version='0.1.0',
description=('Python implementation of Global Vectors '
'for Word Representation (GloVe)'),
long_description='',
packages=["glove"],
install_requires=['numpy', 'scipy'],
tests_require=['pytest'],
cmdclass={'test': PyTest, 'cythonize': Cythonize, 'clean': Clean},
author='Maciej Kula',
url='https://github.com/maciejkula/glove-python',
download_url='https://github.com/maciejkula/glove-python/tarball/0.1.0',
license='Apache 2.0',
classifiers=['Development Status :: 3 - Alpha',
'License :: OSI Approved :: Apache Software License',
'Topic :: Scientific/Engineering :: Artificial Intelligence'],
ext_modules=define_extensions()
)