From 527d1706c2b842bdebf9a83224dc76619d7f6ffc Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Fri, 2 Apr 2021 03:30:09 +0000 Subject: [PATCH] [core/module] add fallback for module loading Looks like some Python versions work with find_spec(), others with spec_from_file_location(), so add find_spec() as fallback. fixes #779 --- bumblebee_status/core/module.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bumblebee_status/core/module.py b/bumblebee_status/core/module.py index 5be7a4f..c4b66a4 100644 --- a/bumblebee_status/core/module.py +++ b/bumblebee_status/core/module.py @@ -27,10 +27,16 @@ def import_user(module_short, config, theme): return getattr(mod, "Module")(config, theme) else: log.debug("importing {} from user via importlib.util".format(module_short)) - spec = importlib.util.spec_from_file_location("modules.{}".format(module_short), usermod) - mod = importlib.util.module_from_spec(spec) - spec.loader.exec_module(mod) - return mod.Module(config, theme) + try: + spec = importlib.util.spec_from_file_location("modules.{}".format(module_short), usermod) + mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(mod) + return mod.Module(config, theme) + except Exception as e: + spec = importlib.util.find_spec("modules.{}".format(module_short), usermod) + mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(mod) + return mod.Module(config, theme) raise ImportError("not found") """Loads a module by name