-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathsetup.py
177 lines (154 loc) · 6 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
# -*- coding: utf-8 -*-
import sys
import os
import os.path
from glob import glob
import setuptools
from distutils.core import setup, Extension
from distutils import sysconfig, spawn
import platform
build_asan = False
# If we're not on Windows, assume something POSIX-compatible (either Linux, OSX, *BSD or Cygwin) with a working gcc-like compiler
windows = platform.system() == "Windows"
# Dual-build: work-around for the fact that we have both C and C++ files in the extension, and sometimes need
# to split it into two. Windows and CYGWIN for now seems to need dual_build set to False, OSX to True, Linux seems fine
# with either setting.
dual_build = not windows
if platform.system() == "Windows":
assert not build_asan
dual_build = False
elif platform.system().startswith("CYGWIN"):
dual_build = False
# native_build = "CIBUILDWHEEL" not in os.environ and 'darwin' not in platform.system().lower() and not 'aarch' in platform.machine().lower()
native_build = False # For now, Ubuntu ships with GCC on which -march=native is broken... and it just fails in too many situations.
use_clang = (
(not windows)
and spawn.find_executable("clang++") != None
and os.getenv("OPENTIMS_USE_DEFAULT_CXX") == None
)
# use_ccache = (not windows) and spawn.find_executable('ccache') != None and native_build
use_ccache = os.path.exists("./use_ccache")
# Prefer clang on UNIX if available
if use_clang:
if use_ccache:
os.environ["CXX"] = "ccache g++"
os.environ["CC"] = "ccache gcc"
else:
os.environ["CXX"] = "clang++"
else:
if use_ccache:
os.environ["CXX"] = "ccache c++"
os.environ["CC"] = "ccache cc"
else:
# leave defaults
pass
def get_cflags(asan=False, warnings=True, std_flag=False):
if windows:
return ["/O2"]
if asan:
return "-Og -g -std=c++20 -fsanitize=address".split()
res = ["-g", "-O3"]
if std_flag:
res.append("-std=c++20")
if warnings:
res.extend(["-Wall", "-Wextra"])
if native_build:
res.extend(["-march=native", "-mtune=native"])
return res
cflags = get_cflags
class get_pybind_include(object):
"""Helper class to determine the pybind11 include path
The purpose of this class is to postpone importing pybind11
until it is actually installed, so that the ``get_include()``
method can be invoked."""
def __str__(self):
try:
import pybind11
return pybind11.get_include()
except ImportError:
print(
"pybind11 not found. Please either install it manually, or install via pip rather than through setuptools directly."
)
sys.exit(1)
if dual_build:
ext_modules = [
Extension(
name="libopentims_support",
sources=[
os.path.join("opentims++", "sqlite", "sqlite3.c"),
os.path.join("opentims++", "zstd", "zstddeclib.c"),
],
extra_compile_args=get_cflags(asan=False, warnings=False, std_flag=False),
libraries=[] if windows else "pthread dl".split(),
include_dirs=[get_pybind_include()],
),
Extension(
name="opentimspy_cpp",
sources=[
os.path.join("opentims++", "opentims_pybind11.cpp"),
],
extra_compile_args=get_cflags(asan=build_asan, std_flag=True),
libraries=[] if windows else "pthread dl".split(),
include_dirs=[get_pybind_include()],
undef_macros=[] if not build_asan else ["NDEBUG"],
),
Extension(
name="libopentims_cpp",
sources=[os.path.join("opentims++", "opentims_all.cpp")],
extra_compile_args=get_cflags(asan=False, std_flag=True),
libraries=[] if windows else "pthread dl".split(),
),
]
else:
ext_modules = [
Extension(
name="opentimspy_cpp",
sources=[
os.path.join("opentims++", "sqlite", "sqlite3.c"),
os.path.join("opentims++", "zstd", "zstddeclib.c"),
os.path.join("opentims++", "opentims_pybind11.cpp"),
],
extra_compile_args=get_cflags(asan=build_asan, std_flag=True),
libraries="" if windows else "pthread dl".split(),
include_dirs=[get_pybind_include()],
),
Extension(
name="libopentims_cpp",
sources=[
os.path.join("opentims++", "sqlite", "sqlite3.c"),
os.path.join("opentims++", "zstd", "zstddeclib.c"),
os.path.join("opentims++", "libopentims_py.cpp"),
],
extra_compile_args=get_cflags(asan=False, std_flag=True),
libraries=[] if windows else "pthread dl".split(),
),
]
setup(
name="opentimspy",
packages=["opentimspy"],
version="1.0.16",
author="Mateusz Krzysztof Łącki (MatteoLacki), Michał Startek (michalsta)",
author_email="[email protected], [email protected]",
description="opentimspy: An open-source parser of Bruker Tims Data File (.tdf).",
long_description="opentimspy: An open-source parser of Bruker Tims Data File (.tdf).",
keywords=["timsTOFpro", "Bruker TDF", "data science", "mass spectrometry"],
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering :: Chemistry",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
],
zip_safe=False,
setup_requires=["pybind11"],
install_requires=["pybind11", "numpy"],
ext_modules=ext_modules,
scripts=glob("scripts/*.py"),
package_dir={"opentimspy": "opentimspy"},
package_data={
"opentimspy": ["opentims++/*.h", "opentims++/*/*.h", "opentims++/*.hpp"]
},
extras_require={"bruker_proprietary": ["opentims_bruker_bridge>=1.0.3"], "plotting":["matplotlib"]},
)