From b4eab4897161eb15b37c6995991d76bf56de9ff7 Mon Sep 17 00:00:00 2001 From: Joe Jensen Date: Fri, 31 Jan 2025 04:14:27 -0500 Subject: [PATCH] Fall through to default behavior when pyinstall toc is not found (#3256) Close #3255 --- patroni/dynamic_loader.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/patroni/dynamic_loader.py b/patroni/dynamic_loader.py index 48881fe7..64d7a206 100644 --- a/patroni/dynamic_loader.py +++ b/patroni/dynamic_loader.py @@ -38,8 +38,11 @@ def iter_modules(package: str) -> List[str]: for importer in pkgutil.iter_importers(): if hasattr(importer, 'toc'): toc |= getattr(importer, 'toc') - dots = module_prefix.count('.') # search for modules only on the same level - return [module for module in toc if module.startswith(module_prefix) and module.count('.') == dots] + # If it found the pyinstaller toc then use it, otherwise fall through to default + # behavior which works in pyinstaller >= 4.4 + if len(toc) > 0: + dots = module_prefix.count('.') # search for modules only on the same level + return [module for module in toc if module.startswith(module_prefix) and module.count('.') == dots] # here we are making an assumption that the package which is calling this function is already imported pkg_file = sys.modules[package].__file__