1 from __future__ import print_function
11 if not pkgutil.find_loader('setuptools'):
12 from distutils.core import setup
13 from distutils.extension import Extension
15 from setuptools import setup
16 from setuptools.extension import Extension
18 from distutils.ccompiler import new_compiler
19 from distutils.errors import CompileError, LinkError
20 from distutils.sysconfig import customize_compiler
22 # PEP 440 versioning of the Rados package on PyPI
23 # Bump this version, after every changeset
24 # NOTE: This version is not the same as get_ceph_version()
29 def get_ceph_version():
31 for line in open(os.path.join(os.path.dirname(__file__), "..", "..", "ceph_ver.h")):
32 if "CEPH_GIT_NICE_VER" in line:
33 return line.split()[2].strip('"')
40 def get_python_flags():
41 cflags = {'I': [], 'extras': []}
42 ldflags = {'l': [], 'L': [], 'extras': []}
44 if os.environ.get('VIRTUAL_ENV', None):
47 python = 'python' + str(sys.version_info.major) + '.' + str(sys.version_info.minor)
49 python_config = python + '-config'
51 for cflag in subprocess.check_output(
52 [python_config, "--cflags"]
53 ).strip().decode('utf-8').split():
54 if cflag.startswith('-I'):
55 cflags['I'].append(cflag.replace('-I', ''))
57 cflags['extras'].append(cflag)
59 for ldflag in subprocess.check_output(
60 [python_config, "--ldflags"]
61 ).strip().decode('utf-8').split():
62 if ldflag.startswith('-l'):
63 ldflags['l'].append(ldflag.replace('-l', ''))
64 if ldflag.startswith('-L'):
65 ldflags['L'].append(ldflag.replace('-L', ''))
67 ldflags['extras'].append(ldflag)
77 Test if development headers and library for rados is available by compiling a dummy C program.
79 CEPH_SRC_DIR = os.path.join(
80 os.path.dirname(os.path.abspath(__file__)),
85 tmp_dir = tempfile.mkdtemp(dir=os.environ.get('TMPDIR', os.path.dirname(__file__)))
86 tmp_file = os.path.join(tmp_dir, 'rados_dummy.c')
88 with open(tmp_file, 'w') as fp:
89 dummy_prog = textwrap.dedent("""
90 #include <rados/librados.h>
94 rados_create(&cluster, NULL);
100 compiler = new_compiler()
101 customize_compiler(compiler)
103 if {'MAKEFLAGS', 'MFLAGS', 'MAKELEVEL'}.issubset(set(os.environ.keys())):
104 # The setup.py has been invoked by a top-level Ceph make.
105 # Set the appropriate CFLAGS and LDFLAGS
107 compiler.set_include_dirs([os.path.join(CEPH_SRC_DIR, 'include')])
108 compiler.set_library_dirs([os.environ.get('CEPH_LIBDIR')])
111 link_objects = compiler.compile(
115 compiler.link_executable(
116 objects=link_objects,
117 output_progname=os.path.join(tmp_dir, 'rados_dummy'),
123 print('\nCompile Error: RADOS development headers not found', file=sys.stderr)
126 print('\nLink Error: RADOS library not found', file=sys.stderr)
131 shutil.rmtree(tmp_dir)
134 if 'BUILD_DOC' in os.environ.keys():
143 from Cython.Build import cythonize
144 from Cython.Distutils import build_ext
146 cmdclass = {'build_ext': build_ext}
148 print("WARNING: Cython is not installed.")
150 if not os.path.isfile('rados.c'):
151 print('ERROR: Cannot find Cythonized file rados.c', file=sys.stderr)
154 def cythonize(x, **kwargs):
161 # Disable cythonification if we're not really building anything
162 if (len(sys.argv) >= 2 and
163 any(i in sys.argv[1:] for i in ('--help', 'clean', 'egg_info', '--version')
165 def cythonize(x, **kwargs):
168 flags = get_python_flags()
173 description="Python bindings for the Ceph librados library",
175 "This package contains Python bindings for interacting with Ceph's "
176 "RADOS library. RADOS is a reliable, autonomic distributed object "
177 "storage cluster developed as part of the Ceph distributed storage "
178 "system. This is a shared library allowing applications to access "
179 "the distributed object store using a simple file-like interface."
181 url='https://github.com/ceph/ceph/tree/master/src/pybind/rados',
184 ext_modules=cythonize(
189 include_dirs=flags['cflags']['I'],
190 library_dirs=flags['ldflags']['L'],
191 libraries=["rados"] + flags['ldflags']['l'],
192 extra_compile_args=flags['cflags']['extras'] + flags['ldflags']['extras'],
194 ], build_dir=os.environ.get("CYTHON_BUILD_DIR", None)
197 'Intended Audience :: Developers',
198 'Intended Audience :: System Administrators',
199 'License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)',
200 'Operating System :: POSIX :: Linux',
201 'Programming Language :: Cython',
202 'Programming Language :: Python :: 2.7',
203 'Programming Language :: Python :: 3.4',
204 'Programming Language :: Python :: 3.5'