From 7d84330c5f1020a97ac4ab04e39246779dd66c87 Mon Sep 17 00:00:00 2001 From: Philipp Wolfer Date: Sun, 10 Sep 2023 16:31:19 +0200 Subject: [PATCH] PluginManager: Minor code cleanup --- picard/pluginmanager.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/picard/pluginmanager.py b/picard/pluginmanager.py index cc89b717e8..3ffbcb9f39 100644 --- a/picard/pluginmanager.py +++ b/picard/pluginmanager.py @@ -215,8 +215,11 @@ def register_plugin_dir(path): def plugin_dir_for_path(path): for plugin_dir in plugin_dirs(): - if path.startswith(plugin_dir): - return plugin_dir + try: + if os.path.commonpath((path, plugin_dir)) == plugin_dir: + return plugin_dir + except ValueError: + pass return path @@ -338,7 +341,7 @@ def _load_plugin(self, name): module_pathname = spec.origin if isinstance(spec.loader, zipimport.zipimporter): manifest_data = load_zip_manifest(spec.loader.archive) - if module_pathname.endswith("__init__.py"): + if os.path.basename(module_pathname) == '__init__.py': module_pathname = os.path.dirname(module_pathname) plugin_dir = plugin_dir_for_path(module_pathname)