Skip to content

[Feat] Implement module level library file injection into python path #2022

@marisn

Description

@marisn

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?

Metadata

Metadata

Labels

PythonRelated code is in PythonenhancementNew feature or request

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions