]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/rbd/setup.py
1 from __future__
import print_function
10 from distutils
.ccompiler
import new_compiler
11 from distutils
.errors
import CompileError
, LinkError
12 from distutils
.sysconfig
import customize_compiler
14 if not pkgutil
.find_loader('setuptools'):
15 from distutils
.core
import setup
16 from distutils
.extension
import Extension
18 from setuptools
import setup
19 from setuptools
.extension
import Extension
21 # PEP 440 versioning of the RBD package on PyPI
22 # Bump this version, after every changeset
27 def get_python_flags():
28 cflags
= {'I': [], 'extras': []}
29 ldflags
= {'l': [], 'L': [], 'extras': []}
31 if os
.environ
.get('VIRTUAL_ENV', None):
34 python
= 'python' + str(sys
.version_info
.major
) + '.' + str(sys
.version_info
.minor
)
36 python_config
= python
+ '-config'
38 for cflag
in subprocess
.check_output(
39 [python_config
, "--cflags"]
40 ).strip().decode('utf-8').split():
41 if cflag
.startswith('-I'):
42 cflags
['I'].append(cflag
.replace('-I', ''))
44 cflags
['extras'].append(cflag
)
46 for ldflag
in subprocess
.check_output(
47 [python_config
, "--ldflags"]
48 ).strip().decode('utf-8').split():
49 if ldflag
.startswith('-l'):
50 ldflags
['l'].append(ldflag
.replace('-l', ''))
51 if ldflag
.startswith('-L'):
52 ldflags
['L'].append(ldflag
.replace('-L', ''))
54 ldflags
['extras'].append(ldflag
)
64 Test if development headers and library for rbd is available by compiling a dummy C program.
66 CEPH_SRC_DIR
= os
.path
.join(
67 os
.path
.dirname(os
.path
.abspath(__file__
)),
72 tmp_dir
= tempfile
.mkdtemp(dir=os
.environ
.get('TMPDIR', os
.path
.dirname(__file__
)))
73 tmp_file
= os
.path
.join(tmp_dir
, 'rbd_dummy.c')
75 with
open(tmp_file
, 'w') as fp
:
76 dummy_prog
= textwrap
.dedent("""
78 #include <rbd/librbd.h>
81 rados_create(&cluster, NULL);
87 compiler
= new_compiler()
88 customize_compiler(compiler
)
90 if {'MAKEFLAGS', 'MFLAGS', 'MAKELEVEL'}.issubset(set(os
.environ
.keys())):
91 # The setup.py has been invoked by a top-level Ceph make.
92 # Set the appropriate CFLAGS and LDFLAGS
94 compiler
.set_include_dirs([os
.path
.join(CEPH_SRC_DIR
, 'include')])
95 compiler
.set_library_dirs([os
.environ
.get('CEPH_LIBDIR')])
98 compiler
.define_macro('_FILE_OFFSET_BITS', '64')
100 link_objects
= compiler
.compile(
105 compiler
.link_executable(
106 objects
=link_objects
,
107 output_progname
=os
.path
.join(tmp_dir
, 'rbd_dummy'),
108 libraries
=['rbd', 'rados'],
113 print('\nCompile Error: RBD development headers not found', file=sys
.stderr
)
116 print('\nLink Error: RBD library not found', file=sys
.stderr
)
121 shutil
.rmtree(tmp_dir
)
124 if 'BUILD_DOC' in os
.environ
.keys():
133 from Cython
.Build
import cythonize
134 from Cython
.Distutils
import build_ext
136 cmdclass
= {'build_ext': build_ext
}
138 print("WARNING: Cython is not installed.")
140 if not os
.path
.isfile('rbd.c'):
141 print('ERROR: Cannot find Cythonized file rbd.c', file=sys
.stderr
)
144 def cythonize(x
, **kwargs
):
151 # Disable cythonification if we're not really building anything
152 if (len(sys
.argv
) >= 2 and
153 any(i
in sys
.argv
[1:] for i
in ('--help', 'clean', 'egg_info', '--version')
155 def cythonize(x
, **kwargs
):
158 flags
= get_python_flags()
163 description
="Python bindings for the RBD library",
165 "This package contains Python bindings for interacting with the "
166 "RADOS Block Device (RBD) library. rbd is a utility for manipulating "
167 "rados block device images, used by the Linux rbd driver and the rbd "
168 "storage driver for QEMU/KVM. RBD images are simple block devices that "
169 "are striped over objects and stored in a RADOS object store. The size "
170 "of the objects the image is striped over must be a power of two."
172 url
='https://github.com/ceph/ceph/tree/master/src/pybind/rbd',
175 ext_modules
=cythonize(
180 include_dirs
=flags
['cflags']['I'],
181 library_dirs
=flags
['ldflags']['L'],
182 libraries
=['rbd', 'rados'] + flags
['ldflags']['l'],
183 extra_compile_args
=flags
['cflags']['extras'] + flags
['ldflags']['extras'],
186 build_dir
=os
.environ
.get("CYTHON_BUILD_DIR", None),
188 os
.path
.join(os
.path
.dirname(__file__
), "..", "rados")
192 'Intended Audience :: Developers',
193 'Intended Audience :: System Administrators',
194 'License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)',
195 'Operating System :: POSIX :: Linux',
196 'Programming Language :: Cython',
197 'Programming Language :: Python :: 2.7',
198 'Programming Language :: Python :: 3.4',
199 'Programming Language :: Python :: 3.5'