forked from scipopt/PySCIPOpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
120 lines (99 loc) · 3.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
import sys, os, readline, glob
from distutils.core import setup
from distutils.extension import Extension
cythonize = True
try:
from Cython.Distutils import build_ext
from Cython.Build import cythonize
except ImportError:
cythonize = False
# defines whether the python interface should link againt a static (.a)
# or a shared (.so) scipopt library
usesharedlib = True
pathToScipoptsuite = os.path.abspath('../../../')
if usesharedlib:
libscipopt = 'lib/libscipopt.so'
else:
libscipopt = 'lib/libscipopt.a'
linkincludescip = 'lib/scip-src'
# create lib directory if necessary
if not os.path.exists('lib'):
os.makedirs('lib')
# try to find library automatically
if os.path.exists(os.path.join(pathToScipoptsuite,libscipopt)):
# create symbolic links to SCIP
if not os.path.lexists(libscipopt):
os.symlink(os.path.join(pathToScipoptsuite,libscipopt), libscipopt)
def complete(text, state):
return (glob.glob(text+'*')+[None])[state]
readline.set_completer_delims(' \t\n;')
readline.parse_and_bind("tab: complete")
readline.set_completer(complete)
args = sys.argv[1:]
# Python 2/3 compatibility
if sys.version_info >= (3, 0):
my_input = input
else:
my_input = raw_input
# remove links to lib and include
if 'cleanlib' in args:
if os.path.lexists(libscipopt):
print('removing '+libscipopt)
os.remove(libscipopt)
quit()
# completely remove compiled code
if 'clean' in args:
compiledcode = 'pyscipopt/scip.c'
if os.path.exists(compiledcode):
print('removing '+compiledcode)
os.remove(compiledcode)
# always use build_ext --inplace
if args.count("build_ext") > 0 and args.count("--inplace") == 0:
sys.argv.insert(sys.argv.index("build_ext")+1, "--inplace")
# check for missing scipopt library
if not os.path.lexists(libscipopt):
pathToLib = os.path.abspath(my_input('Please enter path to scipopt library (scipoptsuite/lib/libscipopt.so or .a):\n'))
print(pathToLib)
if not os.path.exists(pathToLib):
print('Sorry, the path to scipopt library does not exist')
quit()
# check for missing scip src directory
if not os.path.lexists(linkincludescip):
includescip = os.path.abspath(my_input('Please enter path to scip src directory (scipoptsuite/scip/src):\n'))
print(includescip)
if not os.path.exists(includescip):
print('Sorry, the path to SCIP src/ directory does not exist')
quit()
# create symbolic links to SCIP
if not os.path.lexists(libscipopt):
os.symlink(pathToLib, libscipopt)
if not os.path.lexists(linkincludescip):
os.symlink(includescip, linkincludescip)
extensions = []
ext = '.pyx' if cythonize else '.c'
if usesharedlib:
extensions = [Extension('pyscipopt.scip', [os.path.join('pyscipopt', 'scip'+ext)],
extra_compile_args=['-UNDEBUG'],
include_dirs=[linkincludescip],
library_dirs=['lib'],
runtime_library_dirs=[os.path.abspath('lib')],
libraries=['scipopt', 'readline', 'z', 'gmp', 'ncurses', 'm'])]
else:
extensions = [Extension('pyscipopt.scip', [os.path.join('pyscipopt', 'scip'+ext)],
extra_compile_args=['-UNDEBUG'],
include_dirs=[includescip],
extra_objects=[libscipopt],
libraries=['readline', 'z', 'gmp', 'ncurses', 'm'])]
if cythonize:
extensions = cythonize(extensions)
os.system("sed -i 's/[ ]*$//' pyscipopt/*.c")
setup(
name = 'pyscipopt',
version = '1.0',
description = 'wrapper for SCIP in Python',
author = 'Zuse Institute Berlin',
author_email = '[email protected]',
license = 'ZIB',
ext_modules = extensions,
packages=['pyscipopt']
)