/
setup.py
241 lines (194 loc) · 7.56 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
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
#!/usr/bin/env python
import sys
import os.path
import os
import platform
import warnings
import couchbase_version
import pip
try:
if os.environ.get('PYCBC_NO_DISTRIBUTE'):
raise ImportError()
from setuptools import setup, Extension
except ImportError:
from distutils.core import setup, Extension
import re
extoptions = {}
pkgdata = {}
pkgversion = None
lcb_min_version = (2, 9, 0)
try:
from lcb_version import get_lcb_min_version
lcb_min_version=get_lcb_min_version()
except:
lcb_min_version=(2,9,0)
if not os.path.exists("build"):
os.mkdir("build")
with open("build/lcb_min_version.h", "w+") as LCB_MIN_VERSION:
LCB_MIN_VERSION.writelines(
["#define LCB_MIN_VERSION 0x{}\n".format(''.join(map(lambda x: "{0:02d}".format(x), lcb_min_version))),
'#define LCB_MIN_VERSION_TEXT "{}"'.format('.'.join(map(str, lcb_min_version)))])
try:
couchbase_version.gen_version()
except couchbase_version.CantInvokeGit:
pass
pkgversion = couchbase_version.get_version()
LCB_NAME = None
extoptions['extra_compile_args'] = []
extoptions['extra_link_args'] = []
def boolean_option(flag):
return "-D{}={}".format(flag,os.environ.get(flag))
COMP_OPTION_PREFIX = "PYCBC_COMP_OPT_"
def comp_option(flag):
return "-{}={}".format(flag.replace(COMP_OPTION_PREFIX, ""), os.environ.get(flag))
COMP_OPTION_BOOL_PREFIX = "PYCBC_COMP_OPT_BOOL_"
def comp_option_bool(flag):
return "-{}".format(flag.replace(COMP_OPTION_BOOL_PREFIX, ""))
CLANG_SAN_OPTIONS={"address":"lsan","undefined":"ubsan"}
CLANG_SAN_PREFIX = "PYCBC_SAN_OPT_"
def comp_clang_san_option(flag):
san_option = flag.replace(CLANG_SAN_PREFIX, "")
fsanitize_statement = "-fsanitize={}".format(san_option)
extoptions['extra_link_args']+=["{}".format(fsanitize_statement)]
return fsanitize_statement
def comp_option_pattern(prefix):
return re.escape(prefix) + ".*"
comp_flags = {"PYCBC_STRICT":boolean_option,
"PYCBC_TABBED_CONTEXTS_ENABLE": boolean_option,
"PYCBC_REF_ACCOUNTING": boolean_option,
"PYCBC_TRACING_DISABLE": boolean_option, "PYCBC_DEBUG": boolean_option,
"PYCBC_CRYPTO_VERSION": boolean_option, comp_option_pattern(COMP_OPTION_PREFIX): comp_option,
comp_option_pattern(COMP_OPTION_BOOL_PREFIX): comp_option_bool,
comp_option_pattern(CLANG_SAN_PREFIX):comp_clang_san_option}
debug_symbols = len(set(os.environ.keys()) & {"PYCBC_DEBUG", "PYCBC_DEBUG_SYMBOLS"}) > 0
comp_arg_additions = (action(actual_flag) for flag, action in comp_flags.items() for actual_flag in os.environ.keys() if
re.match(flag, actual_flag))
extoptions['extra_compile_args'] += comp_arg_additions
if sys.platform != 'win32':
extoptions['libraries'] = ['couchbase']
if debug_symbols:
extoptions['extra_compile_args'] += ['-O0', '-g3']
extoptions['extra_link_args'] += ['-O0', '-g3']
if sys.platform == 'darwin':
warnings.warn('Adding /usr/local to search path for OS X')
extoptions['library_dirs'] = ['/usr/local/lib']
extoptions['include_dirs'] = ['/usr/local/include']
else:
if sys.version_info<(3,0,0):
if pip.__version__<"9.0.0":
raise pip.exceptions.InstallationError("Windows on Python earlier than v3 unsupported.")
warnings.warn("I'm detecting you're running windows."
"You might want to modify "
"the 'setup.py' script to use appropriate paths")
# The layout i have here is an ..\lcb-winbuild, in which there are subdirs
# called 'x86' and 'x64', for x86 and x64 architectures. The default
# 'nmake install' on libcouchbase will install them to 'deps'
bit_type = platform.architecture()[0]
lcb_root = os.path.join(os.path.pardir, 'lcb-winbuild')
if bit_type.startswith('32'):
lcb_root = os.path.join(lcb_root, 'x86')
else:
lcb_root = os.path.join(lcb_root, 'x64')
lcb_root = os.path.join(lcb_root, 'deps')
extoptions['libraries'] = ['libcouchbase']
## Enable these lines for debug builds
if debug_symbols:
extoptions['extra_compile_args'] += ['/Zi','/DEBUG','/O0']
extoptions['extra_link_args'] += ['/DEBUG','-debug']
extoptions['library_dirs'] = [os.path.join(lcb_root, 'lib')]
extoptions['include_dirs'] = [os.path.join(lcb_root, 'include')]
extoptions['define_macros'] = [('_CRT_SECURE_NO_WARNINGS', 1)]
pkgdata['couchbase'] = ['libcouchbase.dll']
SOURCEMODS = [
'exceptions',
'ext',
'result',
'opresult',
'callbacks',
'cntl',
'convert',
'bucket',
'store',
'constants',
'multiresult',
'miscops',
'typeutil',
'oputil',
'get',
'counter',
'http',
'htresult',
'ctranscoder',
'crypto',
'observe',
'iops',
'connevents',
'pipeline',
'views',
'n1ql',
'fts',
'ixmgmt'
]
if platform.python_implementation() != 'PyPy':
extoptions['sources'] = [ os.path.join("src", m + ".c") for m in SOURCEMODS ]
module = Extension('couchbase._libcouchbase', **extoptions)
setup_kw = {'ext_modules': [module]}
else:
warnings.warn('The C extension libary does not work on PyPy. '
'You should install the couchbase_ffi module. Installation of this '
'module will continue but will be unusable without couchbase_ffi')
setup_kw = {}
cmake_build=os.environ.get("PYCBC_CMAKE_BUILD")
# Dummy dependency to prevent installation of Python < 3 package on Windows.
pip_not_on_win_python_lt_3 = (
["pip>=9.0; (sys_platform != 'win32' and python_version >= '2.7') or (python_version >= '3.0')"]
if pip.__version__ >= "9.0.0"
else [])
conan_and_cmake_deps = (['conan', 'cmake>=3.0.2'] if
cmake_build and sys.platform.startswith('darwin') else [])
gen_reqs = ["typing; python_version<'3.7'",
"enum34; python_version<'3.5'"]
setup(
name = 'couchbase',
version = pkgversion,
url="https://github.com/couchbase/couchbase-python-client",
author="Couchbase, Inc.",
author_email="PythonPackage@couchbase.com",
license="Apache License 2.0",
description="Python Client for Couchbase",
long_description=open("README.rst", "r").read(),
keywords=["couchbase", "nosql", "pycouchbase", "libcouchbase"],
classifiers=[
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: Apache Software License",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Database",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Libraries :: Python Modules"],
packages = [
'acouchbase',
'couchbase',
'couchbase.views',
'couchbase.iops',
'couchbase.asynchronous',
'couchbase.tests',
'couchbase.tests.cases',
'gcouchbase',
'txcouchbase',
'acouchbase',
] + ([
'acouchbase.tests',
'acouchbase.py34only'
] if sys.version_info >= (3, 4) else []),
package_data=pkgdata,
setup_requires=gen_reqs + conan_and_cmake_deps,
install_requires=gen_reqs + pip_not_on_win_python_lt_3,
tests_require=['nose', 'testresources>=0.2.7', 'basictracer==2.2.0'],
test_suite='couchbase.tests.test_sync',
**setup_kw
)