forked from coin-or/CyLP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
461 lines (403 loc) · 19 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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
import os
import sys
import platform
from os.path import join
import numpy
import unicodedata
#A unicode function that is compatible with Python 2 and 3
u = lambda s: s if sys.version_info[0] > 2 else unicode(s, 'utf-8')
myopen = lambda s: open(s) if sys.version_info[0] == 2 else open(s, encoding="utf-8")
# Setuptools seems to get confused with c++ extensions
try:
from setuptools import setup
from setuptools import Extension
from setuptools.command.install import install
except ImportError:
from distutils.core import setup
from distutils.extension import Extension
from distutils.command.install import install
VERSION = open(join('cylp', 'VERSION')).read()
cythonFilesDir = join('cylp', 'cy')
cppFilesDir = join('cylp', 'cpp')
#Do "export CYLP_USE_CYTHON=" if you want to build cylp from scratch,
#using Cython
try:
os.environ['CYLP_USE_CYTHON']
USECYTHON = True
except:
USECYTHON = False
CoinDir = None
try:
CoinDir = os.environ['COIN_INSTALL_DIR']
except:
from os.path import abspath, dirname
try:
location = dirname(
check_output(['which', 'clp']).strip()).decode('utf-8')
CoinDir = abspath(join(location, ".."))
except:
pass
def get_libs():
'''
Return a list of distinct library names used by ``dependencies``.
'''
libs = []
try:
from subprocess import check_output
flags = (check_output(['pkg-config', '--libs', 'cbc'])
.strip().decode('utf-8'))
libs = [flag[2:] for flag in flags.split()
if flag.startswith('-l')]
libDirs = [flag[2:] for flag in flags.split()
if flag.startswith('-L')]
flags = (check_output(['pkg-config', '--cflags', 'cbc'])
.strip().decode('utf-8'))
incDirs = [flag[2:] for flag in flags.split() if
flag.startswith('-I')]
except:
if CoinDir != None:
if operatingSystem == 'windows':
if os.path.exists(join(CoinDir, 'lib', 'Cbc.lib')):
libs = ['CbcSolver', 'Cbc', 'Cgl', 'OsiClp',
'Clp', 'Osi', 'CoinUtils']
else:
libs = ['libCbcSolver', 'libCbc', 'libCgl', 'libOsiClp',
'libClp', 'libOsi', 'libCoinUtils']
else:
libs = ['CbcSolver', 'Cbc', 'Cgl', 'OsiClp', 'Clp', 'Osi',
'CoinUtils']
libDirs = [join(CoinDir, 'lib')]
incDirs = [join(CoinDir, 'include', 'coin')]
else:
raise Exception('''
Could not find location of COIN installation.
Please ensure that either
* COIN_INSTALL_DIR is set to the location of the installation,
* PKG_CONFIG_PATH points to the location of the .pc files, or
* The cbc executable is in your executable path and is installed
at the same location as the libraries.
''')
return libs, libDirs, incDirs
def getBdistFriendlyString(s):
'''
Solve the issue with restructuredText README
"ordinal not in range error" when using bdist_mpkg or bdist_wininst
'''
return unicodedata.normalize('NFKD', u(s))
operatingSystem = sys.platform
if 'linux' in operatingSystem:
operatingSystem = 'linux'
elif 'darwin' in operatingSystem:
operatingSystem = 'mac'
mac_ver = platform.mac_ver()[0]
elif 'win' in operatingSystem:
operatingSystem = 'windows'
libs, libDirs, incDirs = get_libs()
#Take care of Ubuntu case
if 'CbcSolver' not in libs and operatingSystem == 'linux':
if operatingSystem == 'windows':
libs.append('libCbcSolver')
else:
libs.append('CbcSolver')
libDirs.extend(['.', join('.', cythonFilesDir)])
try:
libDirs.append(join(CoinDir, 'lib'))
except:
pass
if operatingSystem == 'windows':
try:
libDirs.append(join(CoinDir, 'lib', 'intel'))
except:
pass
incDirs.extend([join('.', cppFilesDir), join('.', cythonFilesDir),
numpy.get_include(), '.'])
try:
incDirs.extend([join(CoinDir, 'include', 'coin')])
except:
pass
cmdclass = {}
if USECYTHON:
from Cython.Distutils import build_ext
from Cython.Distutils import extension
Extension = extension.Extension
import Cython.Compiler.Options
Cython.Compiler.Options.annotate = True
cmdclass.update({'build_ext': build_ext})
fileext = '.pyx'
else:
fileext = '.cpp'
extra_compile_args = ['-w', '-std=c++11']
ext_modules = []
if operatingSystem == 'mac':
extra_link_args = ['-Wl,-framework', '-Wl,Accelerate', '-headerpad_max_install_names']
elif operatingSystem == 'linux':
extra_link_args = ['-lrt']
else:
# Assuming Windows
extra_link_args = []
extra_compile_args += ['/EHsc']
ext_modules += [Extension('cylp.cy.CyClpPrimalColumnPivotBase',
sources=[join(cppFilesDir,
'IClpPrimalColumnPivotBase.cpp'),
join(cythonFilesDir, 'CyClpPrimalColumnPivotBase' +
fileext)],
language='c++',
include_dirs=incDirs,
library_dirs=libDirs,
libraries=libs,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args), ]
ext_modules += [Extension('cylp.cy.CyClpDualRowPivotBase',
sources=[join(cppFilesDir,
'IClpDualRowPivotBase.cpp'),
join(cythonFilesDir, 'CyClpDualRowPivotBase' +
fileext)],
language='c++',
include_dirs=incDirs,
library_dirs=libDirs,
libraries=libs,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args), ]
ext_modules += [Extension('cylp.cy.CyCglCutGeneratorBase',
sources=[join(cppFilesDir,
'ICglCutGeneratorBase.cpp'),
join(cythonFilesDir, 'CyCglCutGeneratorBase' +
fileext)],
language='c++',
include_dirs=incDirs,
library_dirs=libDirs,
libraries=libs,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args), ]
ext_modules += [Extension('cylp.cy.CyOsiCuts',
sources=[join(cppFilesDir, 'IOsiCuts.cpp'),
join(cythonFilesDir, 'CyOsiCuts' + fileext)],
language='c++',
include_dirs=incDirs,
library_dirs=libDirs,
libraries=libs,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args), ]
ext_modules += [Extension('cylp.cy.CyOsiSolverInterface',
sources=[join(cythonFilesDir, 'CyOsiSolverInterface' +
fileext)],
language='c++',
include_dirs=incDirs,
library_dirs=libDirs,
libraries=libs,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args), ]
ext_modules += [Extension('cylp.cy.CyCglTreeInfo',
sources=[join(cythonFilesDir, 'CyCglTreeInfo' +
fileext)],
language='c++',
include_dirs=incDirs,
library_dirs=libDirs,
libraries=libs,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args), ]
ext_modules += [Extension('cylp.cy.CyCoinIndexedVector',
sources=[join(cppFilesDir, 'ICoinIndexedVector.cpp'),
join(cythonFilesDir,
'CyCoinIndexedVector' + fileext)],
language='c++',
include_dirs=incDirs,
library_dirs=libDirs,
libraries=libs,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args), ]
ext_modules += [Extension('cylp.cy.CyCoinPackedMatrix',
sources=[join(cppFilesDir, 'ICoinPackedMatrix.cpp'),
join(cythonFilesDir,
'CyCoinPackedMatrix' + fileext)],
language='c++',
include_dirs=incDirs,
library_dirs=libDirs,
libraries=libs,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args), ]
ext_modules += [Extension('cylp.cy.CyCoinModel',
sources=[join(cythonFilesDir,
'CyCoinModel' + fileext)],
language='c++',
include_dirs=incDirs,
library_dirs=libDirs,
libraries=libs,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args), ]
ext_modules += [Extension('cylp.cy.CyCoinMpsIO',
sources=[join(cppFilesDir, 'ICoinMpsIO.cpp'),
join(cythonFilesDir, 'CyCoinMpsIO' + fileext)],
language='c++',
include_dirs=incDirs,
library_dirs=libDirs,
libraries=libs,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args), ]
ext_modules += [Extension('cylp.cy.CyCgl',
sources=[join(cythonFilesDir,
'CyCgl' + fileext)],
language='c++',
include_dirs=incDirs,
library_dirs=libDirs,
libraries=libs,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args), ]
ext_modules += [Extension('cylp.cy.CyCbcNode',
sources=[join(cppFilesDir, 'ICbcNode.cpp'),
join(cythonFilesDir, 'CyCbcNode' + fileext)],
language='c++',
include_dirs=incDirs,
library_dirs=libDirs,
libraries=libs,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args), ]
ext_modules += [Extension('cylp.cy.CyCbcModel',
sources=[join(cppFilesDir, 'ICbcModel.cpp'),
join(cppFilesDir, 'CbcCompareUser.cpp'),
join(cppFilesDir, 'ICbcNode.cpp'),
join(cythonFilesDir,
'CyCbcModel' + fileext)],
language='c++',
include_dirs=incDirs,
library_dirs=libDirs,
libraries=libs,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args), ]
ext_modules += [Extension('cylp.cy.CyClpSimplex',
sources=[join(cppFilesDir,
'IClpPrimalColumnPivotBase.cpp'),
join(cppFilesDir, 'IClpDualRowPivotBase.cpp'),
join(cppFilesDir, 'IClpSimplex.cpp'),
#join(cppFilesDir, 'ICbc.cpp'),
join(cppFilesDir, 'ICbcModel.cpp'),
join(cppFilesDir, 'CbcCompareUser.cpp'),
join(cppFilesDir, 'IClpSimplexPrimal_Wolfe.cpp'),
join(cppFilesDir, 'IClpSimplexPrimal.cpp'),
join(cppFilesDir, 'IClpPackedMatrix.cpp'),
join(cythonFilesDir, 'CyClpSimplex' + fileext)],
language='c++',
include_dirs=incDirs,
library_dirs=libDirs,
libraries=libs,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args), ] #,
#pyrex_gdb=True), ]
ext_modules += [Extension('cylp.cy.CyPEPivot',
sources=[join(cppFilesDir,
'IClpPrimalColumnPivotBase.cpp'),
join(cythonFilesDir, 'CyPEPivot' + fileext)],
language='c++',
include_dirs=incDirs,
library_dirs=libDirs,
libraries=libs,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args), ]
ext_modules += [Extension('cylp.cy.CyWolfePivot',
sources=[join(cppFilesDir,
'IClpPrimalColumnPivotBase.cpp'),
join(cythonFilesDir, 'CyWolfePivot' + fileext)],
language='c++',
include_dirs=incDirs,
library_dirs=libDirs,
libraries=libs,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args), ]
ext_modules += [Extension('cylp.cy.CyDantzigPivot',
sources=[join(cppFilesDir,
'IClpPrimalColumnPivotBase.cpp'),
join(cythonFilesDir, 'CyDantzigPivot' +
fileext)],
language='c++',
include_dirs=incDirs,
library_dirs=libDirs,
libraries=libs,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args), ]
ext_modules += [Extension('cylp.cy.CyTest',
sources=[join(cythonFilesDir, 'CyTest' + fileext)],
language='c++',
include_dirs=incDirs,
library_dirs=libDirs,
libraries=libs,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args), ]
ext_modules += [Extension('cylp.cy.CyPivotPythonBase',
sources=[join(cppFilesDir,
'IClpPrimalColumnPivotBase.cpp'),
join(cythonFilesDir, 'CyPivotPythonBase' +
fileext)],
language='c++',
include_dirs=incDirs,
library_dirs=libDirs,
libraries=libs,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args), ]
ext_modules += [Extension('cylp.cy.CyDualPivotPythonBase',
sources=[join(cppFilesDir,
'IClpDualRowPivotBase.cpp'),
join(cythonFilesDir, 'CyDualPivotPythonBase' +
fileext)],
language='c++',
include_dirs=incDirs,
library_dirs=libDirs,
libraries=libs,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args), ]
ext_modules += [Extension('cylp.cy.CyCutGeneratorPythonBase',
sources=[join(cppFilesDir,
'ICglCutGeneratorBase.cpp'),
join(cppFilesDir,
'IOsiCuts.cpp'),
join(cythonFilesDir, 'CyCutGeneratorPythonBase' +
fileext)],
language='c++',
include_dirs=incDirs,
library_dirs=libDirs,
libraries=libs,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args), ]
s_README = getBdistFriendlyString(myopen('README.rst').read())
s_AUTHORS = u(open('AUTHORS').read())
class customInstall(install):
'''
Take care of adding std:: to isspace in Cython-generated files.
This is currently an issue for Mac OS Mavericks.
'''
def run(self):
currentDir = os.path.dirname(os.path.realpath(__file__))
from distutils.version import LooseVersion
if operatingSystem == 'mac' and LooseVersion(mac_ver) >= LooseVersion('10.9'):
# If std::isspace is not already replaced
if os.system('grep -rI "std::isspace" cylp/cy/*.cpp'):
os.system('''find %s -name "*.cpp" -print | xargs sed -i "" 's/isspace/std::isspace/g' ''' % currentDir)
# These lines commented out per https://github.com/coin-or/CyLP/issues/80
# fixBinaries is now not called, but it's not clear what it actually and
# seems to be unneeded. TKR 1/15/2020
# if operatingSystem == 'mac':
# from fixBinaries import platform_dir
# extra_files.append(join('cbclibs', platform_dir, '*.dylib'))
install.run(self)
# if operatingSystem == 'mac':
# from fixBinaries import fixAll
# fixAll()
cmdclass['install'] = customInstall
extra_files = ['cpp/*.cpp', 'cpp/*.hpp', 'cpp/*.h', 'VERSION']
setup(name='cylp',
version=VERSION,
description='A Python interface for CLP, CBC, and CGL',
long_description=s_README,
long_description_content_type='text/x-rst',
author='Mehdi Towhidi ([email protected]), Dominique Orban ([email protected])',
author_email='[email protected]',
maintainer='Ted Ralphs',
maintainer_email='[email protected]',
url='https://github.com/coin-or/cylp',
license='Eclipse Public License',
packages=['cylp', 'cylp.cy', 'cylp.py', 'cylp.py.pivots', 'cylp.py.modeling',
'cylp.py.utils', 'cylp.py.mip','cylp.py.QP'],
cmdclass=cmdclass,
ext_modules=ext_modules,
install_requires=['numpy >= 1.5.0', 'scipy >= 0.10.0'],
zip_safe = False,
package_data={"cylp": extra_files})