Skip to content

Commit

Permalink
Add new plugin metadata string to indicate whether a plugin
Browse files Browse the repository at this point in the history
implements Processing providers

Plugins which implement providers should include the

    hasProcessingProvider=yes

line within their metadata.txt file. This allows for rapid
identification of all plugins which implement Processing
functionality.
  • Loading branch information
nyalldawson committed Mar 2, 2019
1 parent 2f82bab commit 558d536
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 5 deletions.
2 changes: 2 additions & 0 deletions python/plugins/processing/metadata.txt
Expand Up @@ -14,3 +14,5 @@ icon=:/images/themes/default/processingAlgorithm.svg
homepage=http://qgis.org
tracker=https://issues.qgis.org/projects/qgis/issues
repository=https://github.com/qgis/QGIS

hasProcessingProvider=yes
13 changes: 12 additions & 1 deletion src/python/qgspythonutils.h
Expand Up @@ -167,17 +167,28 @@ class PYTHON_EXPORT QgsPythonUtils
* This command adds a plugin to active plugins and calls initProcessing(),
* initializing only Processing related components of that plugin.
*
* \see pluginHasProcessingProvider()
* \since QGIS 3.8
*/
virtual bool startProcessingPlugin( const QString &packageName ) = 0;

/**
* Helper function to return some information about a plugin.
*
* \param function metadata component to return. Must match one of the strings: name, type, version, or description.
* \param function metadata component to return. Must match one of the strings: name, type, version, description, hasProcessingProvider.
*/
virtual QString getPluginMetadata( const QString &pluginName, const QString &function ) = 0;

/**
* Returns TRUE if a plugin implements a Processing provider.
*
* This is determined by checking the plugin metadata for the "hasProcessingProvider=yes" line.
*
* \see startProcessingPlugin()
* \since QGIS 3.8
*/
virtual bool pluginHasProcessingProvider( const QString &pluginName ) = 0;

/**
* Confirms that the plugin can be uninstalled.
*/
Expand Down
5 changes: 5 additions & 0 deletions src/python/qgspythonutilsimpl.cpp
Expand Up @@ -609,6 +609,11 @@ QString QgsPythonUtilsImpl::getPluginMetadata( const QString &pluginName, const
return res;
}

bool QgsPythonUtilsImpl::pluginHasProcessingProvider( const QString &pluginName )
{
return getPluginMetadata( pluginName, QStringLiteral( "hasProcessingProvider" ) ).compare( QLatin1String( "yes" ), Qt::CaseInsensitive ) == 0;
}

bool QgsPythonUtilsImpl::loadPlugin( const QString &packageName )
{
QString output;
Expand Down
1 change: 1 addition & 0 deletions src/python/qgspythonutilsimpl.h
Expand Up @@ -87,6 +87,7 @@ class QgsPythonUtilsImpl : public QgsPythonUtils
bool startPlugin( const QString &packageName ) override;
bool startProcessingPlugin( const QString &packageName ) override;
QString getPluginMetadata( const QString &pluginName, const QString &function ) override;
bool pluginHasProcessingProvider( const QString &pluginName ) override;
bool canUninstallPlugin( const QString &packageName ) override;
bool unloadPlugin( const QString &packageName ) override;
bool isPluginEnabled( const QString &packageName ) const override;
Expand Down
20 changes: 20 additions & 0 deletions tests/src/app/testqgisapppython.cpp
Expand Up @@ -43,6 +43,7 @@ class TestQgisAppPython : public QObject
void hasPython();
void plugins();
void pythonPlugin();
void pluginMetadata();
void runString();
void evalString();

Expand Down Expand Up @@ -105,6 +106,25 @@ void TestQgisAppPython::pythonPlugin()
QVERIFY( !mQgisApp->mPythonUtils->startProcessingPlugin( QStringLiteral( "PluginPathTest" ) ) );
}

void TestQgisAppPython::pluginMetadata()
{
QCOMPARE( mQgisApp->mPythonUtils->getPluginMetadata( QStringLiteral( "not a plugin" ), QStringLiteral( "name" ) ), QStringLiteral( "__error__" ) );
QCOMPARE( mQgisApp->mPythonUtils->getPluginMetadata( QStringLiteral( "PluginPathTest" ), QStringLiteral( "invalid" ) ), QStringLiteral( "__error__" ) );
QCOMPARE( mQgisApp->mPythonUtils->getPluginMetadata( QStringLiteral( "PluginPathTest" ), QStringLiteral( "name" ) ), QStringLiteral( "plugin path test" ) );
QCOMPARE( mQgisApp->mPythonUtils->getPluginMetadata( QStringLiteral( "PluginPathTest" ), QStringLiteral( "qgisMinimumVersion" ) ), QStringLiteral( "2.0" ) );
QCOMPARE( mQgisApp->mPythonUtils->getPluginMetadata( QStringLiteral( "PluginPathTest" ), QStringLiteral( "description" ) ), QStringLiteral( "desc" ) );
QCOMPARE( mQgisApp->mPythonUtils->getPluginMetadata( QStringLiteral( "PluginPathTest" ), QStringLiteral( "version" ) ), QStringLiteral( "0.1" ) );
QCOMPARE( mQgisApp->mPythonUtils->getPluginMetadata( QStringLiteral( "PluginPathTest" ), QStringLiteral( "author" ) ), QStringLiteral( "HM/Oslandia" ) );
QCOMPARE( mQgisApp->mPythonUtils->getPluginMetadata( QStringLiteral( "PluginPathTest" ), QStringLiteral( "email" ) ), QStringLiteral( "hugo.mercier@oslandia.com" ) );
QCOMPARE( mQgisApp->mPythonUtils->getPluginMetadata( QStringLiteral( "PluginPathTest" ), QStringLiteral( "hasProcessingProvider" ) ), QStringLiteral( "__error__" ) );
QVERIFY( !mQgisApp->mPythonUtils->pluginHasProcessingProvider( QStringLiteral( "x" ) ) );
QVERIFY( !mQgisApp->mPythonUtils->pluginHasProcessingProvider( QStringLiteral( "PluginPathTest" ) ) );

QCOMPARE( mQgisApp->mPythonUtils->getPluginMetadata( QStringLiteral( "ProcessingPluginTest" ), QStringLiteral( "name" ) ), QStringLiteral( "processing plugin test" ) );
QCOMPARE( mQgisApp->mPythonUtils->getPluginMetadata( QStringLiteral( "ProcessingPluginTest" ), QStringLiteral( "hasProcessingProvider" ) ), QStringLiteral( "yes" ) );
QVERIFY( mQgisApp->mPythonUtils->pluginHasProcessingProvider( QStringLiteral( "ProcessingPluginTest" ) ) );
}

void TestQgisAppPython::runString()
{
QVERIFY( mQgisApp->mPythonUtils->runString( "a=1+1" ) );
Expand Down
@@ -1,7 +1,7 @@
[general]
name=plugin path test
qgisMinimumVersion=2.0
name=processing plugin test
qgisMinimumVersion=3.8
description=desc
version=0.1
author=HM/Oslandia
email=hugo.mercier@oslandia.com
author=matt cauthin
hasProcessingProvider=yes

0 comments on commit 558d536

Please sign in to comment.