Skip to content

Commit

Permalink
PluginManager: Minor code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
phw committed Sep 10, 2023
1 parent 83ea460 commit 7d84330
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions picard/pluginmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 7d84330

Please sign in to comment.