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

@ -180,7 +180,7 @@ 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).

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,