Skip to content

Commit 1de9e28

Browse files
pmav99nyalldawson
authored andcommitted
Make it easier to subclass "Grass7AlgorithmProvider"
Backport of 9202: #9202 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
1 parent c88e7ab commit 1de9e28

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

python/plugins/processing/algs/grass7/Grass7AlgorithmProvider.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444

4545
class Grass7AlgorithmProvider(QgsProcessingProvider):
4646

47+
# Subclasses of `Grass7AlgorithmProvider` should override `descriptionFolder`
48+
# and set its value to their own description folder.
49+
descriptionFolder = Grass7Utils.grassDescriptionPath()
50+
4751
def __init__(self):
4852
super().__init__()
4953
self.algs = []
@@ -99,7 +103,7 @@ def setActive(self, active):
99103

100104
def createAlgsList(self):
101105
algs = []
102-
folder = Grass7Utils.grassDescriptionPath()
106+
folder = self.descriptionFolder
103107
for descriptionFile in os.listdir(folder):
104108
if descriptionFile.endswith('txt'):
105109
try:

0 commit comments

Comments
 (0)