You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to create a plugin. I made a module for UI, one for database and one for funcionalities. All that modules are import in main module (with geany.plugin).
If i want to import correctly these module i have to import them into init of class which inherit from geany.plugin.
I attach my beginning plugin with the error (change the extension to zip).
I'm working under Linux Mint , and my plugin is under .conf directory in my home.
I'm having also issues here. I have a class file in combination with an init.py inside a subfolder, but importing scripts seems not to recognize it. Could it be possible, that module search path due to the way of handling Python file maybe is screwed up?
Probably the geany conf dir is not in Python's sys.path. The sys.path will probably start with where the geanypy Python script was loaded from. You can try printing sys.path from a pyplugin to see.
If thats the case you can just add an appropriate dir to sys.path.
Geany config dir is really not inside. Only geanypy related path is /usr/local/lib/geany-plugins/geanypy. From my understanding, folder of file should be also part of this. Can this being done by geanypy via default?
The problem is Geanypy loads plugins itself, it doesn't use Python import so no paths are added to sys.path. The potential problem of adding the plugin directory to sys.path is that it is a global, ie any value added for one plugin will affect the load path of another. The best way is for a plugin to append what it needs to sys.path possibly using the directory part of its __FILE__ , import its modules and then restore sys.path so it won't affect other plugins.
As an aside, plugins should be aware that they are sharing a Python instance, so loading stuff in the global namespace (like modules) may also clash with another plugin.
FWIW, I think this is the only sys.path modifications, needed in order to be able to import the geany module. As @elextr mentioned, the loader "manually" imports plugins by file path, like this.
I agree that the Python import system is quite annoying, and quite the most poorly documented part of the language, the package layout and so on being in PEPs only referred to from the manual, so searching the manual finds nothing about it. (end rant, and Python3 docs are a bit better :)
What it might be possible to do is to have the system and user geanypy plugin directories set up as modules (by having an empty __init__.py in them). Geanypy could load them as modules with known names eg system_plugins and user_plugins. Then the plugins can load stuff in their directory and below by
import user_plugins.franks_plugin.module.whatever
I have used this technique on Python 3, but I'm not sure if it works on Python 2.
And as Enrico would say "somebodys go to do it, PRs are welcome" :)
Hi, thanks to watch this issue. I use Python 2. For the moment, i juste have to import the module once, but i think it could be a problem for another dev.
Activity
frlan commentedon Feb 20, 2015
I'm having also issues here. I have a class file in combination with an init.py inside a subfolder, but importing scripts seems not to recognize it. Could it be possible, that module search path due to the way of handling Python file maybe is screwed up?
elextr commentedon Feb 20, 2015
Probably the geany conf dir is not in Python's
sys.path. Thesys.pathwill probably start with where the geanypy Python script was loaded from. You can try printingsys.pathfrom a pyplugin to see.If thats the case you can just add an appropriate dir to
sys.path.frlan commentedon Feb 20, 2015
Geany config dir is really not inside. Only geanypy related path is /usr/local/lib/geany-plugins/geanypy. From my understanding, folder of file should be also part of this. Can this being done by geanypy via default?
elextr commentedon Feb 20, 2015
The problem is Geanypy loads plugins itself, it doesn't use Python import so no paths are added to
sys.path. The potential problem of adding the plugin directory tosys.pathis that it is a global, ie any value added for one plugin will affect the load path of another. The best way is for a plugin to append what it needs tosys.pathpossibly using the directory part of its__FILE__, import its modules and then restoresys.pathso it won't affect other plugins.As an aside, plugins should be aware that they are sharing a Python instance, so loading stuff in the global namespace (like modules) may also clash with another plugin.
codebrainz commentedon Feb 21, 2015
FWIW, I think this is the only
sys.pathmodifications, needed in order to be able to import thegeanymodule. As @elextr mentioned, the loader "manually" imports plugins by file path, like this.frlan commentedon Feb 21, 2015
Not sure whether it's the best solution as it looks little hackish to me:
I'm try to succeed with something like that
for the meanwhile. Will keep you updated whether it a working solution.
elextr commentedon Feb 21, 2015
I agree that the Python import system is quite annoying, and quite the most poorly documented part of the language, the package layout and so on being in PEPs only referred to from the manual, so searching the manual finds nothing about it. (end rant, and Python3 docs are a bit better :)
What it might be possible to do is to have the system and user geanypy plugin directories set up as modules (by having an empty
__init__.pyin them). Geanypy could load them as modules with known names egsystem_pluginsanduser_plugins. Then the plugins can load stuff in their directory and below byimport user_plugins.franks_plugin.module.whatever
I have used this technique on Python 3, but I'm not sure if it works on Python 2.
And as Enrico would say "somebodys go to do it, PRs are welcome" :)
deusyss commentedon Mar 3, 2015
Hi, thanks to watch this issue. I use Python 2. For the moment, i juste have to import the module once, but i think it could be a problem for another dev.
deusyss commentedon Jul 13, 2015
Hi robblue2x,
Thanks for this information. I didn't know imp, but after doc reading, it seems very nice. Thank you for this tip :)