forked from supermihi/lpdec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·103 lines (92 loc) · 3.77 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
#!/usr/bin/python2
# -*- coding: utf-8 -*-
# Copyright 2014-2015 Michael Helmling
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation
from __future__ import unicode_literals
import os
import fnmatch
import io
import re
import sys
from os.path import join
from setuptools import setup, find_packages
from Cython.Build import cythonize
import numpy as np
requirements = ['numpy', 'sqlalchemy', 'cython', 'python-dateutil', 'jinja2', 'sympy', 'scipy']
def makeExtensions():
"""Returns an Extension object for the given submodule of lpdecoding."""
sources = []
for root, dirnames, filenames in os.walk('lpdec'):
for filename in fnmatch.filter(filenames, '*.pyx'):
sources.append(str(join(root, filename)))
directives = dict(embedsignature=True)
if '--profile' in sys.argv:
directives['profile'] = True
sys.argv.remove('--profile')
if '--debug' in sys.argv:
sys.argv.remove('--debug')
else:
directives['boundscheck'] = False
directives['nonecheck'] = False
directives['initializedcheck'] = False
extensions = cythonize(sources, include_path=[np.get_include()],
compiler_directives=directives)
for e in extensions:
e.include_dirs += [np.get_include()] # the above does not work on windows
if '--no-glpk' in sys.argv:
extensions = [e for e in extensions if 'glpk' not in e.libraries]
sys.argv.remove('--no-glpk')
if '--no-gurobi' in sys.argv:
extensions = [e for e in extensions if 'gurobi65' not in e.libraries]
sys.argv.remove('--no-gurobi')
else:
requirements.append('gurobimh')
# find library version: library name includes major/minor version information (e.g.
# libgurobi65.so vs libgurobi60.so). This hack-ish solution parses version information from
# the C header file.
try:
gurobihome = os.environ['GUROBI_HOME']
except KeyError:
raise RuntimeError('GUROBI_HOME not set')
with open(join(gurobihome, 'include', 'gurobi_c.h'), 'rt') as f:
gurobi_c_h = f.read()
major = re.findall('define GRB_VERSION_MAJOR\s+([0-9]+)', gurobi_c_h)[0]
minor = re.findall('define GRB_VERSION_MINOR\s+([0-9]+)', gurobi_c_h)[0]
libraryName = 'gurobi' + major + minor
for e in extensions:
if 'gurobi65' in e.libraries:
e.libraries[e.libraries.index('gurobi65')] = libraryName
e.library_dirs = [join(gurobihome, 'lib')]
e.include_dirs = [join(gurobihome, 'include')]
return extensions
with io.open(join('lpdec', '__init__.py'), 'r', encoding='UTF-8') as f:
version_file = f.read()
version_match = re.search(r'^__version__ = [\'"]([^\'"]*)[\'"]', version_file, re.M)
version = version_match.group(1)
scriptName = 'lpdec'
setup(
name='lpdec',
version=version,
author='Michael Helmling',
author_email='helmling@uni-koblenz.de',
url='https://github.com/supermihi/lpdec',
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Topic :: Scientific/Engineering :: Mathematics',
],
license='GPL3',
install_requires=requirements,
include_package_data=True,
ext_modules=makeExtensions(),
packages=find_packages(exclude=['test']),
entry_points={'console_scripts': ['{} = lpdec.cli:script'.format(scriptName),]},
test_suite='test',
)