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.
This commit is contained in:
Rok Mandeljc
2021-07-02 08:44:45 +02:00
committed by GitHub
parent e2d8a7d086
commit 96ebf42dc7
+5 -1
View File
@@ -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]