-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup.py
219 lines (189 loc) · 7.38 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
'''
Created on 25/03/2009
@author: jose blanca
'''
#taken from django-tagging
import imp
import os, sys, glob, fnmatch
from distutils.core import setup, Command
from distutils.command.build import build
import franklin
import shutil
TOOL = None
def opj(*args):
path = os.path.join(*args)
return os.path.normpath(path)
def find_data_files(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 wc in wildcards:
wc_name = opj(dirname, wc)
for f in files:
filename = opj(dirname, f)
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 check_modules(modules):
'It check the modules needed'
all_optionals = True
for module_name, module_info in modules.items():
try:
# we use this and not a simple import because matpliotlib writes
# a directory in the first import. with posible wrong permissions
imp.find_module(module_name)
except ImportError:
if 'required' in module_info and module_info['required']:
print '%s is required and is not installed for %s' % \
(module_name, sys.executable)
print "Instalation Aborted"
sys.exit(1)
print "%s is not installed, %s" % (module_name, module_info['msg'])
all_optionals = False
if not all_optionals:
msg = 'Some optional requirements were not met, do you want to continue'
msg += ' the installation (y/n)? '
answer = raw_input(msg)
if answer.lower() not in ('y', 'yes'):
print 'Installation aborted'
sys.exit()
def fullsplit(path, result=None):
"""
Split a pathname into components (the opposite of os.path.join) in a
platform-neutral way.
"""
if result is None:
result = []
head, tail = os.path.split(path)
if head == '':
return [tail] + result
if head == path:
return result
return fullsplit(head, [tail] + result)
def _guess_packages(directory):
# Compile the list of packages available, because distutils doesn't have
# an easy way to do this.
packages, data_files, modules = [], [], []
pieces = fullsplit(directory)
if pieces[-1] == '':
len_root_dir = len(pieces) - 1
else:
len_root_dir = len(pieces)
for dirpath, dirnames, filenames in os.walk(os.path.join(directory,
PACKAGE_DIR)):
if '__init__.py' in filenames:
package = '.'.join(fullsplit(dirpath)[len_root_dir:])
packages.append(package)
for filename in os.listdir(dirpath):
if (filename.startswith('.') or filename.startswith('_') or
not filename.endswith('.py')):
continue
modules.append(package + '.' + filename)
elif filenames:
data_files.append([dirpath, [os.path.join(dirpath, f) for f in filenames]])
return packages
def _guess_scripts(directory, wanted_scripts):
scripts = []
for dirpath, dirnames, filenames in os.walk(os.path.join(root_dir,
SCRIPTS_DIR)):
for filename in filenames:
if filename in wanted_scripts:
scripts.append(os.path.join(dirpath, filename))
return scripts
import distutils.command.install_data
#Taken from http://wiki.python.org/moin/Distutils/Tutorial
# Specializations of some distutils command classes
## Code borrowed from wxPython's setup and config files
## I am not 100% sure what's going on, but it works!
class wx_smart_install_data(distutils.command.install_data.install_data):
"""need to change self.install_dir to the actual library dir"""
def run(self):
install_cmd = self.get_finalized_command('install')
self.install_dir = getattr(install_cmd, 'install_lib')
return distutils.command.install_data.install_data.run(self)
# a class to build the manpage
class install_manpages(Command):
'it builds the man page '
description = 'Install man page.'
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
'Build and install the manpage'
prefix = sys.prefix
man_dir = os.path.join(prefix, 'share', 'man', 'man1')
if not os.path.exists(man_dir):
os.makedirs(man_dir)
root_dir = os.path.dirname(__file__)
doc_man_dir = os.path.join(root_dir, 'doc', 'man')
if not os.path.exists(doc_man_dir):
return
for man in os.listdir(doc_man_dir):
origin = os.path.join(doc_man_dir, man)
dest = os.path.join(man_dir, man)
shutil.copy(origin, dest)
build.sub_commands.append(('install_manpage', None))
def _guess_installing_program():
'Looking at the directory it guess the program that we are installing'
if TOOL:
return TOOL
dirname = os.path.dirname(os.path.abspath(__file__))
working_dir_name = dirname.split(os.path.sep)[-1]
# remove version
return working_dir_name.split('-', 1)[0]
PACKAGE_DIR = 'franklin'
SCRIPTS_DIR = 'scripts'
#dependencies
MODULES= {'ngs_backbone': {'Bio': {'required': True},
'configobj': {'required': True},
'pysam': {'msg':'SNP calling will fail'},
'matplotlib': {'msg':'some statistics will fail'},
'psubprocess':{'msg':'no parallel processing will be possible'}},
'clean_reads': {'Bio': {'required': True}}
}
#which program are we installing:
program = _guess_installing_program()
if program not in MODULES.keys():
program = 'ngs_backbone'
# check module dependencies
check_modules(MODULES[program])
root_dir = os.path.dirname(__file__)
packages = _guess_packages(root_dir)
wanted_scripts = ['backbone_analysis.py', 'seqio.py',
'backbone_create_project.py', 'clean_reads']
scripts = _guess_scripts(root_dir, wanted_scripts)
data_files = find_data_files('ext', '*')
dist = setup(
# basic package data
name = "franklin",
version = franklin.__version__,
author ='Jose Blanca, Peio Ziarsolo',
author_email ='jblanca@upv.es',
description ='Some genomics related classes',
# package structure
include_package_data = True,
packages=packages,
package_dir={'':'.'},
package_data={'': ['data/*/*']},
data_files = data_files,
cmdclass = { 'install_data': wx_smart_install_data,
'install_manpage':install_manpages },
requires=['BioPython', 'matplotlib', 'configobj',
'pysam', 'psubprocess'],
scripts=scripts,
)