forked from mdrasmus/argweaver
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsetup.py
159 lines (130 loc) · 4.4 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
#!/usr/bin/env python
#
# setup for the ARGweaver library package
#
# use the following to install:
# python setup.py install
#
from distutils import log
from distutils.core import Command
from distutils.core import Extension
from distutils.core import setup
from distutils.command.build import build as _build
from distutils.command.build_clib import build_clib as _build_clib
from distutils.dep_util import newer_group
from distutils.sysconfig import customize_compiler
import os
import argweaver
VERSION = argweaver.PROGRAM_VERSION_TEXT
def get_files(path, ext=''):
"""
Get all files in a directory with a extension.
"""
files = []
for filename in os.listdir(path):
if filename.endswith(ext):
files.append(os.path.join(path, filename))
return files
scripts = get_files('bin')
lib_src = get_files('src/argweaver', '.cpp')
# Default to a C++ compiler, if possible.
if os.system('which g++') == 0:
os.environ.setdefault('CC', 'g++')
os.environ.setdefault('CXX', 'g++')
class build(_build):
"""
Add more subcommands to the build command.
"""
sub_commands = _build.sub_commands + [('build_prog', lambda cmd: True)]
class build_prog(_build_clib):
"""
Build subcommand for compiling programs.
This is implemented as subclass of build_clib since compiling a
C/C++ program is very similar to compiling C/C++ library.
"""
description = 'build compiled programs'
# Config. Ideally, we could add this to setup().
progs = [
(
'arg-sample',
{
'sources': lib_src + ['src/arg-sample.cpp'],
}
),
(
'arg-summarize',
{
'sources': lib_src + ['src/arg-summarize.cpp'],
}
),
(
'smc2bed',
{
'sources': lib_src + ['src/smc2bed.cpp'],
}
),
]
def initialize_options(self):
# Call super class.
_build_clib.initialize_options(self)
# Directory for built binaries.
self.build_bin = None
def finalize_options(self):
# Call super class.
_build_clib.finalize_options(self)
self.set_undefined_options('build', ('build_scripts', 'build_bin'))
self.libraries = self.progs
if self.libraries:
self.check_library_list(self.libraries)
def build_libraries(self, libraries):
if not os.path.exists(self.build_bin):
os.makedirs(self.build_bin)
for (prog_name, build_info) in libraries:
sources = build_info.get('sources')
if sources is None or not isinstance(sources, (list, tuple)):
raise DistutilsSetupError, \
("in 'libraries' option ('%s'), " +
"'sources' must be present and must be " +
"a list of source filenames") % prog_name
sources = list(sources)
# Skip build, if program already built.
prog_path = os.path.join(self.build_bin, prog_name)
if not (self.force or newer_group(sources, prog_path, 'newer')):
log.debug("skipping '%s' program (up-to-date)", prog_name)
return
log.info("building '%s' program", prog_name)
macros = build_info.get('macros')
include_dirs = build_info.get('include_dirs')
objects = self.compiler.compile(sources,
output_dir=self.build_temp,
macros=macros,
include_dirs=include_dirs,
debug=self.debug)
self.compiler.link_executable(objects, prog_name,
output_dir=self.build_bin,
debug=self.debug)
setup(
name='argweaver',
version=VERSION,
description='Ancestral recombination graph sampling method',
long_description = """
""",
author='Matt Rasmussen',
author_email='[email protected]',
cmdclass={
'build': build,
'build_prog': build_prog,
},
packages=[
'argweaver',
'argweaver.deps.rasmus',
'argweaver.deps.compbio',
],
scripts=scripts,
ext_modules=[
Extension(
'libargweaver',
lib_src,
)
],
)