-
Notifications
You must be signed in to change notification settings - Fork 164
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
Set multiple parameters #728
base: rolling
Are you sure you want to change the base?
Conversation
198575d
to
81ca3bb
Compare
81ca3bb
to
dfb3b8b
Compare
ros2param/ros2param/verb/set.py
Outdated
def build_parameters(self, params): | ||
parameters = [] | ||
if len(params) % 2: | ||
raise RuntimeError('Must pass list of parameter name and value pairs') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like we shouldn't raise an exception here; previously, this would result in printing out a usage message and returning with shell result 2. I think we should try to emulate that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true -- printing out the whole backtrace and all is rather ugly. I've added an action to the new parameter argument list to maintain the same error behavior as before
ros2cli/ros2param/ros2param/verb/set.py
Lines 32 to 41 in 2e90009
class RequireParameterPairAction(argparse.Action): | |
"""Argparse action to validate parameter argument pairs.""" | |
def __call__(self, parser, args, values, option_string=None): | |
if len(values) == 0: | |
parser.error('No parameters specified') | |
SystemExit(2) | |
if len(values) % 2: | |
parser.error('Must provide parameter name and value pairs') | |
setattr(args, self.dest, values) |
λ ros2 param set /add_two_ints_server
usage: ros2 param set [-h] [--spin-time SPIN_TIME] [-s]
[--no-daemon] [--include-hidden-nodes]
node_name [parameters ...]
ros2 param set: error: No parameter pairs specified
λ echo $?
2
λ ros2 param set /add_two_ints_server true
usage: ros2 param set [-h] [--spin-time SPIN_TIME] [-s]
[--no-daemon] [--include-hidden-nodes]
node_name [parameters ...]
ros2 param set: error: Must provide parameter name and value pairs
ros2param/ros2param/verb/set.py
Outdated
if result.successful: | ||
msg = 'Set parameter successful' | ||
if result.reason: | ||
msg += ': ' + result.reason | ||
print(msg) | ||
else: | ||
msg = 'Setting parameter failed' | ||
if result.reason: | ||
msg += ': ' + result.reason | ||
print(msg, file=sys.stderr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two blocks are very similar, with the exception of successful
vs failed
in the output string, and also using stderr
or stdout
for printing. It feels like they can be combined, though I'm not sure of that so just take this as a suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've combined them here but I feel like it's a little unnecessairly terse.
for i, result in enumerate(results):
print('Set parameter ' + parameters[i].name + ' ' +
'successful' if result.successful else 'failed' +
str(result.reason) if result.reason else '',
file=sys.stderr if result.successful else sys.stdout)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, agreed. This is kind of hard to read. I'd say let's go back to the previous version (sorry).
@clalancette Friendly ping -- I've made the requested changes, can you take a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think test needs to be added in ros2cli/ros2param/test
to set and get the parameters w/o error.
648d77e
to
d5d5010
Compare
Done in 5547f87. There weren't any tests for the set verb before. |
multiple param set standardize argument errors & address pr comments revert parameter set print code address pr comments add test_verb_set Signed-off-by: Brian Chen <[email protected]>
To support Python 3.6 (no fstrings), and also to slightly clean up the generation of output. Signed-off-by: Chris Lalancette <[email protected]>
5547f87
to
21caf35
Compare
I just rebased this and made some small fixes to it. With this, it is looking good to me but I'd like another opinion before I merge it. I'll go ahead and run CI, though. |
For backwards compatibility with Just an observation, not blocking |
Yeah, I agree completely. The thing is I think the backwards compatibility is important. We could do a thing where the first argument is I'm honestly not sure. @ros2/team thoughts? |
Perhaps it's possible to maintain the old behavior or at least emit a warning if a sequence of arguments is given and none of the arguments contain the := delimiter, thus indicating that it's a
Breaking compatibility to improve usability is worthwhile.
|
Another option could be to have EDIT: I realized this is exactly what @clalancette suggested, sorry. I think it'd be better to emit a warning for |
Support setting multiple parameters at once using
ros2 param set
See: #727 (comment)
This PR uses features from #716 (Diff: brianc/parameter_client...brianc/multiple_param_set)
Example usage:
ros2 param set /test_node int_param 12 str_param hello_world