From bcda101daec81f64685b11bd398c4af853f4f040 Mon Sep 17 00:00:00 2001 From: Philipp Wolfer Date: Sat, 9 Sep 2023 17:17:52 +0200 Subject: [PATCH] pluginmanager: Avoid multiple calls to PathFinder().find_spec() --- picard/pluginmanager.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/picard/pluginmanager.py b/picard/pluginmanager.py index c979c782f..70c056692 100644 --- a/picard/pluginmanager.py +++ b/picard/pluginmanager.py @@ -598,17 +598,17 @@ class PluginMetaPathFinder(MetaPathFinder): if not fullname.startswith(_PLUGIN_MODULE_PREFIX): return None plugin_name = fullname[len(_PLUGIN_MODULE_PREFIX):] - for plugin_dir in _plugin_dirs: - spec = None - if hasattr(zipimport.zipimporter, 'find_spec'): # Python >= 3.10 + spec = None + if hasattr(zipimport.zipimporter, 'find_spec'): # Python >= 3.10 + for plugin_dir in _plugin_dirs: zipfilename = os.path.join(plugin_dir, plugin_name + '.zip') zip_importer = zip_import(zipfilename) if zip_importer: spec = zip_importer.find_spec(fullname) - if not spec: - spec = importlib.machinery.PathFinder().find_spec(fullname, [plugin_dir]) - if spec and spec.loader: - return spec + break + if not spec: + spec = importlib.machinery.PathFinder().find_spec(fullname, _plugin_dirs) + return spec if spec and spec.loader else None sys.meta_path.append(PluginMetaPathFinder())