At the moment if a python script from the scripts/ folder is using more than one file to implement its functionality, there is no easy way how to access those library files from the main module file. There are two modules performing ugly hacks to work around the issue: r.in.wms and wxpyimgview. r.in.wms is a good example of the problem – it stores additional files in etc/r.in.wms and then uses sys.path.insert to access them
|
sys.path.insert(1, os.path.join(os.path.dirname(sys.path[0]), "etc", "r.in.wms")) |
My proposal is to create a new Makefile variable allowing to automatically place specified python files into a subfolder located in a python path. This would provide two benefits – 1) ease up building modules with multiple python files and 2) add ability to use one module functionality in other module without making another "main" library.
Makefile of r.foo could contain something like:
PYTHONLIBFILES = myfunction1 myfunction2
This would result in following directory layout:
$GISBASE/etc/python/grass/modlibs/r_foo/myfunction1.py
Thus one could do:
from grass.modlibs.r_foo import myfunction1
instead of current:
sys.path.insert(1, os.path.join(os.path.dirname(sys.path[0]), "etc", "r.foo"))
import myfunction1
Thoughts? Who knows Makefiles good enough to implement it?
At the moment if a python script from the scripts/ folder is using more than one file to implement its functionality, there is no easy way how to access those library files from the main module file. There are two modules performing ugly hacks to work around the issue: r.in.wms and wxpyimgview. r.in.wms is a good example of the problem – it stores additional files in etc/r.in.wms and then uses
sys.path.insertto access themgrass/scripts/r.in.wms/r.in.wms.py
Line 238 in 2f94d78
My proposal is to create a new Makefile variable allowing to automatically place specified python files into a subfolder located in a python path. This would provide two benefits – 1) ease up building modules with multiple python files and 2) add ability to use one module functionality in other module without making another "main" library.
Makefile of
r.foocould contain something like:PYTHONLIBFILES = myfunction1 myfunction2This would result in following directory layout:
$GISBASE/etc/python/grass/modlibs/r_foo/myfunction1.pyThus one could do:
from grass.modlibs.r_foo import myfunction1instead of current:
Thoughts? Who knows Makefiles good enough to implement it?