Skip to content

Commit

Permalink
When processing is initialized in external scripts, ensure the GRASS,
Browse files Browse the repository at this point in the history
SAGA and OTB providers are included by default

Fixes #45935
  • Loading branch information
nyalldawson authored and github-actions[bot] committed Feb 1, 2022
1 parent 76a0157 commit afb3bb5
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion python/core/auto_generated/qgsapplication.sip.in
Expand Up @@ -85,7 +85,7 @@ to change due to centralization.
static const char *QGIS_ORGANIZATION_DOMAIN;
static const char *QGIS_APPLICATION_NAME;

QgsApplication( SIP_PYLIST argv, bool GUIenabled, QString profileFolder = QString(), QString platformName = "desktop" ) / PostHook = __pyQtQAppHook__ / [( int &argc, char **argv, bool GUIenabled, const QString &profileFolder = QString(), const QString &platformName = "desktop" )];
QgsApplication( SIP_PYLIST argv, bool GUIenabled, QString profileFolder = QString(), QString platformName = "external" ) / PostHook = __pyQtQAppHook__ / [( int &argc, char **argv, bool GUIenabled, const QString &profileFolder = QString(), const QString &platformName = "desktop" )];
%Docstring
Constructor for QgsApplication.

Expand Down
27 changes: 27 additions & 0 deletions python/plugins/processing/core/Processing.py
Expand Up @@ -116,6 +116,33 @@ def initialize():
p = c()
if QgsApplication.processingRegistry().addProvider(p):
Processing.BASIC_PROVIDERS.append(p)

if QgsApplication.platform() == 'external':
# for external applications we must also load the builtin providers stored in separate plugins
try:
from grassprovider.Grass7AlgorithmProvider import Grass7AlgorithmProvider
p = Grass7AlgorithmProvider()
if QgsApplication.processingRegistry().addProvider(p):
Processing.BASIC_PROVIDERS.append(p)
except ImportError:
pass

try:
from otbprovider.OtbAlgorithmProvider import OtbAlgorithmProvider
p = OtbAlgorithmProvider()
if QgsApplication.processingRegistry().addProvider(p):
Processing.BASIC_PROVIDERS.append(p)
except ImportError:
pass

try:
from sagaprovider.SagaAlgorithmProvider import SagaAlgorithmProvider
p = SagaAlgorithmProvider()
if QgsApplication.processingRegistry().addProvider(p):
Processing.BASIC_PROVIDERS.append(p)
except ImportError:
pass

# And initialize
ProcessingConfig.initialize()
ProcessingConfig.readSettings()
Expand Down
15 changes: 15 additions & 0 deletions python/plugins/processing/tests/ProcessingGeneralTest.py
Expand Up @@ -107,6 +107,21 @@ def testRunAndLoadResults(self):
# Python should NOT have ownership
self.assertFalse(sip.ispyowned(layer))

def testProviders(self):
"""
When run from a standalone script (like this test), ensure that the providers from separate plugins are available
"""
providers = [p.id() for p in QgsApplication.processingRegistry().providers()]
self.assertIn('qgis', providers)
self.assertIn('native', providers)
self.assertIn('gdal', providers)
self.assertIn('project', providers)
self.assertIn('script', providers)
self.assertIn('model', providers)
self.assertIn('grass7', providers)
self.assertIn('saga', providers)
self.assertIn('otb', providers)


if __name__ == '__main__':
nose2.main()
2 changes: 1 addition & 1 deletion src/core/qgsapplication.h
Expand Up @@ -181,7 +181,7 @@ class CORE_EXPORT QgsApplication : public QApplication
* \param profileFolder optional string representing the profile to load at startup
* \param platformName the QGIS platform name, e.g., "desktop", "server", "qgis_process" or "external" (for external CLI scripts)
*/
QgsApplication( SIP_PYLIST argv, bool GUIenabled, QString profileFolder = QString(), QString platformName = "desktop" ) / PostHook = __pyQtQAppHook__ / [( int &argc, char **argv, bool GUIenabled, const QString &profileFolder = QString(), const QString &platformName = "desktop" )];
QgsApplication( SIP_PYLIST argv, bool GUIenabled, QString profileFolder = QString(), QString platformName = "external" ) / PostHook = __pyQtQAppHook__ / [( int &argc, char **argv, bool GUIenabled, const QString &profileFolder = QString(), const QString &platformName = "desktop" )];
% MethodCode
// The Python interface is a list of argument strings that is modified.

Expand Down

0 comments on commit afb3bb5

Please sign in to comment.