]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/rbd: move legacy_implicit_noexcept to rbd.pyx 67045/head
authorKefu Chai <k.chai@proxmox.com>
Wed, 28 Jan 2026 02:58:31 +0000 (10:58 +0800)
committerKefu Chai <k.chai@proxmox.com>
Thu, 29 Jan 2026 00:45:50 +0000 (08:45 +0800)
Move the legacy_implicit_noexcept compiler directive from setup.py to
the top of rbd.pyx, making it consistent with how CephFS handles this
directive. This simplifies the build setup by:

- Removing conditional logic based on Cython version in setup.py
- Eliminating the need for compiler_directives dict and packaging import
- Making RBD's directive handling consistent with other bindings

The directive is needed for building with both Cython 0.x and Cython 3
from the same file while preserving the same behavior. Cython safely
ignores unknown compiler directives when specified at the top of .pyx
files, so this works across all supported Cython versions.

When Cython 0.x support is eventually dropped, this directive can be
replaced with explicit noexcept annotations on rbd_callback_t and
librbd_progress_fn_t type definitions.

Signed-off-by: Kefu Chai <k.chai@proxmox.com>
src/pybind/rbd/rbd.pyx
src/pybind/rbd/setup.py

index 1a4c6ded18f8297a484cad7fe59f6f61d44c04cf..3d025c3c48a51e73ffd71d895e1c8fc527b888a6 100644 (file)
@@ -1,5 +1,14 @@
 # cython: language_level=3
+# cython: legacy_implicit_noexcept=True
 # cython: embedsignature=True
+
+# legacy_implicit_noexcept is needed for building with Cython 0.x and
+# Cython 3 from the same file, preserving the same behavior.
+# When Cython 0.x builds go away, replace this compiler directive with
+# noexcept on rbd_callback_t and librbd_progress_fn_t (or consider doing
+# something similar to except? -9000 on rbd_diff_iterate2() callback for
+# progress callbacks to propagate exceptions).
+
 """
 This module is a thin wrapper around librbd.
 
index 237385c4b3c571e415d3a9a27cdfe716b001efad..0f615fa0ab1704ac882c571071a8c7d1c2433d26 100755 (executable)
@@ -14,7 +14,6 @@ else:
 from distutils.ccompiler import new_compiler
 from distutils.errors import CompileError, LinkError
 from itertools import filterfalse, takewhile
-from packaging import version
 import distutils.sysconfig
 
 
@@ -155,23 +154,13 @@ else:
     sys.exit(1)
 
 cmdclass = {}
-compiler_directives = {}
 try:
     from Cython.Build import cythonize
     from Cython.Distutils import build_ext
-    from Cython import __version__ as cython_version
     from Cython import Tempita
 
     cmdclass = {'build_ext': build_ext}
 
-    # Needed for building with Cython 0.x and Cython 3 from the same file,
-    # preserving the same behavior.
-    # When Cython 0.x builds go away, replace this compiler directive with
-    # noexcept on rbd_callback_t and librbd_progress_fn_t (or consider doing
-    # something similar to except? -9000 on rbd_diff_iterate2() callback for
-    # progress callbacks to propagate exceptions).
-    if version.parse(cython_version) >= version.parse('3'):
-        compiler_directives['legacy_implicit_noexcept'] = True
 except ImportError:
     print("WARNING: Cython is not installed.")
 
@@ -234,7 +223,6 @@ setup(
                 **ext_args
             )
         ],
-        compiler_directives=compiler_directives,
         build_dir=os.environ.get("CYTHON_BUILD_DIR", None),
         **cythonize_args
     ),