-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup.py
executable file
·146 lines (128 loc) · 4.61 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
import glob
import io
from pathlib import Path
from setuptools import setup
import sys
import platform
from distutils.core import Extension
from distutils.ccompiler import new_compiler
from Cython.Build import cythonize
EXTRA_COMPILE_ARGS = []
EXTRA_LINK_ARGS = []
if sys.platform == 'linux':
EXTRA_COMPILE_ARGS += ['-std=c++11', '-I/usr/include', '-O2']
elif sys.platform == "darwin":
EXTRA_COMPILE_ARGS += [
"-stdlib=libc++",
"-std=c++11",
"-O2",
"-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1",
"-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
]
EXTRA_LINK_ARGS += [
"-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib",
]
elif sys.platform == "win32":
EXTRA_COMPILE_ARGS += ['/std:c++14', '/O2']
if platform.machine() == 'x86_64':
EXTRA_COMPILE_ARGS += ['-mavx', '-mavx2']
def flatten(*lists):
return [str(x) for sublist in lists for x in sublist]
def build_zlib():
''' compile zlib code to object files for linking with bgen on windows
Returns:
list of paths to compiled object code
'''
include_dirs = ['src/zlib/']
sources = list(glob.glob('src/zlib/*.c'))
extra_compile_args = ['/O2']
cc = new_compiler()
return cc.compile(sources, include_dirs=include_dirs,
extra_preargs=extra_compile_args)
def build_zstd():
''' compile zstd code to object files for linking with bgen c++ code
This needs to be compiles independently of the bgen c++ code, as zstd is in
c, so cannot be compiled directly with the bgen code. zstd is compiled to
object files, and these are staticly linked in with the bgen code.
I tried to link to a shared/dynamic zstd library, but couldn't specify a
location that would be found by the compiled bgen library after relocating
files into to a python package.
Returns:
list of paths to compiled object code
'''
print('building zstd')
folder = Path('src/zstd/lib')
include_dirs = ['src/zstd/lib/', 'src/zstd/lib/common']
sources = flatten(
(folder / 'common').glob('*.c'),
(folder / 'compress').glob('*.c'),
(folder / 'decompress').glob('*.c'),
(folder / 'dictBuilder').glob('*.c'),
(folder / 'deprecated').glob('*.c'),
(folder / 'legacy').glob('*.c'), # TODO: drop some legacy versions
)
extra_compile_args = ['-std=gnu11', '-fPIC', '-O2']
# newer zstd versions have an asm file, which needs to be to compiled and
# used as a library for full zstd compilation.
cc = new_compiler()
# the unix compiler needs to allow files with .S extension
cc.src_extensions += ['.S']
compiled = cc.compile(sources=flatten((folder / 'decompress').glob('*.S')),)
if len(compiled) > 0:
extra_compile_args += [f'-L{" ".join(compiled)}']
return cc.compile(sources, include_dirs=include_dirs,
extra_preargs=extra_compile_args) + compiled
if sys.platform == 'win32':
zlib, libs = build_zlib(), []
else:
zlib, libs = [], ['z']
zstd = build_zstd()
ext = cythonize([
Extension('bgen.reader',
extra_compile_args=EXTRA_COMPILE_ARGS,
extra_link_args=EXTRA_LINK_ARGS,
sources=['src/bgen/reader.pyx',
'src/reader.cpp',
'src/genotypes.cpp',
'src/header.cpp',
'src/samples.cpp',
'src/utils.cpp',
'src/variant.cpp'],
extra_objects=zstd + zlib,
include_dirs=['src', 'src/zstd/lib', 'src/zlib'],
libraries=libs,
language='c++'),
Extension('bgen.writer',
extra_compile_args=EXTRA_COMPILE_ARGS,
extra_link_args=EXTRA_LINK_ARGS,
sources=['src/bgen/writer.pyx',
'src/writer.cpp',
'src/genotypes.cpp',
'src/utils.cpp',
],
extra_objects=zstd + zlib,
include_dirs=['src', 'src/zstd/lib', 'src/zlib'],
libraries=libs,
language='c++'),
])
setup(name='bgen',
description='Package for loading data from bgen files',
long_description=io.open('README.md', encoding='utf-8').read(),
long_description_content_type='text/markdown',
version='1.7.3',
author='Jeremy McRae',
author_email='[email protected]',
license="MIT",
url='https://github.com/jeremymcrae/bgen',
packages=['bgen'],
package_dir={'': 'src'},
install_requires=[
'numpy',
],
classifiers=[
'Development Status :: 4 - Beta',
'Topic :: Scientific/Engineering :: Bio-Informatics',
],
ext_modules=ext,
test_loader='unittest:TestLoader',
)