forked from opencobra/cobrapy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
190 lines (172 loc) · 7.13 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
# -*- coding: utf-8 -*-
from os.path import abspath, dirname, isfile, join
from sys import argv
from warnings import warn
from setuptools import setup, find_packages
# cython is optional for building. The c file can be used directly. However,
# for certain functions, the c file must be generated, which requires cython.
try:
from Cython.Build import cythonize
from distutils.version import StrictVersion
import Cython
try:
cython_version = StrictVersion(Cython.__version__)
except ValueError:
raise ImportError("Cython version not parseable")
else:
if cython_version < StrictVersion("0.21"):
raise ImportError("Cython version too old to use")
except ImportError:
cythonize = None
for k in ["sdist", "develop"]:
if k in argv:
raise Exception("Cython >= 0.21 required for " + k)
# Begin constructing arguments for building
setup_kwargs = {}
# for building the cglpk solver
try:
from distutils.extension import Extension
from distutils.command.build_ext import build_ext
from os import name
from platform import system
class FailBuild(build_ext):
"""allow building of the C extension to fail"""
def run(self):
try:
build_ext.run(self)
except Exception as e:
warn(e)
def build_extension(self, ext):
try:
build_ext.build_extension(self, ext)
except:
None
build_args = {}
setup_kwargs["cmdclass"] = {"build_ext": FailBuild}
# MAC OS X needs some additional configuration tweaks
# Build should be run with the python.org python
# Cython will output C which could generate warnings in clang
# due to the addition of additional unneeded functions. Because
# this is a known phenomenon, these warnings are silenced to
# make other potential warnings which do signal errors stand
# out.
if system() == "Darwin":
build_args["extra_compile_args"] = ["-Wno-unused-function"]
build_args["libraries"] = ["glpk"]
# It is possible to statically link libglpk to the built extension. This
# allows for simplified installation without the need to install libglpk to
# the system, and is also usueful when installing a particular version of
# glpk which conflicts with thesystem version. A static libglpk.a can be
# built by running configure with the export CLFAGS="-fPIC" and copying the
# file from src/.libs to either the default lib directory or to the build
# directory. For an example script, see
# https://gist.github.com/aebrahim/94a2b231d86821f7f225
include_dirs = []
library_dirs = []
if isfile("libglpk.a"):
library_dirs.append(abspath("."))
if isfile("glpk.h"):
include_dirs.append(abspath("."))
# if the glpk files are not in the current directory attempt to
# auto-detect their location by finding the location of the glpsol
# command
if name == "posix" and len(include_dirs) == 0 and len(library_dirs) == 0:
from subprocess import check_output
try:
glpksol_path = check_output(["which", "glpsol"],
universal_newlines=True).strip()
glpk_path = abspath(join(dirname(glpksol_path), ".."))
include_dirs.append(join(glpk_path, "include"))
library_dirs.append(join(glpk_path, "lib"))
except Exception as e:
print('Could not autodetect include and library dirs: ' + str(e))
if len(include_dirs) > 0:
build_args["include_dirs"] = include_dirs
if len(library_dirs) > 0:
build_args["library_dirs"] = library_dirs
# use cython if present, otherwise use c file
if cythonize:
ext_modules = cythonize([Extension("cobra.solvers.cglpk",
["cobra/solvers/cglpk.pyx"],
**build_args)],
force=True)
else:
ext_modules = [Extension("cobra.solvers.cglpk",
["cobra/solvers/cglpk.c"], **build_args)]
except Exception as e:
print('Could not build CGLPK: {}'.format(e))
ext_modules = None
setup_requirements = []
# prevent pytest-runner from being installed on every invocation
if {'pytest', 'test', 'ptr'}.intersection(argv):
setup_requirements.append("pytest-runner")
extras = {
'matlab': ["pymatbridge"],
'sbml': ["python-libsbml", "lxml"],
'array': ["scipy>=0.11.0"],
'display': ["matplotlib", "palettable"]
}
all_extras = {'Cython>=0.21'}
for extra in extras.values():
all_extras.update(extra)
extras["all"] = sorted(list(all_extras))
# If using bdist_wininst, the installer will not get dependencies like
# a setuptools installation does. Therefore, for the one external dependency,
# which is six.py, we can just download it here and include it in the
# installer.
# The file six.py will need to be manually downloaded and placed in the
# same directory as setup.py.
if "bdist_wininst" in argv:
setup_kwargs["py_modules"] = ["six"]
try:
with open('README.rst') as handle:
readme = handle.read()
with open('INSTALL.rst') as handle:
install = handle.read()
setup_kwargs["long_description"] = readme + "\n\n" + install
except:
setup_kwargs["long_description"] = ''
setup(
name="cobra",
version="0.8.2",
packages=find_packages(),
setup_requires=setup_requirements,
install_requires=["future", "swiglpk", "optlang>=1.2.1",
"ruamel.yaml<0.15",
"pandas>=0.17.0", "numpy>=1.6", "tabulate"],
tests_require=["jsonschema > 2.5", "pytest", "pytest-benchmark"],
extras_require=extras,
ext_modules=ext_modules,
package_data={
'': ['test/data/*',
'mlab/matlab_scripts/*m']},
author="The cobrapy core team",
author_email="[email protected]",
description="COBRApy is a package for constraints-based modeling of "
"biological networks",
license="LGPL/GPL v2+",
keywords="metabolism biology linear programming optimization flux"
" balance analysis fba",
url="https://opencobra.github.io/cobrapy",
test_suite="cobra.test.suite",
download_url='https://pypi.python.org/pypi/cobra',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: GNU Lesser General Public License v2'
' or later (LGPLv2+)',
'License :: OSI Approved :: GNU General Public License v2'
' or later (GPLv2+)',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Cython',
'Programming Language :: Python :: Implementation :: CPython',
'Topic :: Scientific/Engineering',
'Topic :: Scientific/Engineering :: Bio-Informatics'
],
platforms="GNU/Linux, Mac OS X >= 10.7, Microsoft Windows >= 7",
**setup_kwargs)