[GRASS-dev] Accessing GRASS GIS addons from within QGIS

Dear QGIS team,
Dear GRASS GIS team,

I kindly ask for some response on how to offer access to a GRASS GIS
add-on through QGIS.

I have asked again about this, months ago. Yet there are still
technicalities for which I need help to understand.

So, please bear with me and thank you in advance for any support.

I developed a GRASS GIS add-on which has been recently published as
an Open Source tool through the European Commission [0,1].

[0] https://gitlab.com/natcapes/r.estimap.recreation
[1] https://gitlab.com/natcapes/r.estimap.recreation/blob/master/C_2018_8970_F1_COMMISSION_DECISION_EN_V3_P1_1006093.PDF

The tool is in a working state, yet under bug-fixing and refactoring to
make it both easier to use and to maintain.

The official documentation of the QGIS project, leads to two ways to
"access" a GRASS GIS add-on through QGIS:

1. the QGIS GRASS plugin [2]

2. the Processing Toolbox [3] -- this wiki-page is created by me based
on detailed guidelines kindly provided by Médéric Ribreux

[2] https://www.qgis.org/en/site/getinvolved/development/addinggrasstools.html
[3] https://trac.osgeo.org/grass/wiki/QGIS-Processing-GRASS-Provider

1) For the QGIS GRASS plugin, there must be a way to update the file
https://github.com/qgis/QGIS/blob/b3d2619976a69d7fb67b884492da491dfaba287c/src/plugins/grass/modules/default.qgc
which sets up the list of available GRASS GIS modules under the QGIS
GRASS plugin. This file seems not to be writable for normal users, after
installation of QGIS, i.e. there is no write access to
non-admin/non-root users.

Under Linux, for example, this file is/might be under
`/usr/share/qgis/grass/modules` and its owner is `root`. And, there
seems no way to edit/update this file from within QGIS at run-time.

While I can customise locally, as root, my own QGIS GRASS plugin, and
add an entry for a/ny GRASS GIS add-on, I cannot, however, understand
how any user that installs QGIS, GRASS GIS and any desired GRASS GIS
add-on, can access it through QGIS.

Something similar is valid under Windows as well.

Can/should I write my own routine(s) to ensure the appearance of my/any
GRASS GIS add-on in the list of available QGIS GRASS modules? This is
something suggested in an earlier thread [*].

Is it possible at all to update this file at run-time, for any user,
under any major/well known operating system?

2) For the Processing Toolbox, my understanding is that it requires
significant effort to reflect the logic of a GRASS GIS module using
QGIS' Processing interface to GRASS GIS. Am I wrong?

If I go for the Processing option, however, is it possible to inegrate a
GRASS GIS add-on under the QGIS' Processing GRASS provider, at run-time?

Essentially, is it possible to write (new) "description" files under
`python/plugins/processing/algs/grass7/description/` which are likely
placed under directories owned by the root/admin user?

If none of the above can ensure access to a GRASS GIS add-on through
QGIS, one that is to be installed using `g.extension` after having
installed QGIS and GRASS GIS, what would you then recommend?

Do only core GRASS GIS modules work for any of the above mentioned
options?

Thank you,

Nikos Alexandris

--
Earlier posts:

https://lists.osgeo.org/pipermail/qgis-developer/2018-October/054828.html
[*] https://lists.osgeo.org/pipermail/qgis-developer/2018-October/054829.html

Related fora:

- https://gis.stackexchange.com/a/173536/5256
- https://gis.stackexchange.com/a/223770/5256
- https://gis.stackexchange.com/a/176723/5256
- https://gis.stackexchange.com/a/294157/5256

--
Nikos Alexandris | Remote Sensing & Geomatics
GPG Key Fingerprint 6F9D4506F3CA28380974D31A9053534B693C4FB3

* Nyall Dawson <nyall.dawson@gmail.com> [2019-02-07 17:05:14 +1000]:

On Thu, 7 Feb 2019 at 01:41, Nikos Alexandris <nik@nikosalexandris.net> wrote:

2) For the Processing Toolbox, my understanding is that it requires
significant effort to reflect the logic of a GRASS GIS module using
QGIS' Processing interface to GRASS GIS. Am I wrong?

If I go for the Processing option, however, is it possible to inegrate a
GRASS GIS add-on under the QGIS' Processing GRASS provider, at run-time?

Essentially, is it possible to write (new) "description" files under
`python/plugins/processing/algs/grass7/description/` which are likely
placed under directories owned by the root/admin user?

If none of the above can ensure access to a GRASS GIS add-on through
QGIS, one that is to be installed using `g.extension` after having
installed QGIS and GRASS GIS, what would you then recommend?

My recommendation:

I would implement expose your GRASS add-on as its own processing
provider. You would base this almost entirely off the existing
processing grass provider, but with its own set of description files
exposing only your add on modules. You should be able to do this by
importing the existing grass provider classes, and overwriting the
provider code to have a new ID/name/icon/etc.

This would also make it easy to redistribute - you'd wrap your
provider into a plugin, and then could distribute via the normal
plugin channels. And if you do it right (and only import existing
processing grass code, minimising the copy/paste of this code), then
you're provider will automatically inherit any future fixes and
features added to the main grass provider.

Dear Nyal,

thank you for your time and the recommendation. I guess this is
currently the only reasonable approach to distribute the "provider" and the
plugin.

Kind regards, Nikos

Dear lists,

following Nyall's recommendation [0],

[0] https://lists.osgeo.org/pipermail/qgis-developer/2019-February/056155.html

a QGIS plug-in [1] adds a provider in QGIS' Processing Toolbox to
expose a GRASS GIS add-on [2].

[1] https://gitlab.com/pmav99/estimap_recreation_qgis
[2] https://gitlab.com/natcapes/r.estimap.recreation

The installation of the/any GRASS GIS add-on, is independent from QGIS
and its Processing framework. Nevertheless, it would be nice from a UX
point of view, if the plug-in can also install the GRASS GIS add-on
itself.

To perform the installation, the following is required:

1) enter in a GRASS GIS session
2) run `g.extension -a`, parse the output and check if the add-on is installed
3) if the add-on is not installed, then run `g.extension
extension='r.estimap.recreation'`

These steps do not manipulate any data.

Grass7Utils features the following relevant methods [3]:

- `executeGrass`
- `startGrassSession`
- `endGrassSession`

[3] https://github.com/qgis/QGIS/blob/1d8bd004a619cb001cfc469fd42a6f71ecb93888/python/plugins/processing/algs/grass7/Grass7Utils.py#L365-L469

There is, however, no documentation about what the arguments should be.

1. Is this the appropriate way to do this?
2. Is there any documentation or example code?
3. Where would it make sense to "plug-in" this code? Currently,
`Grass7AlgorithmProvider` is subclassed without essential modifications
[4] and it would make sense to keep it this way [5].

[4] https://github.com/qgis/QGIS/pull/9202
[5] https://lists.osgeo.org/pipermail/qgis-developer/2019-February/056155.html

Kind regards, Nikos