Rename more references to grass7 to version-less "grass"

This commit is contained in:
Nyall Dawson 2024-02-06 13:57:27 +10:00
parent 0ab66b7b6f
commit ea3a86508e
19 changed files with 59 additions and 60 deletions

View File

@ -138,9 +138,9 @@ ProcessingGdalAlgorithmsGeneralTest
ProcessingGdalAlgorithmsRasterTest
ProcessingGdalAlgorithmsVectorTest
ProcessingCheckValidityAlgorithmTest
ProcessingGrass7AlgorithmsImageryTest
ProcessingGrass7AlgorithmsRasterTestPt1
ProcessingGrass7AlgorithmsRasterTestPt2
ProcessingGrass7AlgorithmsVectorTest
ProcessingGrassAlgorithmsImageryTest
ProcessingGrassAlgorithmsRasterTestPt1
ProcessingGrassAlgorithmsRasterTestPt2
ProcessingGrassAlgorithmsVectorTest
PyQgsCoordinateReferenceSystemModel
PyQgsProviderRegistry

View File

@ -103,7 +103,7 @@ def regroupRasters(alg, parameters, context, src, group, subgroup=None, extFile=
# extFileName = new_parameters[ext]
# if extFileName:
# shortFileName = os.path.basename(extFileName)
# destPath = os.path.join(Grass7Utils.grassMapsetFolder(),
# destPath = os.path.join(GrassUtils.grassMapsetFolder(),
# 'PERMANENT',
# 'group', new_parameters[group.name()],
# 'subgroup', new_parameters[subgroup.name()],
@ -184,7 +184,7 @@ def verifyRasterNum(alg, parameters, context, rasters, mini, maxi=None):
def createDestDir(alg, toFile):
""" Generates an mkdir command for GRASS7 script """
""" Generates an mkdir command for GRASS script """
# Creates the destination directory
command = "{} \"{}\"".format(
"MD" if isWindows() else "mkdir -p",
@ -194,7 +194,7 @@ def createDestDir(alg, toFile):
def moveFile(alg, fromFile, toFile):
""" Generates a move command for GRASS7 script """
""" Generates a move command for GRASS script """
createDestDir(alg, toFile)
command = "{} \"{}\" \"{}\"".format(
"MOVE /Y" if isWindows() else "mv -f",
@ -205,7 +205,7 @@ def moveFile(alg, fromFile, toFile):
def copyFile(alg, fromFile, toFile):
""" Generates a copy command for GRASS7 script """
""" Generates a copy command for GRASS script """
createDestDir(alg, toFile)
command = "{} \"{}\" \"{}\"".format(
"COPY /Y" if isWindows() else "cp -f",

View File

@ -31,7 +31,7 @@ if os.name == 'nt':
def rliPath():
"""Return r.li GRASS7 user dir"""
"""Return r.li GRASS user dir"""
if isWindows():
homeDir = win32api.GetShortPathName(os.path.expanduser('~'))
return os.path.join(homeDir, 'AppData', 'Roaming', 'GRASS7', 'r.li')
@ -82,17 +82,17 @@ def configFile(alg, parameters, context, feedback, outputTxt=False):
"""Handle inline configuration
:param parameters:
"""
# Where is the GRASS7 user directory ?
userGrass7Path = rliPath()
if not os.path.isdir(userGrass7Path):
mkdir(userGrass7Path)
if not os.path.isdir(os.path.join(userGrass7Path, 'output')):
mkdir(os.path.join(userGrass7Path, 'output'))
# Where is the GRASS user directory ?
user_grass_path = rliPath()
if not os.path.isdir(user_grass_path):
mkdir(user_grass_path)
if not os.path.isdir(os.path.join(user_grass_path, 'output')):
mkdir(os.path.join(user_grass_path, 'output'))
# If we have a configuration file, we need to copy it into user dir
if parameters['config']:
fileName = alg.parameterAsString(parameters, 'config', context)
configFilePath = os.path.join(userGrass7Path, os.path.basename(fileName))
configFilePath = os.path.join(user_grass_path, os.path.basename(fileName))
# Copy the file
shutil.copy(parameters['config'], configFilePath)
# Change the parameter value
@ -101,7 +101,7 @@ def configFile(alg, parameters, context, feedback, outputTxt=False):
elif parameters['config_txt']:
# Creates a temporary txt file in user r.li directory
tempConfig = os.path.basename(getTempFilename(context=context))
configFilePath = os.path.join(userGrass7Path, tempConfig)
configFilePath = os.path.join(user_grass_path, tempConfig)
# Inject rules into temporary txt file
with open(configFilePath, "w") as f:
f.write(alg.parameterAsString(parameters, 'config_txt', context))
@ -128,9 +128,9 @@ def configFile(alg, parameters, context, feedback, outputTxt=False):
def moveOutputTxtFile(alg, parameters, context):
# Find output file name:
txtPath = alg.parameterAsString(parameters, 'output_txt', context)
userGrass7Path = rliPath()
user_grass_path = rliPath()
output = os.path.join(userGrass7Path, 'output',
output = os.path.join(user_grass_path, 'output',
alg.parameterAsString(parameters, 'output', context))
# move the file
if isWindows():

View File

@ -14,7 +14,7 @@
* *
***************************************************************************
This Python module handles pre-treatment operations for v.net.* GRASS7 modules.
This Python module handles pre-treatment operations for v.net.* GRASS modules.
Before using a v.net module you often have to incorporate a points layer into
the network vector map.
"""

View File

@ -2,8 +2,8 @@ A short guide for creating and editing GRASS GIS processing algorithms:
-----------------------------------------------------------------------
For a GRASS command to be executed within QGIS a plain text description file is needed
to define the inputs required by the command, the output it generates and the parameters
that are used to configure it. Each command is described in a separate text file, but some
to define the inputs required by the command, the output it generates and the parameters
that are used to configure it. Each command is described in a separate text file, but some
commands can be split into several algorithms by using more than one description file,
so that more than one entry is shown in the algorithms list. Splitting a grass command
was originally done because the processing provider did not support optional parameters,
@ -15,7 +15,7 @@ create new algorithms or improve existing algorithms.
Each file starts with three lines containing:
- The name of the grass command to call to execute the algorithm (e.g. v.buffer)
- The description of the algorithm to show to the user. For split commands you must
- The description of the algorithm to show to the user. For split commands you must
include the algorithm id first, e.g.:
r.sun.insoltime - Solar irradiance and irradiation model (daily sums).
and
@ -155,7 +155,7 @@ Example: *QgsProcessingParameterBoolean|-i|Output raster map as integer|False
RELOADING ALGORITHM DESCRIPTIONS
---------------------------------------
You do not need to restart QGIS after editing or creating an algorithm description - simply click the wrench icon in the processing toolbox, then click OK, and QGIS will reload the descriptions.
You do not need to restart QGIS after editing or creating an algorithm description - simply click the wrench icon in the processing toolbox, then click OK, and QGIS will reload the descriptions.
ADVANCED PROCESSING
--------------------------
@ -165,13 +165,13 @@ To save the console output from GRASS to file, simply create a QgsProcessingPara
Example: QgsProcessingParameterFileDestination|html|List of addons|Html files (*.html)|addons_list.html|False
To add additional logic to an algorithm, like a preliminary check on data, the use of more than one GRASS command,
or a transformation of output data, then you need to use the ext mechanism.
or a transformation of output data, then you need to use the ext mechanism.
There are 4 different levels where you can add logic:
- Checking the input parameters, e.g. if you want to verify that two mutually exclusive options have not been both enabled.
- Processing inputs import: if you need to do more than importing input layers.
- Processing the command itself: if you need to chain more than one GRASS command for your algorithm.
- Processing the outputs: if you need to do special things before exporting layers or if you need special export methods.
There are 4 different levels where you can add logic:
- Checking the input parameters, e.g. if you want to verify that two mutually exclusive options have not been both enabled.
- Processing inputs import: if you need to do more than importing input layers.
- Processing the command itself: if you need to chain more than one GRASS command for your algorithm.
- Processing the outputs: if you need to do special things before exporting layers or if you need special export methods.
To add some logic on one (or more) level(s), you have to create a .py file named according to the algorithm name in python/plugins/grassprovider/ext, replacing '.' with '_'.
Then you need to create methods using the respective names:
@ -180,10 +180,10 @@ Then you need to create methods using the respective names:
- Command: processCommand
- Outputs: processOutputs
If there is a Python file with the algorithm name in the ext directory, methods will be imported from the file and run instead of the common methods (there are "standard" processCommand/processInputs/processOutputs/checkParameterValuesBeforeExecuting methods in the code of the GRASS provider for QGIS Processing, in python/plugins/grassprovider/Grass7Algorithm.py).
If there is a Python file with the algorithm name in the ext directory, methods will be imported from the file and run instead of the common methods (there are "standard" processCommand/processInputs/processOutputs/checkParameterValuesBeforeExecuting methods in the code of the GRASS provider for QGIS Processing, in python/plugins/grassprovider/grass_algorithm.py).
If we take the example of v.what.rast, there is an ext file: ext/v_what_rast.py.
In this file there is a processCommand method. It just launches the standard processCommand but with the delOutputs option set to True (we do not want to have standard outputs).
Then there is also a customized processOutputs which exports the input vector as an output for QGIS. We need to do this because v.what.rast modifies values directly in the input vector layer instead of generating a new output, so we have to build this output ourself.
Then there is also a customized processOutputs which exports the input vector as an output for QGIS. We need to do this because v.what.rast modifies values directly in the input vector layer instead of generating a new output, so we have to build this output ourself.
If you want to do special things in the ext mechanism, you will need to read (and understand) the GRASS provider code standard methods in Grass7Algorithm.py.

View File

@ -117,7 +117,7 @@ class GrassAlgorithm(QgsProcessingAlgorithm):
self._short_description = ''
self._group = ''
self._groupId = ''
self.grass7Name = ''
self.grass_name = ''
self.params = []
self.hardcodedStrings = []
self.inputLayers = []
@ -216,9 +216,9 @@ class GrassAlgorithm(QgsProcessingAlgorithm):
return None
if os.path.exists(helpPath):
return QUrl.fromLocalFile(os.path.join(helpPath, '{}.html'.format(self.grass7Name))).toString()
return QUrl.fromLocalFile(os.path.join(helpPath, '{}.html'.format(self.grass_name))).toString()
else:
return helpPath + '{}.html'.format(self.grass7Name)
return helpPath + '{}.html'.format(self.grass_name)
def initAlgorithm(self, config=None):
"""
@ -254,7 +254,7 @@ class GrassAlgorithm(QgsProcessingAlgorithm):
"""
Create algorithm parameters and outputs from parsed description
"""
self.grass7Name = description.grass_command
self.grass_name = description.grass_command
self._name = description.name
self._short_description = description.short_description
self._display_name = description.display_name
@ -588,7 +588,7 @@ class GrassAlgorithm(QgsProcessingAlgorithm):
# Add the default parameters commands
self.commands.append(command)
QgsMessageLog.logMessage(self.tr('processInputs end. Commands: {}').format(self.commands), 'Grass7', Qgis.MessageLevel.Info)
QgsMessageLog.logMessage(self.tr('processInputs end. Commands: {}').format(self.commands), 'Grass', Qgis.MessageLevel.Info)
def processCommand(self, parameters, context, feedback, delOutputs=False):
"""
@ -598,7 +598,7 @@ class GrassAlgorithm(QgsProcessingAlgorithm):
:param delOutputs: do not add outputs to commands.
"""
noOutputs = [o for o in self.parameterDefinitions() if o not in self.destinationParameterDefinitions()]
command = '{} '.format(self.grass7Name)
command = '{} '.format(self.grass_name)
command += '{}'.join(self.hardcodedStrings)
# Add algorithm command
@ -743,7 +743,7 @@ class GrassAlgorithm(QgsProcessingAlgorithm):
command += ' --overwrite'
self.commands.append(command)
QgsMessageLog.logMessage(self.tr('processCommands end. Commands: {}').format(self.commands), 'Grass7', Qgis.MessageLevel.Info)
QgsMessageLog.logMessage(self.tr('processCommands end. Commands: {}').format(self.commands), 'Grass', Qgis.MessageLevel.Info)
def vectorOutputType(self, parameters, context):
"""Determine vector output types for outputs"""

View File

@ -161,7 +161,7 @@ class GrassProvider(QgsProcessingProvider):
def supportsNonFileBasedOutput(self):
"""
GRASS7 Provider doesn't support non file based outputs
GRASS Provider doesn't support non file based outputs
"""
return False

View File

@ -150,7 +150,7 @@ class GrassUtils:
def grassBin():
"""
Find GRASS binary path on the operating system.
Sets global variable Grass7Utils.command
Sets global variable GrassUtils.command
"""
def searchFolder(folder):
@ -223,7 +223,7 @@ class GrassUtils:
def grassPath():
"""
Find GRASS path on the operating system.
Sets global variable Grass7Utils.path
Sets global variable GrassUtils.path
"""
if GrassUtils.path is not None:
return GrassUtils.path
@ -543,7 +543,7 @@ class GrassUtils:
# the layers.
@staticmethod
def endGrassSession():
# shutil.rmtree(Grass7Utils.grassMapsetFolder(), True)
# shutil.rmtree(GrassUtils.grassMapsetFolder(), True)
GrassUtils.sessionRunning = False
GrassUtils.sessionLayers = {}
GrassUtils.projectionSet = False
@ -564,7 +564,7 @@ class GrassUtils:
if GrassUtils.isGrassInstalled:
return
# We check the version of Grass7
# We check the version of Grass
if GrassUtils.installedVersion() is not None:
# For Ms-Windows, we check GRASS binaries
if isWindows():

View File

@ -33,7 +33,7 @@ from grassprovider.grass_provider import GrassProvider
from grassprovider.grass_utils import GrassUtils
class TestGrass7AlgorithmsImageryTest(QgisTestCase, AlgorithmsTestBase.AlgorithmsTest):
class TestGrassAlgorithmsImageryTest(QgisTestCase, AlgorithmsTestBase.AlgorithmsTest):
@classmethod
def setUpClass(cls):
@ -51,7 +51,7 @@ class TestGrass7AlgorithmsImageryTest(QgisTestCase, AlgorithmsTestBase.Algorithm
shutil.rmtree(path)
def test_definition_file(self):
return 'grass7_algorithms_imagery_tests.yaml'
return 'grass_algorithms_imagery_tests.yaml'
if __name__ == '__main__':

View File

@ -34,7 +34,7 @@ from grassprovider.grass_provider import GrassProvider
from grassprovider.grass_utils import GrassUtils
class TestGrass7AlgorithmsRasterTest(QgisTestCase, AlgorithmsTestBase.AlgorithmsTest):
class TestGrassAlgorithmsRasterTest(QgisTestCase, AlgorithmsTestBase.AlgorithmsTest):
@classmethod
def setUpClass(cls):
@ -52,7 +52,7 @@ class TestGrass7AlgorithmsRasterTest(QgisTestCase, AlgorithmsTestBase.Algorithms
shutil.rmtree(path)
def test_definition_file(self):
return 'grass7_algorithms_raster_tests1.yaml'
return 'grass_algorithms_raster_tests1.yaml'
if __name__ == '__main__':

View File

@ -42,7 +42,7 @@ from grassprovider.grass_utils import GrassUtils
testDataPath = os.path.join(os.path.dirname(__file__), 'testdata')
class TestGrass7AlgorithmsRasterTest(QgisTestCase, AlgorithmsTestBase.AlgorithmsTest):
class TestGrassAlgorithmsRasterTest(QgisTestCase, AlgorithmsTestBase.AlgorithmsTest):
@classmethod
def setUpClass(cls):
@ -63,13 +63,13 @@ class TestGrass7AlgorithmsRasterTest(QgisTestCase, AlgorithmsTestBase.Algorithms
shutil.rmtree(path)
def test_definition_file(self):
return 'grass7_algorithms_raster_tests2.yaml'
return 'grass_algorithms_raster_tests2.yaml'
def testNeighbors(self):
context = QgsProcessingContext()
input_raster = os.path.join(testDataPath, 'custom', 'grass7', 'float_raster.tif')
alg = QgsApplication.processingRegistry().createAlgorithmById('grass7:r.neighbors')
alg = QgsApplication.processingRegistry().createAlgorithmById('grass:r.neighbors')
self.assertIsNotNone(alg)
temp_file = os.path.join(self.temp_dir, 'grass_output.tif')

View File

@ -47,7 +47,7 @@ from grassprovider.grass_utils import GrassUtils
testDataPath = os.path.join(os.path.dirname(__file__), 'testdata')
class TestGrass7AlgorithmsVectorTest(QgisTestCase, AlgorithmsTestBase.AlgorithmsTest):
class TestGrassAlgorithmsVectorTest(QgisTestCase, AlgorithmsTestBase.AlgorithmsTest):
@classmethod
def setUpClass(cls):
@ -68,7 +68,7 @@ class TestGrass7AlgorithmsVectorTest(QgisTestCase, AlgorithmsTestBase.Algorithms
shutil.rmtree(path)
def test_definition_file(self):
return 'grass7_algorithms_vector_tests.yaml'
return 'grass_algorithms_vector_tests.yaml'
def testMemoryLayerInput(self):
# create a memory layer and add to project and context
@ -88,7 +88,7 @@ class TestGrass7AlgorithmsVectorTest(QgisTestCase, AlgorithmsTestBase.Algorithms
context = QgsProcessingContext()
context.setProject(QgsProject.instance())
alg = QgsApplication.processingRegistry().createAlgorithmById('grass7:v.buffer')
alg = QgsApplication.processingRegistry().createAlgorithmById('grass:v.buffer')
self.assertIsNotNone(alg)
temp_file = os.path.join(self.temp_dir, 'grass_output.shp')
@ -148,7 +148,7 @@ class TestGrass7AlgorithmsVectorTest(QgisTestCase, AlgorithmsTestBase.Algorithms
context = QgsProcessingContext()
context.setProject(QgsProject.instance())
alg = QgsApplication.processingRegistry().createAlgorithmById('grass7:v.buffer')
alg = QgsApplication.processingRegistry().createAlgorithmById('grass:v.buffer')
self.assertIsNotNone(alg)
temp_file = os.path.join(self.temp_dir, 'grass_output_sel.shp')
parameters = {'input': QgsProcessingFeatureSourceDefinition('testmem', True),
@ -202,7 +202,7 @@ class TestGrass7AlgorithmsVectorTest(QgisTestCase, AlgorithmsTestBase.Algorithms
context = QgsProcessingContext()
context.setProject(QgsProject.instance())
alg = QgsApplication.processingRegistry().createAlgorithmById('grass7:v.buffer')
alg = QgsApplication.processingRegistry().createAlgorithmById('grass:v.buffer')
self.assertIsNotNone(alg)
temp_file = os.path.join(self.temp_dir, 'grass_output.gpkg')

View File

@ -1,4 +1,4 @@
# Here is a list of grass7 algorithms without test units
# Here is a list of grass algorithms without test units
## Raster algorithms
@ -99,4 +99,4 @@
## Vector algorithms
We need to handle gml for output and input for GRASS7 algorithms before creating tests !
We need to handle gml for output and input for GRASS algorithms before creating tests !

View File

@ -117,7 +117,7 @@ class TestProcessingGeneral(QgisTestCase):
self.assertIn('project', providers)
self.assertIn('script', providers)
self.assertIn('model', providers)
self.assertIn('grass7', providers)
self.assertIn('grass', providers)
if __name__ == '__main__':

View File

@ -48,7 +48,6 @@ per-file-ignores =
python/plugins/db_manager/dlg_sql_window.py:E722,
python/plugins/db_manager/table_viewer.py:E722,
python/plugins/processing/algs/gdal/GdalUtils.py:E722,
python/plugins/processing/algs/grass7/Grass7Utils.py:E722,
python/plugins/processing/algs/qgis/FieldPyculator.py:E722,
python/plugins/processing/algs/qgis/FindProjection.py:E722,
python/plugins/processing/algs/qgis/TextToFloat.py:E722,