Adding plug-in-paths to python path
I'm trying to figure out the best way to add all of the paths listed in
gimprc under 'plug-in-path' to the python path in order to properly
support the python package/module structure.
http://docs.python.org/tutorial/modules.html#packages
Adding this would allow better organization of larger python plugins and
import statements would work correctly.
As far as I can tell there is three problems to solve.
1) Getting the directories added to sys.path
2) When gimp scans directories for plugins to register, it'll also
need to search through all of the folders
3) When scanning the files, ignore the files without the register
function. (right now is outputs a warning)
Right now I'm just trying to solve the first problem.
The first option is to add the following code(or something similar) to
gimpfu.py and gimpplugin.py
Most plugins are going to use gimpfu, but adding it in both spots would
work for those that just use gimpplugin.
import sys
try:
gimprc_file = open(gimp.personal_rc_file("gimprc"), "r")
for line in gimprc_file:
if line.startswith("(plug-in-path"):
for path in line.split('"')[1].split(':'):
sys.path.append(path)
except:
pass
This approach works, but the same code is in two different spots.
2nd option that I came up with is to make the change in gimpmodule.c in
the initgimp function. Having the change in this module would work
everywhere.
I'm not a C person so my best attempt so far is something along the lines of
PyRun_SimpleString("import sys");
Loop paths here
PyRun_SimpleString("sys.path.append('looped_paths')");
I tried using gimp_gimprc_query("plug-in-path") to get the paths, but
calling this in initgimp causes the 'gimp wire read' error.
So I figure using this approach, I'll have to load and parse the gimprc
manually.
I would really like to see this functionality added to trunk so if you
have any suggestions on what would be an acceptable solution I'd really
appreciate it...
Thanks...