-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathsetup.py
256 lines (221 loc) · 7.69 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#!/usr/bin/env python
from __future__ import print_function
import sys
import os
from distutils.log import INFO as logINFO
if ((sys.version_info[0] == 2 and sys.version_info[1] < 7) or
(sys.version_info[0] == 3 and sys.version_info[1] < 5)):
sys.stderr.write("Error in setup script for HTSeq:\n")
sys.stderr.write("HTSeq support Python 2.7 or 3.5+.")
sys.exit(1)
# Manage python2/3 compatibility with symlinks
py_maj = sys.version_info[0]
py_fdn = 'python'+str(py_maj)+'/'
print('symlinking folders for python'+str(py_maj))
for fdn in ['src', 'HTSeq', 'doc', 'scripts', 'test']:
if os.path.islink(fdn):
os.unlink(fdn)
os.symlink(py_fdn+fdn, fdn)
# Update version from VERSION file into module
with open('VERSION') as fversion:
version = fversion.readline().rstrip()
with open(py_fdn+'HTSeq/_version.py', 'wt') as fversion:
fversion.write('__version__ = "'+version+'"')
# Check OS-specific quirks
try:
from setuptools import setup, Extension
from setuptools.command.build_py import build_py
from setuptools import Command
# Setuptools but not distutils support build/runtime/optional dependencies
# NOTE: setuptools < 18.0 has issues with Cython as a dependency
# NOTE: old setuptools < 18.0 has issues with extras
kwargs = dict(
setup_requires=[
'Cython',
'numpy',
'pysam>=0.9.0',
],
install_requires=[
'numpy',
'pysam>=0.9.0',
],
extras_require={
'htseq-qa': ['matplotlib>=1.4']
},
)
except ImportError:
sys.stderr.write("Could not import 'setuptools'," +
" falling back to 'distutils'.\n")
from distutils.core import setup, Extension
from distutils.command.build_py import build_py
from distutils.cmd import Command
kwargs = dict(
requires=[
'Cython',
'numpy',
'pysam>=0.9.0',
]
)
try:
import numpy
except ImportError:
sys.stderr.write("Setup script for HTSeq: Failed to import 'numpy'.\n")
sys.stderr.write("Please install numpy and then try again to install" +
" HTSeq.\n")
sys.exit(1)
numpy_include_dir = os.path.join(
os.path.dirname(numpy.__file__),
'core',
'include',
)
def get_include_dirs(cpp=False):
'''OSX 10.14 and later split the /usr/include contents everywhere'''
include_dirs = []
if sys.platform != 'darwin':
return include_dirs
paths = {
'C': [
'/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/',
],
'C++': [
'/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/',
],
}
for path in paths['C']:
if os.path.isdir(path):
include_dirs.append(path)
if cpp:
for path in paths['C++']:
if os.path.isdir(path):
include_dirs.append(path)
return include_dirs
def get_library_dirs_cpp():
'''OSX 10.14 and later messed up C/C++ library locations'''
if sys.platform == 'darwin':
return ['/usr/X11R6/lib']
else:
return []
def get_extra_args_cpp():
'''OSX 101.14 and later refuses to use libstdc++'''
if sys.platform == 'darwin':
return ['-stdlib=libc++']
else:
return []
class Preprocess_command(Command):
'''Cython and SWIG preprocessing'''
description = "preprocess Cython and SWIG files for HTSeq"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
self.swig_and_cython()
def swig_and_cython(self):
import os
from shutil import copy
from subprocess import check_call
if py_maj == 2:
from subprocess import CalledProcessError as SubprocessError
else:
from subprocess import SubprocessError
def c(x): return check_call(x, shell=True)
def p(x): return self.announce(x, level=logINFO)
# CYTHON
p('cythonizing')
cython = os.getenv('CYTHON', 'cython')
try:
c(cython+' --version')
except SubprocessError:
if os.path.isfile('src/_HTSeq.c'):
p('Cython not found, but transpiled file found')
else:
raise
else:
if py_maj == 2:
c(cython+' '+py_fdn+'src/HTSeq/_HTSeq.pyx -o '+py_fdn+'src/_HTSeq.c')
else:
c(cython+' -3 '+py_fdn+'src/HTSeq/_HTSeq.pyx -o '+py_fdn+'src/_HTSeq.c')
# SWIG
p('SWIGging')
swig = os.getenv('SWIG', 'swig')
pyswigged = py_fdn+'src/StepVector.py'
try:
if py_maj == 2:
c(swig+' -Wall -c++ -python '+py_fdn+'src/StepVector.i')
else:
p('correcting SWIG for python3')
c("2to3 --no-diffs --write --nobackups "+pyswigged)
c("sed -i 's/ import builtins as __builtin__/ import builtins/' "+pyswigged)
c("sed -i 's/\.next/.__next__/' "+pyswigged)
except SubprocessError:
if (os.path.isfile(py_fdn+'src/StepVector_wrap.cxx') and
os.path.isfile(py_fdn+'src/StepVector.py')):
p('SWIG not found, but transpiled files found')
else:
raise
p('moving swigged .py module')
copy(pyswigged, py_fdn+'HTSeq/StepVector.py')
p('done')
class Build_with_preprocess(build_py):
def run(self):
self.run_command('preprocess')
build_py.run(self)
setup(name='HTSeq',
version=version,
author='Simon Anders, Fabio Zanini',
author_email='sanders@fs.tum.de',
maintainer='Fabio Zanini',
maintainer_email='fabio.zanini@stanford.edu',
url='https://github.com/simon-anders/htseq',
description="A framework to process and analyze data from " +
"high-throughput sequencing (HTS) assays",
long_description="""
A framework to process and analyze data from high-throughput sequencing
(HTS) assays.
Development: https://github.com/simon-anders/htseq
Documentation: http://htseq.readthedocs.io""",
license='GPL3',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Topic :: Scientific/Engineering :: Bio-Informatics',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: GNU General Public License (GPL)',
'Operating System :: POSIX',
'Programming Language :: Python'
],
ext_modules=[
Extension(
'HTSeq._HTSeq',
['src/_HTSeq.c'],
include_dirs=[numpy_include_dir]+get_include_dirs(),
extra_compile_args=['-w']),
Extension(
'HTSeq._StepVector',
['src/StepVector_wrap.cxx'],
include_dirs=get_include_dirs(cpp=True),
library_dirs=get_library_dirs_cpp(),
extra_compile_args=['-w'] + get_extra_args_cpp(),
extra_link_args=get_extra_args_cpp(),
),
],
py_modules=[
'HTSeq._HTSeq_internal',
'HTSeq.StepVector',
'HTSeq._version',
'HTSeq.scripts.qa',
'HTSeq.scripts.count',
'HTSeq.scripts.count_with_barcodes',
],
scripts=[
'scripts/htseq-qa',
'scripts/htseq-count',
'scripts/htseq-count-barcodes',
],
cmdclass={
'preprocess': Preprocess_command,
'build_py': Build_with_preprocess,
},
**kwargs
)