-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathsetup.py
150 lines (126 loc) · 4.64 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
#!/usr/bin/env python
"""
setup.py file for Bloomberg Python SDK
"""
import os
import platform as plat
import re
import codecs
from sys import argv
from shutil import copyfile
from setuptools import setup, Extension
def override_get_tag():
from wheel.bdist_wheel import bdist_wheel
# bdist_wheel upon seeing an extension module will (wrongly) assume
# that not only platform needs to be fixed, but also interpreter.
# This makes sure we create no-py-specific wheel
class BDistWheel(bdist_wheel):
def get_tag(self):
return (self.python_tag, "none", self.plat_name.replace("-", "_"))
return {"bdist_wheel": BDistWheel}
os.chdir(os.path.dirname(os.path.realpath(__file__)))
platform = plat.system().lower()
def find_version_number():
"""Load the version number from blpapi/version.py"""
version_path = os.path.abspath(os.path.join("src", "blpapi", "version.py"))
version_file = None
with codecs.open(version_path, "r") as fp:
version_file = fp.read()
version_match = re.search(
r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M
)
if version_match:
return version_match.group(1)
raise RuntimeError("Unable to find version string.")
package_data = {}
cmdclass = {}
if "bdist_wheel" in argv:
libpath = os.getenv("BLPAPI_DEPENDENCY")
if libpath:
libname = os.path.basename(libpath)
assert os.path.exists(
libpath
), f"Could not find blpapi library at {libpath}"
# copy, as package_data only supports local files
copyfile(libpath, f"./src/blpapi/{libname}")
package_data = {"blpapi": [libname, "py.typed"]}
else:
print("BLPAPI_DEPENDENCY environment variable isn't defined")
cmdclass = override_get_tag()
packages = ["blpapi", "blpapi.test"]
# INTERNAL ONLY START
# see automation/prepare_release.py
internal_build = os.environ.get("BLPAPI_PY_INTERNAL_BUILD", False)
if internal_build:
internalutils_path = "src/blpapi/internalutils"
if not (
os.path.exists(internalutils_path)
and os.path.isdir(internalutils_path)
):
error_msg = """Tried to build the internal Bloomberg build of the
BLPAPI Python SDK, but failed to find the internalutils subdirectory.
If you are not a Bloomberg developer, this will not work, and you should unset
the BLPAPI_PY_INTERNAL_BUILD environment variable to continue. internalutils
provide some default configurations for use only within Bloomberg networks.
If you are a Bloomberg developer, either unset the BLPAPI_PY_INTERNAL_BUILD
environment variable to build the public release, or ensure the internalutils
subdirectory is present.
"""
raise ImportError(error_msg)
packages.append("blpapi.internalutils")
# INTERNAL ONLY END
def lib_in_release():
"""Returns the right library folder name for each platform"""
if platform == "windows":
return "lib"
if platform == "linux":
return "Linux"
if platform == "darwin":
return "Darwin"
raise Exception("Platform '" + platform + "' isn't supported")
blpapiRoot = os.environ.get("BLPAPI_ROOT", ".")
blpapiIncludesVar = os.environ.get("BLPAPI_INCDIR")
blpapiLibVar = os.environ.get("BLPAPI_LIBDIR")
assert blpapiRoot or (blpapiIncludesVar and blpapiLibVar), (
"BLPAPI_ROOT (or BLPAPI_INCDIR/BLPAPI_LIBDIR) "
+ "environment variable isn't defined"
)
blpapiLibraryPath = blpapiLibVar or os.path.join(blpapiRoot, lib_in_release())
blpapiIncludes = blpapiIncludesVar or os.path.join(blpapiRoot, "include")
is64bit = plat.architecture()[0] == "64bit"
if is64bit:
blpapiLibraryName = "blpapi3_64"
else:
blpapiLibraryName = "blpapi3_32"
extraLinkArgs = ["/MANIFEST"] if platform == "windows" else []
blpapi_wrap = Extension(
"blpapi.ffiutils",
sources=["src/blpapi/ffi_utils.c"],
include_dirs=[blpapiIncludes],
library_dirs=[blpapiLibraryPath],
libraries=[blpapiLibraryName],
extra_compile_args=[],
extra_link_args=extraLinkArgs,
)
extensions = [blpapi_wrap]
setup(
name="blpapi",
version=find_version_number(),
author="Bloomberg L.P.",
author_email="[email protected]",
cmdclass=cmdclass,
description="Python SDK for Bloomberg BLPAPI",
ext_modules=extensions,
url="http://www.bloomberglabs.com/api/",
packages=packages,
package_dir={"": "src"},
package_data=package_data,
python_requires=">=3.8",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Intended Audience :: Financial and Insurance Industry",
"License :: Other/Proprietary License",
"Topic :: Office/Business :: Financial",
],
)