-
-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] grass.pygrass Module parameter checking is too strict #3237
Comments
Command line interface parser allows parameter (option) values such as 'val' when full value should be 'value'. Parameter class from pygrass does the checking, but does not know about these rules. This addition covers the simple case of val-value which is not much work to implement and maintain. It does not cover more complex cases with underscores and legacy aliases. The test covers the issue for use=value change in v.to.rast made in OSGeo#3110. Strict checking in pygrass is discussed in OSGeo#3237.
Here is where I'm at right now with teaching pygrass about the backwards compatibility supported by the command line interface parser: I can use return code (0 or 1) of def update(self, *args, **kargs):
...
# Pseudo-code
for parameter in parameters:
if (parameter known to pygrass):
set_the_parameter()
else:
# Before marking parameter as invalid, ask the underlying tool.
if (not self._ask_if_parameters_are_valid()):
raise ParameterError("%s is not a valid parameter." % key)
# If valid, exception is not raised, but parameter is not set anyway.
def _ask_if_parameters_are_valid(self):
"""Ask the underlying tool whether the parameters are valid or not"""
cmd = self.make_cmd()
cmd.append("--json")
self.start_time = time.time()
process = subprocess.run(
cmd,
capture_output=True,
env=self.env_,
)
return process.returncode == 0 |
I can make it work by just removing all the parameter checking from pygrass. I'm wondering if people make use of that or not. As a reminder, run_command family of functions from grass.script is relying on the underlying tool to report any issues with parameters. While this is not disabled by grass.pygrass, the Module class from grass.pygrass has its own layer of checks before it runs the tool, so you get grass.exceptions.ParameterError or standard ValueError for the individual parameter name or value. |
Command line interface parser allows parameter (option) values such as 'val' when full value should be 'value'. Parameter class from pygrass does the checking, but does not know about these rules. This addition covers the simple case of val-value which is not much work to implement and maintain. It does not cover more complex cases with underscores and legacy aliases. The test covers the issue for use=value change in v.to.rast made in #3110. Strict checking in pygrass is discussed in #3237.
Command line interface parser allows parameter (option) values such as 'val' when full value should be 'value'. Parameter class from pygrass does the checking, but does not know about these rules. This addition covers the simple case of val-value which is not much work to implement and maintain. It does not cover more complex cases with underscores and legacy aliases. The test covers the issue for use=value change in v.to.rast made in OSGeo#3110. Strict checking in pygrass is discussed in OSGeo#3237.
Describe the bug
The Module class from grass.pygrass does not understand parser rules for renaming and shortening which creates potential issues for backward compatibility and confusion when switching between command line and Python.
Details
The parser for command line interface of tools (modules) allows renamed options, renamed flags, shorter option names, and shorter option values, for example:
The original motivation for this feature was keeping backward compatibility between v6 and v7 and keeping the convenience of short names when using command line interactively. The convenience still holds and the backward compatibility feature is potentially even more important when we want to fix things without waiting for a next major release.
The run_command family of functions from grass.script understands that (or simply leaves that to the parser implementation), for example:
However, grass.pygrass.modules.Module does its own checking and it does not know about any of the features of parser, for example:
The shortening for convenience is much less important in Python than in an interactive command line interface. Possibly, it is even promoting a better practice by requiring full names. However, the backward compatibility is not supported rendering every change backward incompatible regardless of the parser system in place which is addressing the issue.
To Reproduce
Expected behavior
grass.pygrass.modules.Module should follow the parser rules. This will allow us to introduce changes in backward compatible manner between major version and will allow users to benefit from parser's backward compatibility features for major releases (even when limit ourselves to making changes only for major releases).
Using the parser to do the validation seems like a good solution to me as it relies on a single source of truth about validity of the interface. This would mean skipping the validation in Python completely (like run_command does) or calling the tool itself to check the parameters (like
--json
but with different error handling).Screenshots
System description
Additional context
Backward compatibility issue was created in #3110. Renaming most recently came up in #2189.
The text was updated successfully, but these errors were encountered: