This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
setup.py
161 lines (136 loc) · 4.72 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
"""Install package."""
import os
import re
import shutil
import site
import subprocess
import sys
import tempfile
import traceback
import unittest
from distutils.command.build import build as _build
from multiprocessing import cpu_count
from setuptools import Command, find_packages, setup
from setuptools.command.bdist_egg import bdist_egg as _bdist_egg
from setuptools.command.develop import develop as _develop
SETUP_DIR = os.path.dirname(os.path.abspath(__file__))
PROCESSES = cpu_count()
PROCESSES = str(PROCESSES - 1) if (PROCESSES > 1) else '1'
class setup_pymimkl(Command):
"""Build MIMKL and install pymimkl."""
description = 'Run script to setup MIMKL'
def initialize_options(self):
"""Set initialize options."""
pass
def finalize_options(self):
"""Set finalize options."""
pass
def _install_pymimkl(self):
"""Build and install _pymimkl."""
print('Install _pymimkl')
print('Updating submodules')
# probably redundant but needed if someone just cloned the repo
if os.path.exists(os.path.join(SETUP_DIR, '.git')):
subprocess.check_call(['git', 'submodule', 'init'])
subprocess.check_call(['git', 'submodule', 'update'])
build_directory = os.path.join(SETUP_DIR, 'build_')
os.makedirs(build_directory, exist_ok=True)
print('Building _pymimkl in {}'.format(build_directory))
subprocess.check_call(
[
os.path.join(SETUP_DIR, 'setup_mimkl.sh'),
SETUP_DIR, build_directory, sys.executable, PROCESSES
]
)
package_directory = os.path.join(SETUP_DIR, 'python', 'pymimkl')
print('Adding _pymimkl to local site {}'.format(package_directory))
# then it is shipped py setup(package_data)
pymimkl_build_directory = os.path.join(
build_directory, 'python', 'pymimkl'
)
pymimkl_built_files = [
os.path.join(pymimkl_build_directory, entry)
for entry in os.listdir(pymimkl_build_directory)
if (
entry.startswith('_pymimkl') and
entry.endswith('.so')
)
]
for module_file in pymimkl_built_files:
shutil.copy(
module_file,
package_directory
)
try:
if self.develop:
pass
else:
raise AttributeError
except AttributeError:
print('Cleaning up')
shutil.rmtree(build_directory, ignore_errors=True)
def run(self):
"""Run installation of _pymimkl."""
self._install_pymimkl()
class build(_build):
"""Build command."""
sub_commands = [
('setup_pymimkl', None)
] + _build.sub_commands
class bdist_egg(_bdist_egg):
"""Build bdist_egg."""
def run(self):
"""Run build bdist_egg."""
self.run_command('setup_pymimkl')
_bdist_egg.run(self)
class develop(_develop):
"""Build develop."""
def run(self):
"""Run build develop."""
setup_pymimkl = self.distribution.get_command_obj(
'setup_pymimkl'
)
setup_pymimkl.develop = True
self.run_command('setup_pymimkl')
_develop.run(self)
def test_suite():
"""Enable `python setup.py test`."""
test_loader = unittest.TestLoader()
test_suite = test_loader.discover('python/pymimkl/tests')
return test_suite
if __name__ == '__main__':
setup(
name='pymimkl',
version='0.2.0',
description=('Supervised and Unsupervised Multiple Kernel Learning '
'including matrix induction'),
url='https://github.com/IBM/mimkl',
author='Joris Cadow, Matteo Manica',
author_email='joriscadow@gmail.com, drugilsberg@gmail.com',
packages=find_packages('python'),
package_dir={'': 'python'},
package_data={'pymimkl': ['_pymimkl*.so']},
zip_safe=False,
cmdclass={
'bdist_egg': bdist_egg,
'build': build,
'setup_pymimkl': setup_pymimkl,
'develop': develop
},
tests_require=["numpy", "scipy"],
extras_require={'testing': ["numpy", "scipy"]},
install_requires=["numpy"],
test_suite="setup.test_suite",
license="MIT",
keywords=[
'multiple kernel learning', 'MKL',
'unsupervised', 'kernel', 'matrix induced',
'mimkl', 'pimkl', 'pathway induced',
'EasyMKL'
],
classifiers=[
'Development Status :: 3 - Beta',
'Topic :: Scientific/Engineering :: Artificial Intelligence',
'Topic :: Scientific/Engineering :: Mathematics',
],
)