-
Notifications
You must be signed in to change notification settings - Fork 26
/
setup.py
123 lines (106 loc) · 4.21 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
#! /usr/bin/env python
#
# Authors: N. Benjamin Erichson
# Joseph Knox
# License: GNU General Public License v3.0
from __future__ import print_function
import ast
import io
import os
import re
import sys
import shutil
from setuptools import setup, find_packages
from distutils.command.clean import clean as Clean
from distutils.version import LooseVersion
DISTNAME = 'ristretto'
DESCRIPTION = 'ristretto: Randomized Dimension Reduction Library'
with open('README.rst') as f:
LONG_DESRIPTION = f.read()
AUTHOR = 'N. Benjamin Erichson'
AUTHOR_EMAIL = '[email protected]'
URL = 'https://github.com/erichson/ristretto'
LICENSE = 'GNU'
KEYWORDS = ['randomized algorithms',
'dimension reduction',
'singular value decomposition',
'matrix approximations']
if sys.version_info[0] < 3:
# Python 2.*
import __builtin__ as builtins
else:
import builtins
def get_version():
here = os.path.abspath(os.path.dirname(__file__))
init_file = os.path.join(here, 'ristretto/__init__.py')
_version_re = re.compile(r'__version__\s+=\s+(?P<version>.*)')
with io.open(init_file, 'r', encoding='utf8') as f:
match = _version_re.search(f.read())
version = match.group('version') if match is not None else '"unknown"'
return str(ast.literal_eval(version))
VERSION = get_version()
SCIPY_MIN_VERSION = '0.0.13'
NUMPY_MIN_VERSION = '1.8.2'
CYTHON_MIN_VERSION = '0.23'
# Custom clean command to remove build artifacts from scikit-learn setup.py
# https://github.com/scikit-learn/scikit-learn/blob/master/setup.py
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('ristretto'):
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}
extra_setuptools_args = dict(
zip_safe=False,
include_package_data=True,
install_requires=[
'numpy >= {0}'.format(NUMPY_MIN_VERSION),
'scipy >= {0}'.format(SCIPY_MIN_VERSION),
]
)
def setup_package():
metadata = dict(name=DISTNAME,
author=AUTHOR,
author_email=AUTHOR_EMAIL,
description=DESCRIPTION,
license=LICENSE,
url=URL,
version=VERSION,
keywords=KEYWORDS,
long_description=LONG_DESRIPTION,
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Science/Research',
'Topic :: Scientific/Engineering :: Mathematics',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
],
test_suite='nose.collector',
cmdclass=cmdclass,
packages=find_packages(exclude=['tests']),
**extra_setuptools_args)
setup(**metadata)
if __name__ == '__main__':
setup_package()