Closed AdamWill closed 1 year ago
Revised to try two different possible 'unique' module names, since I found just doing one or the other wasn't enough in a real-world test with a real-world plugin...
I'm not actually sure which of the three possible names is 'most preferred' and which is 'least preferred', we can tweak it if anyone has ideas.
Adding paths to yapsy would be preferable, but if we can still get the module ourselves in some way, that’s good enough.
I'll have a quick look at how viable it would be to add this to yapsy at some point.
Revised. I used mod_
not module_
because there is already mod_path
and mod_dir
.
Thanks for fixing this! I’ll merge this, and if there’s any improvement in yapsy, let us know (or send another PR 😄)
that was quick! I think it may be possible to do this a 'better' way using yaspy's ability to set a callback for loadPlugins
. I'm playing with that ATM. If it works out I'll send a follow-up PR.
https://github.com/tibonihoo/yapsy/pull/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 inloadPlugins
. Interestingly, when you import a module like that, it gets added tosys.modules
under both the modified name and its 'real' name, viz: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...
Pull Request Checklist
Description