grass.tools: Use Tools in v.dissolve #6148
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This uses grass.tools in the v.dissolve tool for whatever was previously done by the grass.script.run_command functions. There is no strong reason to do this migration except to test grass.tool more and create more examples, but that's a good reason. Nice thing is that simple calls once the Tools object is created are shorter by one line. Tools objects need to be created. (I opted for creating them again in functions as opposed to passing one to all functions.)
To keep the behavior close to the original, some of the Tools objects do not capture stdout and stderr so that it is printed as it would be with run_command. This means that progress messages will be printed from the underlying tools and error messages will be part of that output as well. (This choice might have been different for a newly written tool or for different parts of a tool.) Places which capture stdin for further processing are kept with the defaults, so stderr is captured and will be part of an exception, but will not be visible otherwise (but was previously visible).
Places which use tool wrappers from grass.script are left as is. Replacement of the convenience wrappers is waiting for JSON outputs of specific tools, so the current change is only focusing on run_command and friends.
Running the pytest test takes the same time with the old and new code (20-29s depending on external factors but consistent for both versions).