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 Ceph FS 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 cephfs 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, 'cephfs_dummy.c')
75 with open(tmp_file, 'w') as fp:
76 dummy_prog = textwrap.dedent("""
78 #include "cephfs/libcephfs.h"
81 struct ceph_mount_info *cmount = NULL;
88 compiler = new_compiler()
89 customize_compiler(compiler)
91 if {'MAKEFLAGS', 'MFLAGS', 'MAKELEVEL'}.issubset(set(os.environ.keys())):
92 # The setup.py has been invoked by a top-level Ceph make.
93 # Set the appropriate CFLAGS and LDFLAGS
95 compiler.set_library_dirs([os.environ.get('CEPH_LIBDIR')])
98 compiler.define_macro('_FILE_OFFSET_BITS', '64')
100 link_objects = compiler.compile(
103 extra_preargs=['-iquote{path}'.format(path=os.path.join(CEPH_SRC_DIR, 'include'))]
106 compiler.link_executable(
107 objects=link_objects,
108 output_progname=os.path.join(tmp_dir, 'cephfs_dummy'),
109 libraries=['cephfs'],
114 print('\nCompile Error: Ceph FS development headers not found', file=sys.stderr)
117 print('\nLink Error: Ceph FS library not found', file=sys.stderr)
122 shutil.rmtree(tmp_dir)
125 if 'BUILD_DOC' in os.environ.keys():
134 from Cython.Build import cythonize
135 from Cython.Distutils import build_ext
137 cmdclass = {'build_ext': build_ext}
139 print("WARNING: Cython is not installed.")
141 if not os.path.isfile('cephfs.c'):
142 print('ERROR: Cannot find Cythonized file cephfs.c', file=sys.stderr)
145 def cythonize(x, **kwargs):
150 source = "cephfs.pyx"
152 # Disable cythonification if we're not really building anything
153 if (len(sys.argv) >= 2 and
154 any(i in sys.argv[1:] for i in ('--help', 'clean', 'egg_info', '--version')
156 def cythonize(x, **kwargs):
159 flags = get_python_flags()
164 description="Python bindings for the Ceph FS library",
166 "This package contains Python bindings for interacting with the "
167 "Ceph Filesystem (Ceph FS) library. Ceph FS is a POSIX-compliant "
168 "filesystem that uses a Ceph Storage Cluster to store its data. The "
169 "Ceph filesystem uses the same Ceph Storage Cluster system as "
170 "Ceph Block Devices, Ceph Object Storage with its S3 and Swift APIs, "
171 "or native bindings (librados)."
173 url='https://github.com/ceph/ceph/tree/master/src/pybind/cephfs',
176 ext_modules=cythonize(
181 include_dirs=flags['cflags']['I'],
182 library_dirs=flags['ldflags']['L'],
183 libraries=['cephfs'] + flags['ldflags']['l'],
184 extra_compile_args=flags['cflags']['extras'] + flags['ldflags']['extras'],
187 build_dir=os.environ.get("CYTHON_BUILD_DIR", None),
189 os.path.join(os.path.dirname(__file__), "..", "rados")
193 'Intended Audience :: Developers',
194 'Intended Audience :: System Administrators',
195 'License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)',
196 'Operating System :: POSIX :: Linux',
197 'Programming Language :: Cython',
198 'Programming Language :: Python :: 2.7',
199 'Programming Language :: Python :: 3.4',
200 'Programming Language :: Python :: 3.5'