Skip to content

Commit

Permalink
Merge pull request #43792 from alexbruy/provider-plugins
Browse files Browse the repository at this point in the history
Move non-native Processing providers into independent plugins
  • Loading branch information
alexbruy committed Jun 21, 2021
2 parents 01fe6c5 + 8541162 commit adc9d07
Show file tree
Hide file tree
Showing 1,236 changed files with 4,043 additions and 538 deletions.
3 changes: 3 additions & 0 deletions python/plugins/CMakeLists.txt
Expand Up @@ -53,6 +53,9 @@ if (WITH_GUI)
add_subdirectory(db_manager)
endif()
add_subdirectory(processing)
add_subdirectory(sagaprovider)
add_subdirectory(grassprovider)
add_subdirectory(otbprovider)
add_subdirectory(MetaSearch)

PY_COMPILE(staged-plugins "${PYTHON_OUTPUT_DIRECTORY}/plugins")
9 changes: 9 additions & 0 deletions python/plugins/grassprovider/CMakeLists.txt
@@ -0,0 +1,9 @@
file(GLOB PY_FILES *.py)
file(GLOB OTHER_FILES grass7.txt metadata.txt)
file(GLOB DESCR_FILES description/*.txt)

add_subdirectory(ext)
add_subdirectory(tests)

PLUGIN_INSTALL(grassprovider . ${PY_FILES} ${OTHER_FILES})
PLUGIN_INSTALL(grassprovider ./description ${DESCR_FILES})
Expand Up @@ -75,7 +75,7 @@

from processing.core.parameters import getParameterFromString

from .Grass7Utils import Grass7Utils
from grassprovider.Grass7Utils import Grass7Utils

from processing.tools.system import isWindows, getTempFilename

Expand Down Expand Up @@ -141,7 +141,7 @@ def __init__(self, descriptionfile):
name = self.name().replace('.', '_')
try:
self.module = importlib.import_module(
'processing.algs.grass7.ext.{}'.format(name))
'grassprovider.ext.{}'.format(name))
except ImportError:
self.module = None

Expand Down Expand Up @@ -445,9 +445,6 @@ def processAlgorithm(self, original_parameters, context, feedback):
outName = out.name()
if outName in parameters:
if outName in self.fileOutputs:
print('ADD', outName)
print('VAL', parameters[outName])
print('VAL 2', self.fileOutputs[outName])
outputs[outName] = self.fileOutputs[outName]
else:
outputs[outName] = parameters[outName]
Expand Down
Expand Up @@ -31,17 +31,13 @@
QgsProcessingUtils,
QgsRuntimeProfiler)
from processing.core.ProcessingConfig import (ProcessingConfig, Setting)
from .Grass7Utils import Grass7Utils
from .Grass7Algorithm import Grass7Algorithm
from grassprovider.Grass7Utils import Grass7Utils
from grassprovider.Grass7Algorithm import Grass7Algorithm
from processing.tools.system import isWindows, isMac

pluginPath = os.path.normpath(os.path.join(
os.path.split(os.path.dirname(__file__))[0], os.pardir))


class Grass7AlgorithmProvider(QgsProcessingProvider):
descriptionFolder = Grass7Utils.grassDescriptionPath()
activateSetting = "ACTIVATE_GRASS7"

def __init__(self):
super().__init__()
Expand All @@ -50,9 +46,6 @@ def __init__(self):
def load(self):
with QgsRuntimeProfiler.profile('Grass Provider'):
ProcessingConfig.settingIcons[self.name()] = self.icon()
if self.activateSetting:
ProcessingConfig.addSetting(Setting(self.name(), self.activateSetting,
self.tr('Activate'), True))
ProcessingConfig.addSetting(Setting(
self.name(),
Grass7Utils.GRASS_LOG_COMMANDS,
Expand Down Expand Up @@ -87,23 +80,12 @@ def load(self):
return True

def unload(self):
if self.activateSetting:
ProcessingConfig.removeSetting(self.activateSetting)
ProcessingConfig.removeSetting(Grass7Utils.GRASS_LOG_COMMANDS)
ProcessingConfig.removeSetting(Grass7Utils.GRASS_LOG_CONSOLE)
ProcessingConfig.removeSetting(Grass7Utils.GRASS_HELP_PATH)
ProcessingConfig.removeSetting(Grass7Utils.GRASS_USE_REXTERNAL)
ProcessingConfig.removeSetting(Grass7Utils.GRASS_USE_VEXTERNAL)

def isActive(self):
if self.activateSetting:
return ProcessingConfig.getSetting(self.activateSetting)
return True

def setActive(self, active):
if self.activateSetting:
ProcessingConfig.setSettingValue(self.activateSetting, active)

def createAlgsList(self):
algs = []
folder = self.descriptionFolder
Expand Down
Expand Up @@ -130,7 +130,7 @@ def installedVersion(run=False):
if line.startswith("7."):
Grass7Utils.version = line
return Grass7Utils.version
except:
except Exception:
pass

return None
Expand Down Expand Up @@ -398,7 +398,7 @@ def executeGrass(commands, feedback, outputCommands=None):
if 'GRASS_INFO_PERCENT' in line:
try:
feedback.setProgress(int(line[len('GRASS_INFO_PERCENT') + 2:]))
except:
except Exception:
pass
else:
if 'r.out' in line or 'v.out' in line:
Expand Down Expand Up @@ -449,7 +449,7 @@ def executeGrass(commands, feedback, outputCommands=None):
try:
feedback.setProgress(int(
line[len('GRASS_INFO_PERCENT') + 2:]))
except:
except Exception:
pass
if any(l in line for l in ['WARNING', 'ERROR']):
loglines.append(line.strip())
Expand Down
43 changes: 43 additions & 0 deletions python/plugins/grassprovider/GrassProviderPlugin.py
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
GrassProviderPlugin.py
---------------------
Date : June 2021
Copyright : (C) 2021 by Alexander Bruy
Email : alexander dot bruy at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""

__author__ = 'Alexander Bruy'
__date__ = 'June 2021'
__copyright__ = '(C) 2021, Alexander Bruy'


from qgis.core import QgsApplication, QgsRuntimeProfiler

with QgsRuntimeProfiler.profile('Import GRASS Provider'):
from grassprovider.Grass7AlgorithmProvider import Grass7AlgorithmProvider


class GrassProviderPlugin:

def __init__(self):
self.provider = Grass7AlgorithmProvider()

def initProcessing(self):
QgsApplication.processingRegistry().addProvider(self.provider)

def initGui(self):
self.initProcessing()

def unload(self):
QgsApplication.processingRegistry().removeProvider(self.provider)
File renamed without changes.
27 changes: 27 additions & 0 deletions python/plugins/grassprovider/__init__.py
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
__init__.py
---------------------
Date : June 2021
Copyright : (C) 2021 by Alexander Bruy
Email : alexander dot bruy at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""

__author__ = 'Alexander Bruy'
__date__ = 'June 2021'
__copyright__ = '(C) 2021, Alexander Bruy'


def classFactory(iface):
from grassprovider.GrassProviderPlugin import GrassProviderPlugin
return GrassProviderPlugin()

0 comments on commit adc9d07

Please sign in to comment.