From 96ebf42dc783d82b1bb4cdae70d9e041be67dae6 Mon Sep 17 00:00:00 2001 From: Rok Mandeljc Date: Fri, 2 Jul 2021 08:44:45 +0200 Subject: [PATCH] Fix problem with PyInstaller-frozen code and dot in the path (#1994) If `PyInstaller`-frozen application using `patroni` is placed in a location that contains a dot in the path, the `dcs_modules()` function in `patroni.dcs` breaks because `pkgutil.iter_importers()` treats the given path as a package name. Ref: pyinstaller/pyinstaller#5944 This can be avoided altogether by not passing a path to `iter_importers()`, because `PyInstaller`'s `FrozenImporter` is a singleton and registered as top-level finder. --- patroni/dcs/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/patroni/dcs/__init__.py b/patroni/dcs/__init__.py index 10c2d5f8..9e0e225c 100644 --- a/patroni/dcs/__init__.py +++ b/patroni/dcs/__init__.py @@ -68,7 +68,11 @@ def dcs_modules(): if getattr(sys, 'frozen', False): toc = set() - for importer in pkgutil.iter_importers(dcs_dirname): + # dcs_dirname may contain a dot, which causes pkgutil.iter_importers() + # to misinterpret the path as a package name. This can be avoided + # altogether by not passing a path at all, because PyInstaller's + # FrozenImporter is a singleton and registered as top-level finder. + for importer in pkgutil.iter_importers(): if hasattr(importer, 'toc'): toc |= importer.toc return [module for module in toc if module.startswith(module_prefix) and module.count('.') == 2]