From: Samuel Just Date: Fri, 23 Jan 2026 00:39:33 +0000 (+0000) Subject: Revert "pybind: replace deprecated IF statements with Tempita templates" X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b62a951ffc48a50e41d23e63ed6b312afb1c1621;p=ceph-ci.git Revert "pybind: replace deprecated IF statements with Tempita templates" This reverts commit 719b74984605b490f23004eb41583a22c934c5fb. --- diff --git a/src/pybind/cephfs/cephfs.pyx b/src/pybind/cephfs/cephfs.pyx index 737ec7d5b16..23813e72784 100644 --- a/src/pybind/cephfs/cephfs.pyx +++ b/src/pybind/cephfs/cephfs.pyx @@ -10,15 +10,14 @@ from libc.stdint cimport * from libc.stdlib cimport malloc, realloc, free from types cimport * -{{if BUILD_DOC}} -include "mock_cephfs.pxi" -cdef class Rados: - cdef: - rados_t cluster -{{else}} -from c_cephfs cimport * -from rados cimport Rados -{{endif}} +IF BUILD_DOC: + include "mock_cephfs.pxi" + cdef class Rados: + cdef: + rados_t cluster +ELSE: + from c_cephfs cimport * + from rados cimport Rados from collections import namedtuple, deque from datetime import datetime diff --git a/src/pybind/cephfs/setup.py b/src/pybind/cephfs/setup.py index c94ac2037ed..6195820b810 100755 --- a/src/pybind/cephfs/setup.py +++ b/src/pybind/cephfs/setup.py @@ -159,7 +159,6 @@ cmdclass = {} try: from Cython.Build import cythonize from Cython.Distutils import build_ext - from Cython import Tempita cmdclass = {'build_ext': build_ext} except ImportError: @@ -174,27 +173,7 @@ except ImportError: source = "cephfs.c" else: - # Process Tempita template - source_pyx = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "cephfs.pyx" - ) - - # Read the template from source - with open(source_pyx) as f: - template_content = f.read() - - # Process the template with cython_constants - processed = Tempita.sub(template_content, **cython_constants) - - # Write processed output to current working directory - # (which is the build directory when invoked by CMake) - output_pyx = "cephfs_processed.pyx" - - with open(output_pyx, 'w') as f: - f.write(processed) - - source = output_pyx + source = "cephfs.pyx" # Disable cythonification if we're not really building anything if (len(sys.argv) >= 2 and diff --git a/src/pybind/rados/rados.pxd b/src/pybind/rados/rados.pxd index 2bcb4941183..fec534e8cc7 100644 --- a/src/pybind/rados/rados.pxd +++ b/src/pybind/rados/rados.pxd @@ -4,19 +4,16 @@ # # Copyright 2016 Mehdi Abaakouk -cdef extern from *: - """ - #ifdef BUILD_DOC - typedef void* rados_t; - typedef void* rados_config_t; - typedef void* rados_ioctx_t; - #else - #include "rados/librados.h" - #endif - """ - ctypedef void* rados_t - ctypedef void* rados_config_t - ctypedef void* rados_ioctx_t +IF BUILD_DOC: + cdef: + ctypedef void* rados_t + ctypedef void* rados_config_t + ctypedef void* rados_ioctx_t +ELSE: + cdef extern from "rados/librados.h" nogil: + ctypedef void* rados_t + ctypedef void* rados_config_t + ctypedef void* rados_ioctx_t cdef class Rados(object): diff --git a/src/pybind/rados/rados.pyx b/src/pybind/rados/rados.pyx index 48e9746161f..27fa56e5f28 100644 --- a/src/pybind/rados/rados.pyx +++ b/src/pybind/rados/rados.pyx @@ -18,12 +18,10 @@ from cpython.pycapsule cimport * from libc cimport errno from libc.stdint cimport * from libc.stdlib cimport malloc, realloc, free - -{{if BUILD_DOC}} -include "mock_rados.pxi" -{{else}} -from c_rados cimport * -{{endif}} +IF BUILD_DOC: + include "mock_rados.pxi" +ELSE: + from c_rados cimport * import threading import time @@ -234,45 +232,42 @@ class ConnectionShutdown(OSError): "RADOS connection was shutdown (%s)" % message, errno) -# Build errno mapping based on platform -# FreeBSD uses ENOATTR while Linux uses ENODATA -{{if UNAME_SYSNAME == "FreeBSD"}} -cdef errno_to_exception = { - errno.EPERM : PermissionError, - errno.ENOENT : ObjectNotFound, - errno.EIO : IOError, - errno.ENOSPC : NoSpace, - errno.EEXIST : ObjectExists, - errno.EBUSY : ObjectBusy, - errno.ENOATTR : NoData, - errno.EINTR : InterruptedOrTimeoutError, - errno.ETIMEDOUT : TimedOut, - errno.EACCES : PermissionDeniedError, - errno.EINPROGRESS : InProgress, - errno.EISCONN : IsConnected, - errno.EINVAL : InvalidArgumentError, - errno.ENOTCONN : NotConnected, - errno.ESHUTDOWN : ConnectionShutdown, -} -{{else}} -cdef errno_to_exception = { - errno.EPERM : PermissionError, - errno.ENOENT : ObjectNotFound, - errno.EIO : IOError, - errno.ENOSPC : NoSpace, - errno.EEXIST : ObjectExists, - errno.EBUSY : ObjectBusy, - errno.ENODATA : NoData, - errno.EINTR : InterruptedOrTimeoutError, - errno.ETIMEDOUT : TimedOut, - errno.EACCES : PermissionDeniedError, - errno.EINPROGRESS : InProgress, - errno.EISCONN : IsConnected, - errno.EINVAL : InvalidArgumentError, - errno.ENOTCONN : NotConnected, - errno.ESHUTDOWN : ConnectionShutdown, -} -{{endif}} +IF UNAME_SYSNAME == "FreeBSD": + cdef errno_to_exception = { + errno.EPERM : PermissionError, + errno.ENOENT : ObjectNotFound, + errno.EIO : IOError, + errno.ENOSPC : NoSpace, + errno.EEXIST : ObjectExists, + errno.EBUSY : ObjectBusy, + errno.ENOATTR : NoData, + errno.EINTR : InterruptedOrTimeoutError, + errno.ETIMEDOUT : TimedOut, + errno.EACCES : PermissionDeniedError, + errno.EINPROGRESS : InProgress, + errno.EISCONN : IsConnected, + errno.EINVAL : InvalidArgumentError, + errno.ENOTCONN : NotConnected, + errno.ESHUTDOWN : ConnectionShutdown, + } +ELSE: + cdef errno_to_exception = { + errno.EPERM : PermissionError, + errno.ENOENT : ObjectNotFound, + errno.EIO : IOError, + errno.ENOSPC : NoSpace, + errno.EEXIST : ObjectExists, + errno.EBUSY : ObjectBusy, + errno.ENODATA : NoData, + errno.EINTR : InterruptedOrTimeoutError, + errno.ETIMEDOUT : TimedOut, + errno.EACCES : PermissionDeniedError, + errno.EINPROGRESS : InProgress, + errno.EISCONN : IsConnected, + errno.EINVAL : InvalidArgumentError, + errno.ENOTCONN : NotConnected, + errno.ESHUTDOWN : ConnectionShutdown, + } cdef make_ex(ret: int, msg: str): diff --git a/src/pybind/rados/setup.py b/src/pybind/rados/setup.py index 72cfe365dda..c0aa1aa7334 100755 --- a/src/pybind/rados/setup.py +++ b/src/pybind/rados/setup.py @@ -11,7 +11,6 @@ from distutils.ccompiler import new_compiler from itertools import filterfalse, takewhile import os -import platform import shutil import sys import tempfile @@ -139,11 +138,11 @@ def check_sanity(): if 'BUILD_DOC' in os.environ or 'READTHEDOCS' in os.environ: - ext_args = dict(extra_compile_args=['-DBUILD_DOC']) - cython_constants = dict(BUILD_DOC=True, UNAME_SYSNAME=platform.system()) + ext_args = {} + cython_constants = dict(BUILD_DOC=True) elif check_sanity(): ext_args = get_python_flags(['rados']) - cython_constants = dict(BUILD_DOC=False, UNAME_SYSNAME=platform.system()) + cython_constants = dict(BUILD_DOC=False) else: sys.exit(1) @@ -151,7 +150,6 @@ cmdclass = {} try: from Cython.Build import cythonize from Cython.Distutils import build_ext - from Cython import Tempita cmdclass = {'build_ext': build_ext} except ImportError: @@ -166,27 +164,7 @@ except ImportError: source = "rados.c" else: - # Process Tempita template - source_pyx = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "rados.pyx" - ) - - # Read the template from source - with open(source_pyx) as f: - template_content = f.read() - - # Process the template with cython_constants - processed = Tempita.sub(template_content, **cython_constants) - - # Write processed output to current working directory - # (which is the build directory when invoked by CMake) - output_pyx = "rados_processed.pyx" - - with open(output_pyx, 'w') as f: - f.write(processed) - - source = output_pyx + source = "rados.pyx" # Disable cythonification if we're not really building anything if (len(sys.argv) >= 2 and diff --git a/src/pybind/rbd/rbd.pyx b/src/pybind/rbd/rbd.pyx index cd491213e7f..2185f62e2f1 100644 --- a/src/pybind/rbd/rbd.pyx +++ b/src/pybind/rbd/rbd.pyx @@ -34,12 +34,11 @@ import errno from itertools import chain import time -{{if BUILD_DOC}} -include "mock_rbd.pxi" -{{else}} -from c_rbd cimport * -cimport rados -{{endif}} +IF BUILD_DOC: + include "mock_rbd.pxi" +ELSE: + from c_rbd cimport * + cimport rados cdef extern from "Python.h": @@ -374,19 +373,18 @@ cdef make_ex(ret, msg, exception_map=errno_to_exception): return OSError(msg, errno=ret) -{{if BUILD_DOC}} -cdef rados_t convert_rados(rados) nogil: - return 0 +IF BUILD_DOC: + cdef rados_t convert_rados(rados) nogil: + return 0 -cdef rados_ioctx_t convert_ioctx(ioctx) nogil: - return 0 -{{else}} -cdef rados_t convert_rados(rados.Rados rados) except? NULL: - return rados.cluster + cdef rados_ioctx_t convert_ioctx(ioctx) nogil: + return 0 +ELSE: + cdef rados_t convert_rados(rados.Rados rados) except? NULL: + return rados.cluster -cdef rados_ioctx_t convert_ioctx(rados.Ioctx ioctx) except? NULL: - return ioctx.io -{{endif}} + cdef rados_ioctx_t convert_ioctx(rados.Ioctx ioctx) except? NULL: + return ioctx.io cdef int progress_callback(uint64_t offset, uint64_t total, void* ptr) with gil: return (ptr)(offset, total) diff --git a/src/pybind/rbd/setup.py b/src/pybind/rbd/setup.py index f5e654287c5..c59c4e8f789 100755 --- a/src/pybind/rbd/setup.py +++ b/src/pybind/rbd/setup.py @@ -160,7 +160,6 @@ 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} @@ -184,25 +183,7 @@ except ImportError: source = "rbd.c" else: - # Process Tempita template - source_pyx = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "rbd.pyx" - ) - - # Read the template from source - with open(source_pyx) as f: - template_content = f.read() - - # Process the template with cython_constants - processed = Tempita.sub(template_content, **cython_constants) - - # Write processed output to current working directory - # (which is the build directory when invoked by CMake) - source = "rbd_processed.pyx" - - with open(source, 'w') as f: - f.write(processed) + source = "rbd.pyx" # Disable cythonification if we're not really building anything if (len(sys.argv) >= 2 and diff --git a/src/pybind/rgw/rgw.pyx b/src/pybind/rgw/rgw.pyx index a2689d93185..6da956e2d96 100644 --- a/src/pybind/rgw/rgw.pyx +++ b/src/pybind/rgw/rgw.pyx @@ -9,12 +9,11 @@ from libc.stdlib cimport malloc, realloc, free from cstat cimport stat cimport libcpp -{{if BUILD_DOC}} -include "mock_rgw.pxi" -{{else}} -from c_rgw cimport * -cimport rados -{{endif}} +IF BUILD_DOC: + include "mock_rgw.pxi" +ELSE: + from c_rgw cimport * + cimport rados from collections import namedtuple from datetime import datetime @@ -91,36 +90,32 @@ class WouldBlock(Error): class OutOfRange(Error): pass - -# Build errno mapping based on platform -# FreeBSD uses ENOATTR while Linux uses ENODATA -{{if UNAME_SYSNAME == "FreeBSD"}} -cdef errno_to_exception = { - errno.EPERM : PermissionError, - errno.ENOENT : ObjectNotFound, - errno.EIO : IOError, - errno.ENOSPC : NoSpace, - errno.EEXIST : ObjectExists, - errno.ENOATTR : NoData, - errno.EINVAL : InvalidValue, - errno.EOPNOTSUPP : OperationNotSupported, - errno.ERANGE : OutOfRange, - errno.EWOULDBLOCK: WouldBlock, -} -{{else}} -cdef errno_to_exception = { - errno.EPERM : PermissionError, - errno.ENOENT : ObjectNotFound, - errno.EIO : IOError, - errno.ENOSPC : NoSpace, - errno.EEXIST : ObjectExists, - errno.ENODATA : NoData, - errno.EINVAL : InvalidValue, - errno.EOPNOTSUPP : OperationNotSupported, - errno.ERANGE : OutOfRange, - errno.EWOULDBLOCK: WouldBlock, -} -{{endif}} +IF UNAME_SYSNAME == "FreeBSD": + cdef errno_to_exception = { + errno.EPERM : PermissionError, + errno.ENOENT : ObjectNotFound, + errno.EIO : IOError, + errno.ENOSPC : NoSpace, + errno.EEXIST : ObjectExists, + errno.ENOATTR : NoData, + errno.EINVAL : InvalidValue, + errno.EOPNOTSUPP : OperationNotSupported, + errno.ERANGE : OutOfRange, + errno.EWOULDBLOCK: WouldBlock, + } +ELSE: + cdef errno_to_exception = { + errno.EPERM : PermissionError, + errno.ENOENT : ObjectNotFound, + errno.EIO : IOError, + errno.ENOSPC : NoSpace, + errno.EEXIST : ObjectExists, + errno.ENODATA : NoData, + errno.EINVAL : InvalidValue, + errno.EOPNOTSUPP : OperationNotSupported, + errno.ERANGE : OutOfRange, + errno.EWOULDBLOCK: WouldBlock, + } cdef class FileHandle(object): diff --git a/src/pybind/rgw/setup.py b/src/pybind/rgw/setup.py index 8b9b9ac1fef..f48e8550c0b 100755 --- a/src/pybind/rgw/setup.py +++ b/src/pybind/rgw/setup.py @@ -141,15 +141,13 @@ def check_sanity(): shutil.rmtree(tmp_dir) -import platform - if 'BUILD_DOC' in os.environ or 'READTHEDOCS' in os.environ: ext_args = {} - cython_constants = dict(BUILD_DOC=True, UNAME_SYSNAME=platform.system()) + cython_constants = dict(BUILD_DOC=True) cythonize_args = dict(compile_time_env=cython_constants) elif check_sanity(): ext_args = get_python_flags(['rados', 'rgw']) - cython_constants = dict(BUILD_DOC=False, UNAME_SYSNAME=platform.system()) + cython_constants = dict(BUILD_DOC=False) include_path = [os.path.join(os.path.dirname(__file__), "..", "rados")] cythonize_args = dict(compile_time_env=cython_constants, include_path=include_path) @@ -160,7 +158,6 @@ cmdclass = {} try: from Cython.Build import cythonize from Cython.Distutils import build_ext - from Cython import Tempita cmdclass = {'build_ext': build_ext} except ImportError: @@ -175,27 +172,7 @@ except ImportError: source = "rgw.c" else: - # Process Tempita template - source_pyx = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "rgw.pyx" - ) - - # Read the template from source - with open(source_pyx) as f: - template_content = f.read() - - # Process the template with cython_constants - processed = Tempita.sub(template_content, **cython_constants) - - # Write processed output to current working directory - # (which is the build directory when invoked by CMake) - output_pyx = "rgw_processed.pyx" - - with open(output_pyx, 'w') as f: - f.write(processed) - - source = output_pyx + source = "rgw.pyx" # Disable cythonification if we're not really building anything if (len(sys.argv) >= 2 and