-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup.py
executable file
·74 lines (61 loc) · 2.3 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
#
#
#
from __future__ import print_function
import collections
import os
import os.path
import sys
from distutils import ccompiler
from setuptools import Extension
from setuptools import setup
ceph_version_map = collections.OrderedDict(sorted({
"hammer": "rados_pool_get_base_tier",
"jewel": "rados_inconsistent_pg_list",
"kraken": "rados_aio_exec",
"luminous": "rados_read_op_omap_get_keys2",
}.items(), key=lambda t: t[0]))
def log(msg):
print(msg, file=sys.stderr)
def setup_hook(cmd_obj, version=None):
if version == "latest":
version = sorted(ceph_version_map.keys())[-1]
elif version is None:
comp = ccompiler.new_compiler(force=True, verbose=True)
for potential_version, method in ceph_version_map.items():
msg = "* checking for librados >= %s (with function %s)" % (
potential_version, method)
log(msg)
found = comp.has_function(method, libraries=['rados'])
if found:
version = potential_version
log("%s done: FOUND" % msg)
else:
log("%s done: NOT FOUND" % msg)
break
if not version:
raise Exception("gcc, python-dev, librados2 or "
"librados-dev >= 0.80 are missing")
log("building cradox with %s api compatibility" % version)
# Generate the source file from template
from jinja2 import Environment
env = Environment(trim_blocks=True, lstrip_blocks=True)
cradox_out = os.path.join(os.path.dirname(__file__), 'cradox.pyx')
cradox_in = "%s.in" % cradox_out
with open(cradox_in, 'r') as src:
with open(cradox_out, 'w') as dst:
template = env.from_string(src.read())
dst.write(template.render(version=version))
test_out = os.path.join(os.path.dirname(__file__), 'test_rados.py')
test_in = "%s.in" % test_out
with open(test_in, 'r') as src:
with open(test_out, 'w') as dst:
template = env.from_string(src.read())
dst.write(template.render(version=version))
if __name__ == '__main__':
setup(
# cradox segfault with 0.28.0
setup_requires=['pbr', 'Cython<0.28', 'Jinja2'],
pbr=True,
ext_modules=[Extension("cradox", ["cradox.pyx"], libraries=["rados"])],
)