-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsetup.py
135 lines (110 loc) · 4.86 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
from setuptools import setup, Extension
import os, platform, sys, re
# look for environment variable that specifies path to SCIP and GCG
scipoptdir = os.environ.get('SCIPOPTDIR', '').strip('"')
gcgoptdir = os.environ.get('GCGOPTDIR', scipoptdir).strip('"')
extra_compile_args = []
extra_link_args = []
includedirs = []
for optdir in set([scipoptdir, gcgoptdir]):
# determine include directory
if os.path.exists(os.path.join(optdir, 'src')):
# SCIP seems to be installed in place
includedirs.append(os.path.abspath(os.path.join(optdir, 'src')))
else:
# assume that SCIP is installed on the system
includedirs.append(os.path.abspath(os.path.join(optdir, 'include')))
if not gcgoptdir:
if platform.system() == 'Linux':
includedirs.append("/usr/include/gcg")
includedirs = list(set(includedirs))
print('Using include path <%s>.' % ", ".join(includedirs))
# determine scip library
if os.path.exists(os.path.join(scipoptdir, "lib", "shared", "libscip.so")):
# SCIP seems to be created with make
sciplibdir = os.path.abspath(os.path.join(scipoptdir, "lib", "shared"))
sciplibname = "scip"
extra_compile_args.append("-DNO_CONFIG_HEADER")
# the following is a temporary hack to make it compile with SCIP/make:
extra_compile_args.append("-DTPI_NONE") # if other TPIs are used, please modify
else:
# assume that SCIP is installed on the system
sciplibdir = os.path.abspath(os.path.join(scipoptdir, "lib"))
sciplibname = "libscip" if platform.system() in ["Windows"] else "scip"
# determine gcg library
if os.path.exists(os.path.join(gcgoptdir, "lib", "shared", "libgcg.so")):
# SCIP seems to be created with make
gcglibdir = os.path.abspath(os.path.join(gcgoptdir, "lib", "shared"))
gcglibname = "gcg"
else:
# assume that SCIP is installed on the system
gcglibdir = os.path.abspath(os.path.join(gcgoptdir, "lib"))
gcglibname = "libgcg" if platform.system() in ["Windows"] else "gcg"
print('Using SCIP library <%s> at <%s>.' % (sciplibname, sciplibdir))
print('Using GCG library <%s> at <%s>.' % (gcglibname, gcglibdir))
# set runtime libraries
if platform.system() in ['Linux', 'Darwin']:
for libdir in set([sciplibdir, gcglibdir]):
extra_link_args.append('-Wl,-rpath,'+libdir)
# enable debug mode if requested
if "--debug" in sys.argv:
extra_compile_args.append('-UNDEBUG')
sys.argv.remove("--debug")
use_cython = True
packagedirgcg = os.path.join('src', 'pygcgopt')
with open(os.path.join(packagedirgcg, '__init__.py'), 'r') as initfile:
version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]',
initfile.read(), re.MULTILINE).group(1)
try:
from Cython.Build import cythonize
except ImportError:
if not os.path.exists(os.path.join(packagedir, 'gcg.cpp')):
print('Cython is required')
quit(1)
use_cython = False
if not os.path.exists(os.path.join(packagedirgcg, 'gcg.pyx')):
use_cython = False
ext = '.pyx' if use_cython else '.cpp'
extra_compile_args.append("-std=c++11")
on_github_actions = os.getenv('GITHUB_ACTIONS') == 'true'
release_mode = os.getenv('RELEASE') == 'true'
compile_with_line_tracing = on_github_actions and not release_mode
extensions = [Extension('pygcgopt.gcg', [os.path.join(packagedirgcg, 'gcg'+ext)],
include_dirs=includedirs,
library_dirs=list(set([sciplibdir, gcglibdir])),
libraries=[sciplibname, gcglibname],
extra_compile_args = extra_compile_args,
extra_link_args=extra_link_args
)]
if use_cython:
# Compiler directives needed for documentation, see https://stackoverflow.com/a/10060115/11362041
extensions = cythonize(extensions, compiler_directives={'language_level': 3, 'embedsignature': True})
with open('README.md') as f:
long_description = f.read()
setup(
name='PyGCGOpt',
version=version,
description='Python interface and modeling environment for GCG',
long_description=long_description,
long_description_content_type='text/markdown',
url='https://github.com/scipopt/PyGCGOpt',
author='Lehrstuhl für Operations Research - RWTH Aachen University',
author_email='[email protected]',
license='MIT',
classifiers=[
'Development Status :: 2 - Pre-Alpha',
'Intended Audience :: Science/Research',
'Intended Audience :: Education',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3',
'Programming Language :: Cython',
'Topic :: Scientific/Engineering :: Mathematics'],
ext_modules=extensions,
install_requires=[
'wheel',
'pyscipopt==5.3.0'
],
packages=['pygcgopt'],
package_dir={'pygcgopt': packagedirgcg},
package_data = {'pygcgopt': ['gcg.pyx', 'gcg.pxd', '*.pxi', 'gcg/lib/*']}
)