Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
tibonihoo/yapsy#11 changes yapsy plugin loading to not use the deprecated imp module any more. However, as a side effect of that, it breaks this already-kinda-ugly hack, and we have to make it even uglier! yapsy used to import the module like this: imp.load_module(plugin_module_name,plugin_file...) where `plugin_module_name` was the modified, "unique" name it creates early in `loadPlugins`. Interestingly, when you import a module like that, it gets added to `sys.modules` under *both* the modified name and its 'real' name, viz: >>> import sys >>> import imp >>> imp.load_module("someothername", None, "/usr/lib/python3.12/site-packages/yapsy/__init__.py", ("py", "r", imp.PKG_DIRECTORY)) <module 'someothername' from '/usr/lib/python3.12/site-packages/yapsy/__init__.py'> >>> sys.modules["someothername"] <module 'someothername' from '/usr/lib/python3.12/site-packages/yapsy/__init__.py'> >>> sys.modules["yapsy"] <module 'yapsy' from '/usr/lib/python3.12/site-packages/yapsy/__init__.py'> That's why this hack worked. However, now yapsy imports the module using importlib, then adds it to `sys.modules` itself, *only* under the modified "unique" name, not under its original name. So sys.modules["unmodifiedpluginname"] is now a KeyError. I can't think of a less ugly fix than this, unfortunately. We *could* try sending a patch for yapsy to add it under both the modified and unmodified names, but that would be somewhat tricky in yapsy's design, and I also suspect yapsy would consider it to actually be unwanted behavior. Maybe what we really need is to send a patch for yapsy to just provide an interface to find a plugin's filesystem path... Signed-off-by: Adam Williamson <[email protected]>
- Loading branch information