]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/rados/setup.py
1 from __future__
import print_function
2 import distutils
.sysconfig
3 from distutils
.errors
import CompileError
, LinkError
4 from distutils
.ccompiler
import new_compiler
5 from itertools
import filterfalse
, takewhile
16 def filter_unsupported_flags(compiler
, flags
):
17 args
= takewhile(lambda argv
: not argv
.startswith('-'), [compiler
] + flags
)
18 if any('clang' in arg
for arg
in args
):
19 return list(filterfalse(lambda f
:
21 '-fstack-clash-protection',
22 '-fno-var-tracking-assignments',
23 '-Wno-deprecated-register',
24 '-Wno-gnu-designator') or
25 f
.startswith('-fcf-protection'),
31 def monkey_with_compiler(customize
):
32 def patched(compiler
):
34 if compiler
.compiler_type
!= 'unix':
36 compiler
.compiler
[1:] = \
37 filter_unsupported_flags(compiler
.compiler
[0],
38 compiler
.compiler
[1:])
39 compiler
.compiler_so
[1:] = \
40 filter_unsupported_flags(compiler
.compiler_so
[0],
41 compiler
.compiler_so
[1:])
45 distutils
.sysconfig
.customize_compiler
= \
46 monkey_with_compiler(distutils
.sysconfig
.customize_compiler
)
48 if not pkgutil
.find_loader('setuptools'):
49 from distutils
.core
import setup
50 from distutils
.extension
import Extension
52 from setuptools
import setup
53 from setuptools
.extension
import Extension
56 distutils
.sysconfig
.customize_compiler
= \
57 monkey_with_compiler(distutils
.sysconfig
.customize_compiler
)
59 # PEP 440 versioning of the Rados package on PyPI
60 # Bump this version, after every changeset
64 def get_python_flags(libs
):
65 py_libs
= sum((libs
.split() for libs
in
66 distutils
.sysconfig
.get_config_vars('LIBS', 'SYSLIBS')), [])
67 compiler
= new_compiler()
68 distutils
.sysconfig
.customize_compiler(compiler
)
70 include_dirs
=[distutils
.sysconfig
.get_python_inc()],
71 library_dirs
=distutils
.sysconfig
.get_config_vars('LIBDIR', 'LIBPL'),
72 libraries
=libs
+ [lib
.replace('-l', '') for lib
in py_libs
],
73 extra_compile_args
=filter_unsupported_flags(
75 distutils
.sysconfig
.get_config_var('CFLAGS').split()),
76 extra_link_args
=(distutils
.sysconfig
.get_config_var('LDFLAGS').split() +
77 distutils
.sysconfig
.get_config_var('LINKFORSHARED').split()))
82 Test if development headers and library for rados is available by compiling a dummy C program.
84 CEPH_SRC_DIR
= os
.path
.join(
85 os
.path
.dirname(os
.path
.abspath(__file__
)),
90 tmp_dir
= tempfile
.mkdtemp(dir=os
.environ
.get('TMPDIR', os
.path
.dirname(__file__
)))
91 tmp_file
= os
.path
.join(tmp_dir
, 'rados_dummy.c')
93 with
open(tmp_file
, 'w') as fp
:
94 dummy_prog
= textwrap
.dedent("""
95 #include <rados/librados.h>
99 rados_create(&cluster, NULL);
105 compiler
= new_compiler()
106 distutils
.sysconfig
.customize_compiler(compiler
)
108 if 'CEPH_LIBDIR' in os
.environ
:
109 # The setup.py has been invoked by a top-level Ceph make.
110 # Set the appropriate CFLAGS and LDFLAGS
111 compiler
.set_include_dirs([os
.path
.join(CEPH_SRC_DIR
, 'include')])
112 compiler
.set_library_dirs([os
.environ
.get('CEPH_LIBDIR')])
115 link_objects
= compiler
.compile(
119 compiler
.link_executable(
120 objects
=link_objects
,
121 output_progname
=os
.path
.join(tmp_dir
, 'rados_dummy'),
127 print('\nCompile Error: RADOS development headers not found', file=sys
.stderr
)
130 print('\nLink Error: RADOS library not found', file=sys
.stderr
)
135 shutil
.rmtree(tmp_dir
)
138 if 'BUILD_DOC' in os
.environ
.keys():
147 from Cython
.Build
import cythonize
148 from Cython
.Distutils
import build_ext
150 cmdclass
= {'build_ext': build_ext
}
152 print("WARNING: Cython is not installed.")
154 if not os
.path
.isfile('rados.c'):
155 print('ERROR: Cannot find Cythonized file rados.c', file=sys
.stderr
)
158 def cythonize(x
, **kwargs
):
165 # Disable cythonification if we're not really building anything
166 if (len(sys
.argv
) >= 2 and
167 any(i
in sys
.argv
[1:] for i
in ('--help', 'clean', 'egg_info', '--version')
169 def cythonize(x
, **kwargs
):
175 description
="Python bindings for the Ceph librados library",
177 "This package contains Python bindings for interacting with Ceph's "
178 "RADOS library. RADOS is a reliable, autonomic distributed object "
179 "storage cluster developed as part of the Ceph distributed storage "
180 "system. This is a shared library allowing applications to access "
181 "the distributed object store using a simple file-like interface."
183 url
='https://github.com/ceph/ceph/tree/master/src/pybind/rados',
186 ext_modules
=cythonize(
191 **get_python_flags(['rados'])
194 compiler_directives
={'language_level': sys
.version_info
.major
},
195 build_dir
=os
.environ
.get("CYTHON_BUILD_DIR", None)
198 'Intended Audience :: Developers',
199 'Intended Audience :: System Administrators',
200 'License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)',
201 'Operating System :: POSIX :: Linux',
202 'Programming Language :: Cython',
203 'Programming Language :: Python :: 2.7',
204 'Programming Language :: Python :: 3.4',
205 'Programming Language :: Python :: 3.5'