Compatibility with pyinstaller

This commit is contained in:
DarkPhoenix
2020-01-21 13:30:48 +03:00
parent b9c92c48d3
commit d9934160a6
4 changed files with 50 additions and 127 deletions

View File

@@ -7,37 +7,17 @@ item's name. The name of the file is usually arbitrary unless it's used in logic
elsewhere (in which case can be accessed with packs[name])
"""
import pkgutil
from eos.utils.pyinst_support import iterNamespace
# init parent dict
all = {}
# init container to store the separate conversion packs in case we need them
packs = {}
prefix = __name__ + "."
# load modules to work based with and without pyinstaller
# from: https://github.com/webcomics/dosage/blob/master/dosagelib/loader.py
# see: https://github.com/pyinstaller/pyinstaller/issues/1905
# load modules using iter_modules()
# (should find all filters in normal build, but not pyinstaller)
module_names = [m[1] for m in pkgutil.iter_modules(__path__, prefix)]
# special handling for PyInstaller
importers = map(pkgutil.get_importer, __path__)
toc = set()
for i in importers:
if hasattr(i, 'toc'):
toc |= i.toc
for elm in toc:
if elm.startswith(prefix):
module_names.append(elm)
for modname in module_names:
conversionPack = __import__(modname, fromlist="dummy")
for modName in iterNamespace(__name__, __path__):
conversionPack = __import__(modName, fromlist="dummy")
all.update(conversionPack.CONVERSIONS)
modname_tail = modname.rsplit('.', 1)[-1]
modname_tail = modName.rsplit('.', 1)[-1]
packs[modname_tail] = conversionPack.CONVERSIONS