From: John Mulligan Date: Sat, 4 Apr 2026 20:34:32 +0000 (-0400) Subject: python-common/ceph/smb: add a shim file for configuring grpc imports X-Git-Tag: v21.0.1~83^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4ecc0a2d6baed953e9d404143acc91f564b8bc99;p=ceph.git python-common/ceph/smb: add a shim file for configuring grpc imports Add a private shim file that can be used by ceph.smb.ctl to choose the grpc implementation in order to work around issues present in some grpc versions. These are unfortunately the versions packaged for EL distros. Signed-off-by: John Mulligan --- diff --git a/src/python-common/ceph/smb/ctl/_probe.py b/src/python-common/ceph/smb/ctl/_probe.py new file mode 100644 index 00000000000..6a0b9f00f1e --- /dev/null +++ b/src/python-common/ceph/smb/ctl/_probe.py @@ -0,0 +1,26 @@ +"""Utility to probe protobuf version and control behavior.""" + +from typing import Tuple + + +def protobuf_ver_tuple() -> Tuple[int, ...]: + import google.protobuf + + ver = tuple(int(p) for p in google.protobuf.__version__.split('.')) + return ver + + +def protobuf_choose_impl() -> None: + """Work around the crummy old version of protobuf that is available on + rhel10. Force the python implementation unless 3.20 or newer because + we can monkeypatch the python version but not the c ext version. + """ + import os + + key = 'PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION' + if key in os.environ: + return + ver = protobuf_ver_tuple() + if ver[:2] >= (3, 20): + return + os.environ[key] = 'python'