forked from gitter-badger/Skater
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
97 lines (81 loc) · 2.78 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
# Reference: http://python-packaging.readthedocs.io/en/latest/dependencies.html
from setuptools import setup, find_packages
from setuptools.command.install import install
import subprocess
import os
import io
import sys
import contextlib
class InvokingShScript(install):
"""Custom install setup to help run shell commands (outside shell) before installation"""
# reference:
# Syntax (long option, short option, description).
user_options = install.user_options + [
('ostype=', None, 'The OS type of the box(linux-ubuntu/mac)'),
('rl=', None, 'Enable rule based learning')
]
def initialize_options(self):
install.initialize_options(self)
self.ostype = 'linux-ubuntu'
self.rl = False
def finalize_options(self):
if self.ostype is None:
raise Exception("specify os type ...")
if self.rl is None:
raise Exception(" should based learning be enabled? ...")
install.finalize_options(self)
def run(self):
# install rule based learners when asked
if self.rl:
dir_path = os.path.dirname(os.path.realpath(__file__))
shell_script_path = os.path.join(dir_path, 'setup.sh')
subprocess.check_output(['bash', shell_script_path, self.ostype])
install.do_egg_install(self)
@contextlib.contextmanager
def chdir(new_dir):
old_dir = os.getcwd()
try:
os.chdir(new_dir)
sys.path.insert(0, new_dir)
yield
finally:
del sys.path[0]
os.chdir(old_dir)
def setup_package():
root = os.path.abspath(os.path.dirname(__file__))
with chdir(root):
with io.open(os.path.join(root, 'skater', 'about.py'), encoding='utf8') as f:
about = {}
exec(f.read(), about)
with io.open(os.path.join(root, 'description.rst'), encoding='utf8') as f:
readme = f.read()
setup(
name=about['__title__'],
packages=find_packages(),
description=about['__summary__'],
long_description=readme,
author=about['__author__'],
author_email=about['__email__'],
version=about['__version__'],
url=about['__uri__'],
license=about['__license__'],
cmdclass={'install': InvokingShScript},
include_package_data=True,
install_requires=[
'scikit-learn>=0.19',
'scikit-image==0.14',
'pandas>=0.22.0',
'ds-lime>=0.1.1.21',
'requests',
'multiprocess',
'dill>=0.2.6',
'joblib==0.11',
'Jinja2==2.10',
'pydotplus==2.0.2',
'plotly==3.2.0',
'bs4'],
extras_require={
'all': 'matplotlib'},
zip_safe=False)
if __name__ == '__main__':
setup_package()