-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsetup.py
196 lines (159 loc) · 6.46 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
# Copyright 2012 Jose Blanca, Peio Ziarsolo, COMAV-Univ. Politecnica Valencia
# This file is part of seq_crumbs.
# seq_crumbs is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
# seq_crumbs is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with seq_crumbs. If not, see <http://www.gnu.org/licenses/>.
import sys
from sys import version_info
import os
import fnmatch
import glob
import platform
import subprocess
import distutils.command.install_data
try:
from setuptools import setup
from setuptools.command import install
_SETUPTOOLS = True
except ImportError:
from distutils.core import setup
from distutils.command import install
_SETUPTOOLS = False
#print "using_setuptools", _SETUPTOOLS
# The next three lines are modified from Biopython
__version__ = "Undefined"
for line in open('crumbs/__init__.py'):
if (line.startswith('__version__')):
exec(line.strip())
break
def check_biopython():
'If a Biopython is not installed it recommends to do so'
if _SETUPTOOLS:
return # No need to check anything because it will get installed
msg = None
try:
import Bio
except ImportError:
msg = 'For some functionalities Bioypython >= 1.60\n is required'
if not msg:
try:
from Bio.bgzf import BgzfWriter
except ImportError:
msg = 'You have an old version of Biopython installed, '
msg += 'please update to >= 1.60\n'
if not msg:
return
sys.stderr.write(msg)
sys.exit(-1)
check_biopython()
def opj(*args):
path = os.path.join(*args)
return os.path.normpath(path)
def find_data_file(srcdir, *wildcards, **kw):
# get a list of all files under the srcdir matching wildcards,
# returned in a format to be used for install_data
def walk_helper(arg, dirname, files):
if '.svn' in dirname or '.git' in dirname:
return
names = []
lst, wildcards = arg
for wildcard in wildcards:
wc_name = opj(dirname, wildcard)
for fpath in files:
filename = opj(dirname, fpath)
if (fnmatch.fnmatch(filename, wc_name) and
not os.path.isdir(filename)):
names.append(filename)
if names:
lst.append((dirname, names))
file_list = []
recursive = kw.get('recursive', True)
if recursive:
os.path.walk(srcdir, walk_helper, (file_list, wildcards))
else:
walk_helper((file_list, wildcards),
srcdir,
[os.path.basename(f) for f in glob.glob(opj(srcdir, '*'))])
return file_list
def get_platform_bin_dir():
'''It returns the platform specific bindir. It returns the relative path
from the source code root dir'''
system = platform.system().lower()
arch = platform.architecture()[0]
return os.path.join('crumbs', 'third_party', 'bin', system, arch)
platform_bin_dir = get_platform_bin_dir()
external_executables = find_data_file(platform_bin_dir, '*')
def get_scripts():
scripts = []
for file_ in os.listdir('bin'):
if not file_.endswith('.error'):
scripts.append(os.path.join('bin', file_))
return scripts
class SmartInstall(install.install):
def run(self):
result = install.install.run(self)
install_cmd = self.get_finalized_command('install')
self.install_dir = getattr(install_cmd, 'install_lib')
# install the manpages
# check we have rst2man
try:
import docutils
have_rst2man = True
except ImportError:
have_rst2man = False
man_dir = os.path.join(sys.prefix, 'share/man/man1')
if have_rst2man:
if not os.path.exists(man_dir):
os.makedirs(man_dir)
for fpath in os.listdir('doc'):
if not fpath.endswith('.rst'):
continue
rst_fpath = os.path.join('doc', fpath)
man_fpath = os.path.join(man_dir,
os.path.splitext(fpath)[0] + '.1')
#print 'generating manpage: ', man_fpath
subprocess.call(['rst2man.py', rst_fpath, man_fpath])
return result
class InstallData(distutils.command.install_data.install_data):
"""need to change self.install_dir to the actual library dir"""
def run(self):
'''It modifies the place in which the thrid_party_binaries will be
installed.'''
install_cmd = self.get_finalized_command('install')
self.install_dir = getattr(install_cmd, 'install_lib')
return distutils.command.install_data.install_data.run(self)
with open('README.rst') as file_:
long_description = file_.read()
setup_args = {'name': 'ngs_crumbs',
'version': __version__,
'description': 'Small utilities for NGS files manipulation',
'long_description': long_description,
'author': 'Jose Blanca & Peio Ziarsolo',
'author_email': '[email protected]',
'url': 'http://bioinf.comav.upv.es/ngs_crumbs/',
'packages': ['crumbs', 'crumbs.third_party', 'crumbs.utils',
'crumbs.seq', 'crumbs.bam', 'crumbs.vcf'],
'include_package_data': True,
'data_files': external_executables,
'scripts': get_scripts(),
'license': 'AGPL',
'cmdclass': {'install': SmartInstall,
'install_data': InstallData}
}
if _SETUPTOOLS:
setup_args['install_requires'] = ['biopython >= 1.60', 'configobj',
'toolz', 'pysam>=0.8', 'rpy2',
'matplotlib']
if version_info[0] < 3 or (version_info[0] == 3 and version_info[1] < 3):
# until python 3.3 the standard file module has no support for
# wrapping file object and required to open a new file
# bz2file is a backport of the python 3.3 std library module
setup_args['install_requires'].append('bz2file')
setup(**setup_args)