Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[grass7] Make it easier to subclass "Grass7AlgorithmProvider"
After @nyalldawson suggestion [1], we've implemented a Processing plugin
that exposes a GRASS Addon [2]. In order to do this we had to subclass
`Grass7AlgorithmProvider` and override `createAlgsList()`.

`createAlgsList()` had to be overriden in order to change the
"description folder" location.

Nyall wrote:

> And if you do it right (and only import existing
> processing grass code, minimising the copy/paste of this code), then
> your provider will automatically inherit any future fixes and
> features added to the main grass provider.

With this commit we convert the `descriptionFolder` to a class attribute
and in this way, subclasses of `Grass7AlgorithmProvider` will no longer
have to override `createAlgsList()` and will be able to continue inheriting
future enhancements.

References:

1. https://lists.osgeo.org/pipermail/qgis-developer/2019-February/056155.html
2. https://gitlab.com/pmav99/estimap_recreation_qgis/blob/948820b1c0068a7112cb67bc8537d8074e9defb1/estimap_recreation_provider.py#L40-59
  • Loading branch information
pmav99 authored and nyalldawson committed Feb 19, 2019
1 parent 06fab90 commit 1d8bd00
Showing 1 changed file with 5 additions and 1 deletion.
Expand Up @@ -44,6 +44,10 @@

class Grass7AlgorithmProvider(QgsProcessingProvider):

# Subclasses of `Grass7AlgorithmProvider` should override `descriptionFolder`
# and set its value to their own description folder.
descriptionFolder = Grass7Utils.grassDescriptionPath()

def __init__(self):
super().__init__()
self.algs = []
Expand Down Expand Up @@ -99,7 +103,7 @@ def setActive(self, active):

def createAlgsList(self):
algs = []
folder = Grass7Utils.grassDescriptionPath()
folder = self.descriptionFolder
for descriptionFile in os.listdir(folder):
if descriptionFile.endswith('txt'):
try:
Expand Down

0 comments on commit 1d8bd00

Please sign in to comment.