forked from dib-lab/khmer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·188 lines (159 loc) · 6.99 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
#! /usr/bin/env python2
# This file is part of khmer, http://github.com/ged-lab/khmer/, and is
# Copyright (C) Michigan State University, 2009-2013. It is licensed under
# the three-clause BSD license; see doc/LICENSE.txt.
# Contact: [email protected]
""" Setup for khmer project. """
import ez_setup
ez_setup.use_setuptools(version="3.4.1")
import os
import sys
from os import listdir as os_listdir
from os.path import join as path_join
from setuptools import setup
from setuptools import Extension
from setuptools.command.build_ext import build_ext as _build_ext
from distutils.spawn import spawn
from distutils.sysconfig import get_config_vars
from distutils.dist import Distribution
import versioneer
versioneer.versionfile_source = 'khmer/_version.py'
versioneer.versionfile_build = 'khmer/_version.py'
versioneer.tag_prefix = 'v' # tags are like v1.2.0
versioneer.parentdir_prefix = '.'
CMDCLASS = versioneer.get_cmdclass()
# strip out -Wstrict-prototypes; a hack suggested by
# http://stackoverflow.com/a/9740721
# proper fix coming in http://bugs.python.org/issue1222585
# numpy has a "nicer" fix:
# https://github.com/numpy/numpy/blob/master/numpy/distutils/ccompiler.py
OPT = get_config_vars('OPT')[0]
os.environ['OPT'] = " ".join(
flag for flag in OPT.split() if flag != '-Wstrict-prototypes'
)
# We bundle tested versions of zlib & bzip2. To use the system zlib and bzip2
# change setup.cfg or use the `--libraries z,bz2` parameter which will make our
# custom build_ext command strip out the bundled versions.
ZLIBDIR = 'third-party/zlib'
BZIP2DIR = 'third-party/bzip2'
EXTRA_OBJS = []
EXTRA_OBJS.extend(path_join("third-party", "zlib", bn + ".lo") for bn in [
"adler32", "compress", "crc32", "deflate", "gzclose", "gzlib", "gzread",
"gzwrite", "infback", "inffast", "inflate", "inftrees", "trees", "uncompr",
"zutil"])
EXTRA_OBJS.extend(path_join("third-party", "bzip2", bn + ".o") for bn in [
"blocksort", "huffman", "crctable", "randtable", "compress", "decompress",
"bzlib"])
BUILD_DEPENDS = list(EXTRA_OBJS)
BUILD_DEPENDS.extend(path_join("lib", bn + ".hh") for bn in [
"khmer", "khmer_config", "kmer_hash", "hashtable", "counting",
"hashbits", "labelhash"])
SOURCES = ["khmer/_khmermodule.cc"]
SOURCES.extend(path_join("lib", bn + ".cc") for bn in [
"khmer_config", "thread_id_map", "trace_logger", "perf_metrics",
"read_parsers", "kmer_hash", "hashtable", "hashbits", "labelhash",
"counting", "subset", "read_aligner"])
EXTRA_COMPILE_ARGS = ['-O3']
if sys.platform == 'darwin':
EXTRA_COMPILE_ARGS.extend(['-arch', 'x86_64']) # force 64bit only builds
EXTENSION_MOD_DICT = \
{
"sources": SOURCES,
"extra_compile_args": EXTRA_COMPILE_ARGS,
"extra_objects": EXTRA_OBJS,
"depends": BUILD_DEPENDS,
"language": "c++",
"define_macros": [("VERSION", versioneer.get_version()), ],
}
EXTENSION_MOD = Extension("khmer._khmermodule", # pylint: disable=W0142
** EXTENSION_MOD_DICT)
SCRIPTS = []
SCRIPTS.extend([path_join("scripts", script)
for script in os_listdir("scripts")
if script.endswith(".py")])
INSTALL_REQUIRES = ["screed >= 0.7.1"]
try:
import argparse
del argparse
except ImportError:
INSTALL_REQUIRES.append("argparse >= 1.2.1")
SETUP_METADATA = \
{
"name": "khmer",
"version": versioneer.get_version(),
"description": 'khmer k-mer counting library',
"long_description": open("README.rst").read(),
"author": 'Michael R. Crusoe, Greg Edvenson, Jordan Fish,'
' Adina Howe, Luiz Irber, Eric McDonald, Joshua Nahum, Kaben Nanlohy,'
' Humberto Ortiz-Zuazaga, Jason Pell, Jared Simpson, Camille Scott,'
' Ramakrishnan Rajaram Srinivasan, Qingpeng Zhang, and C. Titus Brown',
"author_email": '[email protected]',
# "maintainer": 'Michael R. Crusoe', # this overrides the author field
# "maintainer_email": '[email protected]', # so don't include it
# http://docs.python.org/2/distutils/setupscript.html
# additiona-meta-data note #3
"url": 'http://ged.msu.edu/',
"packages": ['khmer', 'khmer.tests'],
"package_dir": {'khmer.tests': 'tests'},
"install_requires": INSTALL_REQUIRES,
"extras_require": {'docs': ['sphinx', 'sphinxcontrib-autoprogram'],
'tests': ['nose >= 1.0']},
"scripts": SCRIPTS,
"ext_modules": [EXTENSION_MOD, ],
# "platforms": '', # empty as is conveyed by the classifiers below
# "license": '', # empty as is conveyed by the classifier below
"include_package_data": True,
"zip_safe": False,
"classifiers": [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Environment :: MacOS X",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Natural Language :: English",
"Operating System :: POSIX :: Linux",
"Operating System :: MacOS :: MacOS X",
"Programming Language :: C",
"Programming Language :: C++",
"Programming Language :: Python :: 2.7",
"Topic :: Scientific/Engineering :: Bio-Informatics",
],
}
class KhmerBuildExt(_build_ext): # pylint: disable=R0904
"""Specialized Python extension builder for khmer project.
Only run the library setup when needed, not on every invocation.
Also strips out the bundled zlib and bzip2 libraries if
`--libraries z,bz2` is specified or the equivalent is in setup.cfg
"""
def run(self):
if "z" and "bz2" not in self.libraries:
zcmd = ['bash', '-c', 'cd ' + ZLIBDIR + ' && ( test Makefile -nt'
' configure || bash ./configure --static ) && make -f '
'Makefile.pic PIC']
spawn(cmd=zcmd, dry_run=self.dry_run)
bz2cmd = ['bash', '-c', 'cd ' + BZIP2DIR + ' && make -f '
'Makefile-libbz2_so all']
spawn(cmd=bz2cmd, dry_run=self.dry_run)
else:
for ext in self.extensions:
ext.extra_objects = []
_build_ext.run(self)
CMDCLASS.update({'build_ext': KhmerBuildExt})
_DISTUTILS_REINIT = Distribution.reinitialize_command
def reinitialize_command(self, command, reinit_subcommands):
'''
Monkeypatch distutils.Distribution.reinitialize_command() to match behavior
of Distribution.get_command_obj()
This fixes issues with 'pip install -e' and './setup.py nosetests' not
respecting the setup.cfg configuration directives for the build_ext command
'''
cmd_obj = _DISTUTILS_REINIT(self, command, reinit_subcommands)
options = self.command_options.get(command)
if options:
self._set_command_options( # pylint: disable=protected-access
cmd_obj, options)
return cmd_obj
Distribution.reinitialize_command = reinitialize_command
# pylint: disable=W0142
setup(cmdclass=CMDCLASS,
**SETUP_METADATA)