-
Notifications
You must be signed in to change notification settings - Fork 14
/
setup.py
169 lines (135 loc) · 5.04 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
import sys
from setuptools import setup, find_packages, Extension as _Extension
# With gratitude to the SqlAlchemy setup.py authors
from distutils.command.build_ext import build_ext
from distutils.errors import (CCompilerError, DistutilsExecError,
DistutilsPlatformError)
ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
if sys.platform == 'win32':
# 2.6's distutils.msvc9compiler can raise an IOError when failing to
# find the compiler
ext_errors += (IOError,)
def Extension(*args, **kwargs):
ext = _Extension(*args, **kwargs)
ext.include_dirs.append("src/glypy/_c/")
return ext
try:
from Cython.Build import cythonize
extensions = cythonize(
[Extension("glypy.composition.ccomposition", ["src/glypy/composition/ccomposition.pyx"]),
Extension("glypy.utils.cenum", ['src/glypy/utils/cenum.pyx']),
Extension("glypy._c.utils", ["src/glypy/_c/utils.pyx"]),
Extension("glypy._c.structure.glycan_composition", [
"src/glypy/_c/structure/glycan_composition.pyx"]),
],
annotate=True)
except (ImportError, AttributeError):
print("No Cython")
extensions = [
Extension('glypy.composition.ccomposition', sources=[
'src/glypy/composition/ccomposition.c']),
Extension("glypy.utils.cenum", ['src/glypy/utils/cenum.c']),
Extension("glypy._c.utils", ["src/glypy/_c/utils.c"]),
Extension("glypy._c.structure.glycan_composition", [
"src/glypy/_c/structure/glycan_composition.c"]),
]
cmdclass = {}
with open("src/glypy/version.py") as version_file:
version = None
for line in version_file.readlines():
if "version = " in line:
version = line.split(" = ")[1].replace("\"", "").strip()
break
else:
print("Cannot determine version")
long_description = ''
try:
with open("README.rst") as readme_file:
long_description = readme_file.read()
except Exception:
pass
class BuildFailed(Exception):
def __init__(self):
self.cause = sys.exc_info()[1] # work around py 2/3 different syntax
def __str__(self):
return str(self.cause)
class ve_build_ext(build_ext):
# This class allows C extension building to fail.
def run(self):
try:
build_ext.run(self)
except DistutilsPlatformError:
raise BuildFailed()
def build_extension(self, ext):
try:
build_ext.build_extension(self, ext)
except ext_errors:
raise BuildFailed()
except ValueError:
# this can happen on Windows 64 bit, see Python issue 7511
if "'path'" in str(sys.exc_info()[1]): # works with both py 2/3
raise BuildFailed()
raise
cmdclass['build_ext'] = ve_build_ext
def status_msgs(*msgs):
print('*' * 75)
for msg in msgs:
print(msg)
print('*' * 75)
required = ["hjson", "six"]
extras = {
'plot': ["matplotlib>=2.2.0"],
'glyspace': ['requests', 'rdflib', "SPARQLWrapper"]
}
extras['all'] = list({d for extra in extras.values() for d in extra})
def run_setup(include_cext=True):
setup(
name='glypy',
version=version,
packages=find_packages(where='src'),
package_dir={"": 'src'},
include_package_data=True,
package_data={
"glypy.structure": ["src/glypy/structure/data/*"],
"glypy.io": ["src/glypy/io/data/*"],
"glypy.io.nomenclature": ["src/glypy/io/nomenclature/data/*"],
},
install_requires=required,
extras_require=extras,
cmdclass=cmdclass,
zip_safe=False,
keywords="glycomics glycan carbohydrate glycoinformatics glypy n-linked o-linked glycosaminoglycan",
description="A Glycoinformatics Toolkit",
long_description=long_description,
ext_modules=extensions if include_cext else None,
url="https://github.com/mobiusklein/glypy",
maintainer='Joshua Klein',
maintainer_email="[email protected]",
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: Apache Software License',
'Topic :: Scientific/Engineering :: Bio-Informatics',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3'],
project_urls={
"Documentation": "https://glypy.readthedocs.io/",
"Repository": "https://github.com/mobiusklein/glypy",
}
)
try:
run_setup(True)
except Exception as exc:
status_msgs(
str(exc),
"WARNING: The C extension could not be compiled, " +
"speedups are not enabled.",
"Failure information, if any, is above.",
"Retrying the build without the C extension now."
)
run_setup(False)
status_msgs(
"WARNING: The C extension could not be compiled, " +
"speedups are not enabled.",
"Plain-Python build succeeded."
)