Skip to content


[grass7] Make it easier to subclass "Grass7AlgorithmProvider"
Browse files Browse the repository at this point in the history
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.


  • 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):
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'):
Expand Down

0 comments on commit 1d8bd00

Please sign in to comment.