This repository has been archived by the owner on Aug 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsetup.py
316 lines (273 loc) · 9.75 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# NOTE to whoever happens to look in this file: I had to cheat a bit
# to get the installer to work with PIP. Since the 'build' action
# effectively builds both python source and binary libraries (by
# downloading and unpacking the binary distribution)
import distutils.command.build
import os
import os.path
import platform
import re
import shutil
import sys
import setuptools.command.egg_info
import setuptools.command.install
from setuptools import setup
class VersionError(Exception):
pass
class URLError(Exception):
pass
with open(os.path.join(os.path.dirname('__file__'), 'PKG-INFO'), 'rt') as f:
data = f.read()
regex = re.compile(r'^Version: (?P<version_number>(\d+\.)+(\d+\b))',
re.MULTILINE)
o = regex.search(data)
if o is not None:
vn = o.groupdict()['version_number']
vn = vn.split('.')
mosekmajorver = vn[0]
mosekminorver = vn[1]
mosekrevision = vn[2]
state = 'stable'
else:
raise VersionError('No version entry in PKG-INFO')
######################
# Platform setup
######################
libs = {
'win64x86': {
'7.0': [
'mosek64_7_0.dll', 'mosekxx7_0.dll', 'mosekscopt7_0.dll',
'libiomp5md.dll'
],
'7.1': [
'mosek64_7_1.dll', 'mosekxx7_1.dll', 'mosekscopt7_1.dll',
'libiomp5md.dll'
],
'8.0': [
'mosek64_8_0.dll', 'mosekxx8_0.dll', 'mosekscopt8_0.dll',
'libiomp5md.dll', 'cilkrts20.dll'
],
'8.1': [
'mosek64_8_1.dll', 'mosekxx8_1.dll', 'mosekscopt8_1.dll',
'libiomp5md.dll', 'cilkrts20.dll'
],
},
'win34x86': {
'7.0': [
'mosek7_0.dll', 'mosekxx7_0.dll', 'mosekscopt7_0.dll',
'libiomp5md.dll'
],
'7.1': [
'mosek7_1.dll', 'mosekxx7_1.dll', 'mosekscopt7_1.dll',
'libiomp5md.dll'
],
'8.0': [
'mosek8_0.dll', 'mosekxx8_0.dll', 'mosekscopt8_0.dll',
'libiomp5md.dll', 'cilkrts20.dll'
],
'8.1': [
'mosek8_1.dll', 'mosekxx8_1.dll', 'mosekscopt8_1.dll',
'libiomp5md.dll', 'cilkrts20.dll'
],
},
'linux64x86': {
'7.0': [
'libmosek64.so.7.0', 'libmosekxx7_0.so', 'libmosekscopt7_0.so',
'libiomp5.so'
],
'7.1': [
'libmosek64.so.7.1', 'libmosekxx7_1.so', 'libmosekscopt7_1.so',
'libiomp5.so'
],
'8.0': [
'libmosek64.so.8.0', 'libmosekxx8_0.so', 'libmosekscopt8_0.so',
'libiomp5.so', 'libcilkrts.so.5'
],
'8.1': [
'libmosek64.so.8.1', 'libmosekxx8_1.so', 'libmosekscopt8_1.so',
'libiomp5.so', 'libcilkrts.so.5'
],
},
'linux32x86': {
'7.0': [
'libmosek.so.7.0', 'libmosekxx7_0.so', 'libmosekscopt7_0.so',
'libiomp5.so'
],
'7.1': [
'libmosek.so.7.1', 'libmosekxx7_1.so', 'libmosekscopt7_1.so',
'libiomp5.so'
],
},
'osx64x86': {
'7.0': [
'libmosek64.7.0.dylib', 'libmosekxx7_0.dylib',
'libmosekscopt7_0.dylib', 'libiomp5.dylib'
],
'7.1': [
'libmosek64.7.1.dylib', 'libmosekxx7_1.dylib',
'libmosekscopt7_1.dylib', 'libiomp5.dylib'
],
'8.0': [
'libmosek64.8.0.dylib', 'libmosekxx8_0.dylib',
'libmosekscopt8_0.dylib', 'libcilkrts.5.dylib'
],
'8.1': [
'libmosek64.8.1.dylib', 'libmosekxx8.1.dylib',
'libmosekscopt8.1.dylib', 'libcilkrts.5.dylib'
],
},
}
licensepdfd = {
'7.0': ['mosek', '7', 'license.pdf'],
'7.1': ['mosek', '7', 'license.pdf'],
'8.0': ['mosek', '8', 'doc', 'licensing.pdf'],
'8.1': ['mosek', '8', 'doc', 'licensing.pdf'],
}
pkgnames = {
'win64x86': 'mosektoolswin64x86.zip',
'win34x86': 'mosektoolswin32x86.zip',
'linux64x86': 'mosektoolslinux64x86.tar.bz2',
'linux32x86': 'mosektoolslinux32x86.tar.bz2',
'osx64x86': 'mosektoolsosx64x86.tar.bz2'
}
is_64bits = platform.architecture()[0] == '64bit'
pf = platform.system()
if pf == 'Windows':
if is_64bits:
pfname = "win64x86"
pkgname = 'mosektoolswin64x86.zip'
else:
pfname = "win32x86"
pkgname = 'mosektoolswin32x86.zip'
dldir = os.environ.get('TEMP')
elif pf == 'Linux':
if is_64bits:
pfname = "linux64x86"
else:
pfname = "linux32x86"
pkgname = 'mosektoolslinux32x86.tar.bz2'
dldir = '{0}/Downloads'.format(
os.environ['HOME']) # appears to be standart
elif pf == 'Darwin':
pfname = "osx64x86"
pkgname = 'mosektoolsosx64x86.tar.bz2'
dldir = '{0}/Downloads'.format(os.environ['HOME'])
else:
raise VersionError("Unsupported platform {0}".format(pf))
pkgname = pkgnames[pfname]
mskverkey = '{0}.{1}'.format(mosekmajorver, mosekminorver)
moseklibs = libs[pfname][mskverkey]
moseklibs = set(moseklibs)
if dldir is not None and not os.path.isdir(dldir):
dldir = None
pkgpath = '/{state}/{0}.{1}.0.{2}/{3}'.format(
mosekmajorver, mosekminorver, mosekrevision, pkgname, state=state)
unpackdir = os.path.abspath(
os.path.join(os.path.abspath(os.path.dirname(__file__)), 'src'))
distroplatformpfx = 'mosek/{0}/tools/platform/{1}'.format(mosekmajorver,
pfname)
######################
# Get mosek package
######################
def _pre_install():
"""
Fetch MOSEK distribution and unpack the python module structure
"""
# Download the newest distro
if dldir is not None:
pkgfilename = os.path.join(dldir, 'Mosek-{0}.{1}.{2}-'.format(
mosekmajorver, mosekminorver, mosekrevision) + pkgname)
else: # download to local directory
pkgfilename = os.path.join(unpackdir, pkgname)
if not os.path.exists(pkgfilename):
url = "http://download.mosek.com" + pkgpath
if sys.version_info.major == 2:
import urllib
urllib.urlretrieve(url, pkgfilename)
elif sys.version_info.major == 3:
import urllib.request
urllib.request.urlretrieve(url, pkgfilename)
licensepdf = '/'.join(licensepdfd[mskverkey])
pypfx = '{0}/python/{1}/mosek'.format(distroplatformpfx, sys.version_info.major)
if os.path.splitext(pkgname)[-1] == '.zip':
import zipfile
with zipfile.ZipFile(pkgfilename) as zf:
for tmem in zf.infolist():
if tmem.filename.startswith(pypfx):
zf.extract(tmem,
os.path.dirname(tmem.filename[len(pypfx):]))
elif os.path.basename(tmem.filename) in moseklibs:
zf.extract(tmem, unpackdir)
elif tmem.filename == licensepdf:
zf.extract(tmem, unpackdir)
else:
import tarfile
with tarfile.open(pkgfilename) as tf:
for tmem in tf:
if not tmem.isfile():
continue
basename = os.path.basename(tmem.name)
if (tmem.name == licensepdf) or (tmem.name.startswith(pypfx)
) or (basename in moseklibs):
tf.extract(tmem, unpackdir)
def _post_install(sitedir):
"""
Unpack and install the necessary binary libraries and the
license. Create the mosekorigin module.
"""
# Copy python modules
try:
shutil.rmtree(os.path.join(sitedir, 'mosek'))
except:
pass
libsrcdir = os.path.join(unpackdir, 'mosek', mosekmajorver, 'tools',
'platform', pfname, 'bin')
shutil.copytree(
os.path.join('src', 'mosek', mosekmajorver, 'tools', 'platform',
pfname, 'python', str(sys.version_info.major), 'mosek'),
os.path.join(sitedir, 'mosek'))
tgtpath = os.path.join(sitedir, 'mosek')
#try: os.makedirs(tgtpath)
#except OSError: pass
for l in moseklibs:
shutil.copyfile(os.path.join(libsrcdir, l), os.path.join(tgtpath, l))
with open(os.path.join(sitedir, 'mosek', 'mosekorigin.py'), 'wt') as f:
f.write('import os\n')
f.write('__mosekinstpath__ = os.path.dirname(__file__)\n')
f.write('\n')
shutil.copy(
os.path.join('src', *licensepdfd[mskverkey]),
os.path.join(sitedir, 'mosek'))
print("""
*** MOSEK for Python ***
Please read through the MOSEK software license before using MOSEK:
{0}
To use MOSEK for optimization a license file is required. Free
academic licenses, commercial trial licenses and full licenses can be
obtained at http://mosek.com.
""".format(os.path.join(sitedir, *licensepdfd[mskverkey])))
class build(distutils.command.build.build):
def run(self):
self.execute(_pre_install, (), msg="Fetch and unpack MOSEK distro")
distutils.command.build.build.run(self)
class install(setuptools.command.install.install):
def run(self):
setuptools.command.install.install.run(self)
self.execute(
_post_install, (self.install_lib, ),
msg="Install binary libraries")
packages = ['mosek', 'mosek.fusion']
setup(
name='Mosek',
cmdclass={'build': build,
'install': install},
version='{0}.{1}.{2}'.format(mosekmajorver, mosekminorver, mosekrevision),
#packages = packages,
#package_dir = { 'mosek' : os.path.join('src','mosek',mosekmajorver,'tools','platform',pfname,'python',str(major),'mosek') },
install_requires=['numpy>=1.4'],
author='Mosek ApS',
author_email="[email protected]",
description='Mosek/Python APIs',
long_description='Interface for MOSEK',
license="See %s in the MOSEK distribution" % licensepdfd[mskverkey][-1],
url='http://www.mosek.com', )