From bb115afc1a77fba01131a7fd447cd0a4471565f6 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 10 Dec 2018 11:41:37 +0100 Subject: [PATCH] Make sure we always yield full names --- misc/qutebrowser.spec | 2 +- qutebrowser/extensions/loader.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/misc/qutebrowser.spec b/misc/qutebrowser.spec index b40172754..269668751 100644 --- a/misc/qutebrowser.spec +++ b/misc/qutebrowser.spec @@ -32,7 +32,7 @@ def get_data_files(): def get_hidden_imports(): imports = ['PyQt5.QtOpenGL', 'PyQt5._QOpenGLFunctions_2_0'] for info in loader.walk_components(): - imports.append('qutebrowser.components.' + info.name) + imports.append(info.name) return imports diff --git a/qutebrowser/extensions/loader.py b/qutebrowser/extensions/loader.py index d7f9b2533..2679e89dc 100644 --- a/qutebrowser/extensions/loader.py +++ b/qutebrowser/extensions/loader.py @@ -51,13 +51,19 @@ def walk_components() -> typing.Iterator[ComponentInfo]: yield from _walk_normal() +def _walk_error(name: str): + raise ImportError("Failed to import {}".format(name)) + + def _walk_normal() -> typing.Iterator[ComponentInfo]: """Walk extensions when not using PyInstaller.""" - for _finder, name, ispkg in pkgutil.walk_packages(components.__path__): + for _finder, name, ispkg in pkgutil.walk_packages( + path=components.__path__, + prefix=components.__name__ + '.', + onerror=_walk_error): if ispkg: continue - fullname = components.__name__ + '.' + name - yield ComponentInfo(name=fullname) + yield ComponentInfo(name=name) def _walk_pyinstaller() -> typing.Iterator[ComponentInfo]: