When processing is initialized in external scripts, ensure the GRASS,

SAGA and OTB providers are included by default

Fixes #45935
This commit is contained in:
Nyall Dawson 2022-02-01 12:21:11 +10:00
parent 93c0510f3e
commit dd368a4289
4 changed files with 44 additions and 2 deletions

View File

@ -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.

View File

@ -114,6 +114,33 @@ class Processing(object):
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()

View File

@ -107,6 +107,21 @@ class TestProcessingGeneral(unittest.TestCase):
# 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()

View File

@ -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.