Repository navigation
Expand file tree
/
Copy pathsetup.py
More file actions
287 lines (214 loc) · 8.58 KB
/
Copy pathsetup.py
File metadata and controls
287 lines (214 loc) · 8.58 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# -*- coding: utf-8 -*-
#
# Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
# Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 StatPro Italia srl
#
# This file is part of QuantLib, a free-software/open-source library
# for financial quantitative analysts and developers - http://quantlib.org/
#
# QuantLib is free software: you can redistribute it and/or modify it
# under the terms of the QuantLib license. You should have received a
# copy of the license along with this program; if not, please email
# <[email protected]>. The license is also available online at
# <https://www.quantlib.org/license.shtml>.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the license for more details.
import os, sys, math, platform, sysconfig
from setuptools import setup, Extension
from setuptools._distutils.ccompiler import get_default_compiler
def is_debug_quantlib():
return os.getenv("QL_DEBUG", "False").lower() in ("true", "1", "t")
def define_macros():
define_macros = []
if py_limited_api():
define_macros += [("Py_LIMITED_API", "0x03090000")]
if free_threading():
define_macros += [("SWIGPYTHON_NOGIL", None), ("Py_GIL_DISABLED", None)]
compiler = get_default_compiler()
if compiler == "msvc":
define_macros += [
("__WIN32__", None),
("WIN32", None),
("NDEBUG", None),
("_WINDOWS", None),
("NOMINMAX", None),
]
elif compiler == "unix":
ql_compile_args = os.popen("quantlib-config --cflags").read()[:-1].split()
define_macros += [
(arg[2:], None) for arg in ql_compile_args if arg.startswith("-D")
]
define_macros += [("NDEBUG", None)]
return define_macros
def include_dirs():
include_dirs = []
compiler = get_default_compiler()
if compiler == "msvc":
try:
QL_INSTALL_DIR = os.environ["QL_DIR"]
include_dirs += [QL_INSTALL_DIR]
except KeyError:
print("warning: unable to detect QuantLib installation")
if "INCLUDE" in os.environ:
include_dirs += [
d.strip() for d in os.environ["INCLUDE"].split(";") if d.strip()
]
elif compiler == "unix":
ql_compile_args = os.popen("quantlib-config --cflags").read()[:-1].split()
include_dirs += [arg[2:] for arg in ql_compile_args if arg.startswith("-I")]
return include_dirs
def library_dirs():
library_dirs = []
compiler = get_default_compiler()
if compiler == "msvc":
try:
QL_INSTALL_DIR = os.environ["QL_DIR"]
library_dirs += [os.path.join(QL_INSTALL_DIR, "lib")]
except KeyError:
print("warning: unable to detect QuantLib installation")
if "LIB" in os.environ:
dirs = [dir for dir in os.environ["LIB"].split(";")]
library_dirs += [d for d in dirs if d.strip()]
elif compiler == "unix":
ql_link_args = os.popen("quantlib-config --libs").read()[:-1].split()
library_dirs += [arg[2:] for arg in ql_link_args if arg.startswith("-L")]
return library_dirs
def libraries():
libraries = []
compiler = get_default_compiler()
if compiler == "unix":
ql_link_args = os.popen("quantlib-config --libs").read()[:-1].split()
libraries += [arg[2:] for arg in ql_link_args if arg.startswith("-l")]
return libraries
def extra_compile_args():
extra_compile_args = []
compiler = get_default_compiler()
if compiler == "msvc":
# /utf-8: the QuantLib headers are UTF-8 (author names in the licence
# headers, mathematical symbols in the documentation); tell the
# compiler so, rather than letting it warn C4819.
extra_compile_args = [
"/GR",
"/FD",
"/Zm250",
"/EHsc",
"/bigobj",
"/std:c++17",
"/utf-8",
]
if is_debug_quantlib():
if "QL_STATIC_RUNTIME" in os.environ:
extra_compile_args.append("/MTd")
else:
extra_compile_args.append("/MDd")
extra_compile_args.append("/Od")
extra_compile_args.append("/Ob0")
extra_compile_args.append("/Zi")
else:
if "QL_STATIC_RUNTIME" in os.environ:
extra_compile_args.append("/MT")
else:
extra_compile_args.append("/MD")
elif compiler == "unix":
ql_compile_args = os.popen("quantlib-config --cflags").read()[:-1].split()
extra_compile_args = [
arg
for arg in ql_compile_args
if not arg.startswith("-D")
if not arg.startswith("-I")
] + ["-Wno-unused"]
if "CXXFLAGS" in os.environ:
extra_compile_args += os.environ["CXXFLAGS"].split()
return extra_compile_args
def extra_link_args():
extra_link_args = []
compiler = get_default_compiler()
if compiler == "msvc":
dbit = round(math.log(sys.maxsize, 2) + 1)
if dbit == 64:
machinetype = "/machine:x64"
else:
machinetype = "/machine:x86"
extra_link_args = ["/subsystem:windows", machinetype]
if is_debug_quantlib():
extra_link_args += ["/DEBUG"]
elif compiler == "unix":
ql_link_args = os.popen("quantlib-config --libs").read()[:-1].split()
extra_link_args = [
arg
for arg in ql_link_args
if not arg.startswith("-L")
if not arg.startswith("-l")
]
if "LDFLAGS" in os.environ:
extra_link_args += os.environ["LDFLAGS"].split()
return extra_link_args
classifiers = [
"Development Status :: 6 - Mature",
"Environment :: Console",
"Intended Audience :: Developers",
"Intended Audience :: Education",
"Intended Audience :: End Users/Desktop",
"Intended Audience :: Financial and Insurance Industry",
"Intended Audience :: Science/Research",
"Operating System :: OS Independent",
"Programming Language :: C++",
"Programming Language :: Python",
"Programming Language :: Python :: Free Threading :: 2 - Beta",
"Topic :: Office/Business :: Financial",
"Topic :: Scientific/Engineering",
]
long_description = """
QuantLib (https://www.quantlib.org/) is a free/open-source C++ library
for financial quantitative analysts and developers, aimed at providing
a comprehensive software framework for quantitative finance.
QuantLib is Non-Copylefted Free Software and OSI Certified Open Source Software.
Free-threading wheels are also provided, and we did build the wheels
with some configuration options that make it possible to use them
using some limited multi-threading. In particular:
- the globals in the library are per-thread; most notably,
the evaluation date and the stored index fixings;
- there is code in place to prevent the garbage collector
to interfere with notifications inside the library.
Note, though, that the underlying C++ library is not thread-safe and
any complex attempt at multi-threading will probably fail. We suggest
to avoid sharing objects and state across threads; each thread should
have its set of objects, evaluation date etc.
"""
def py_limited_api():
return platform.python_implementation() == "CPython" and not free_threading()
def free_threading():
return bool(sysconfig.get_config_var("Py_GIL_DISABLED"))
with open("./setup.cfg", "w") as f:
if py_limited_api():
f.write("[bdist_wheel]" + os.linesep + "py_limited_api=cp39" + os.linesep)
setup(
name="QuantLib",
version="1.44",
description="Python bindings for the QuantLib library",
long_description=long_description,
long_description_content_type="text/x-rst",
author="QuantLib Team",
url="https://www.quantlib.org",
license="BSD-3-Clause",
classifiers=classifiers,
package_dir={"": "src"},
py_modules=["QuantLib.__init__", "QuantLib.QuantLib"],
ext_modules=[
Extension(
name="QuantLib._QuantLib",
sources=["src/QuantLib/quantlib_wrap.cpp"],
py_limited_api=py_limited_api(),
define_macros=define_macros(),
include_dirs=include_dirs(),
library_dirs=library_dirs(),
libraries=libraries(),
extra_compile_args=extra_compile_args(),
extra_link_args=extra_link_args(),
)
],
data_files=[("share/doc/quantlib", ["../LICENSE.TXT"])],
)