forked from scikit-bio/scikit-bio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
192 lines (162 loc) · 5.13 KB
/
setup.py
File metadata and controls
192 lines (162 loc) · 5.13 KB
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
#!/usr/bin/env python
"""Setup script for scikit-bio installation.
----------------------------------------------------------------------------
Copyright (c) 2013--, scikit-bio development team.
Distributed under the terms of the Modified BSD License.
The full license is in the file LICENSE.txt, distributed with this software.
----------------------------------------------------------------------------
"""
import os
import platform
import sys
import sysconfig
import subprocess
from setuptools import find_packages, setup
from setuptools.extension import Extension
import numpy as np
from Cython.Build import cythonize
if sys.version_info.major != 3:
sys.exit(
"scikit-bio can only be used with Python 3. You are currently "
"running Python %d." % sys.version_info.major
)
def check_bin(ccbin, source, allow_dash):
"""Check if a given compiler matches the specified name."""
# remove any parameters (e.g. gcc -I /a/b/c -> gcc)
source0 = source.split()[0]
# remove any path
bsource = os.path.basename(source0)
# now let's go search for ccbin
if allow_dash:
found = False
# allow for the ccbin to be between - (e.g. gcc-1.2)
for el in bsource.split("-"):
if el == ccbin:
found = True
break
else:
found = bsource == ccbin
return found
# Enable OpenMP during build
# Note: We are looking for Apple/MacOS clang, which does not support omp
# Will treat "real clang" (e.g. llvm based) same as gcc
clang = False
# icc uses slightly different omp cmdline arguments
icc = False
# Are we using the default gcc as the compiler?
gcc = True
try:
if os.environ["CC"] == "gcc":
gcc = True
elif os.environ["CC"] != "":
gcc = False
except KeyError:
pass
if not gcc:
try:
if check_bin("clang", os.environ["CC"], False):
# note, the conda provideed clang is not detected here
# and this is on purpose, as MacOS clang is very different
# than conda-provised one (which is llvm based)
# so do not look for substrings
# (e.g. do not match x86_64-apple-darwin13.4.0-clang)
clang = True
elif check_bin("icc", os.environ["CC"], True):
icc = True
except KeyError:
pass
else:
try:
if check_bin("clang", sysconfig.get_config_vars()["CC"], False):
# as above
clang = True
gcc = False
elif check_bin("icc", sysconfig.get_config_vars()["CC"], True):
icc = True
gcc = False
except KeyError:
pass
if gcc:
# check if the default gcc is just a wrapper around clang
try:
if (
subprocess.check_output(["gcc", "--version"], universal_newlines=True).find(
"clang"
)
!= -1
):
clang = True
except (subprocess.CalledProcessError, FileNotFoundError):
pass
# Determine if we want to use OpenMP
# Enabled by default
use_openpm = True
if clang:
# Apple clang does not support OpenMP at all
use_openpm = False
if os.getenv("DISABLE_OPENMP") in ("Y", "Yes", "YES", "1"):
# Developer explicity requested not to use OpenMP
use_openpm = False
# Compiler flags
extra_compile_args = ["-I."] # search current directory
extra_link_args = []
if use_openpm:
# Enable OpenMP for parallelism.
if platform.system() == "Windows":
extra_compile_args.append("/openmp")
elif icc:
extra_compile_args.append("-qopenmp")
extra_link_args.append("-qopenmp")
else:
extra_compile_args.append("-fopenmp")
extra_link_args.append("-fopenmp")
# Cython modules (*.pyx). They will be compiled into C code (*.c) during build.
ext = ".pyx"
extensions = [
Extension(
"skbio.metadata._intersection",
["skbio/metadata/_intersection" + ext],
),
Extension(
"skbio.tree._c_nj",
["skbio/tree/_c_nj" + ext],
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
),
Extension(
"skbio.tree._c_me",
["skbio/tree/_c_me" + ext],
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
),
Extension(
"skbio.diversity._phylogenetic",
["skbio/diversity/_phylogenetic" + ext],
include_dirs=[np.get_include()],
),
Extension(
"skbio.stats.ordination._cutils",
["skbio/stats/ordination/_cutils" + ext],
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
),
Extension(
"skbio.stats.distance._cutils",
["skbio/stats/distance/_cutils" + ext],
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
),
Extension(
"skbio.alignment._cutils",
["skbio/alignment/_cutils" + ext],
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
include_dirs=[np.get_include()],
),
]
extensions = cythonize(extensions, force=True)
setup(
packages=find_packages(),
ext_modules=extensions,
include_dirs=[np.get_include()],
)