-
Notifications
You must be signed in to change notification settings - Fork 44
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
Add no_arr and no_str parameters #38
Conversation
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.
@vinnamkim using either parameter does not show any length, but merely empty strings/arrays, which I don't think is in the spirit of what ros2/ros2cli#136 describes. Is this still a work in progress?
I missed these things. I'll update PR. |
@hidmic PR is updated. |
result += to_string(value) | ||
|
||
if no_arr is True and any( | ||
isinstance(value, t) for t in [list, tuple, array.array, numpy.ndarray]): |
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.
@vinnamkim I think that you may achieve the same behavior by just doing:
isinstance(value, (list, tuple, array.array, numpy.ndarray))
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.
Fixed.
return r | ||
result = '' | ||
# We rely on __slots__ retaining the order of the fields in the .msg file. | ||
for field_name in msg.__slots__: | ||
value = getattr(msg, field_name) | ||
field_type = msg._fields_and_field_types[field_name[1:]] |
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.
@vinnamkim consider querying for the field type only if and when it's actually necessary
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.
In the next commit, field_type
is passed to to_string()
and if-statement to check no_arr
is moved to to_string()
. It becomes inevitable to query for the field type only if and when it's actually necessary.
if no_arr is True and any( | ||
isinstance(value, t) for t in [list, tuple, array.array, numpy.ndarray]): | ||
d[field_name[1:]] = '<array type: <{0}>, length: <{1}>>'.format( | ||
field_type, len(value)) |
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.
@vinnamkim the same two previous observations apply.
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.
Found a few more details while trying this out locally.
""" | ||
Convert a ROS message to string of comma-separated values. | ||
|
||
:param msg: The ROS message to convert. | ||
:param truncate_length: Truncate values for all message fields to this length. | ||
This does not truncate the list of message fields. | ||
:param no_arr: Exclude array fields of the message | ||
:param no_str: Exclude string fields of the message | ||
:returns: A string of comma-separated values representing the input message. | ||
""" | ||
def to_string(val): |
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.
@vinnamkim this isn't dealing with e.g. strings in arrays.
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.
Fixed.
if no_arr is True and any( | ||
isinstance(value, t) for t in [list, tuple, array.array, numpy.ndarray]): | ||
result += '<array type: <{0}>, length: <{1}>>'.format( | ||
field_type, len(value)) |
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.
@vinnamkim when the type is already bounded, length information turns out to be redundant. Consider dropping it in that case.
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.
Fixed
@vinnamkim Are you still planning to work on this PR? |
@hidmic @dirk-thomas |
""" | ||
Convert a ROS message to a YAML string. | ||
|
||
:param msg: The ROS message to convert. | ||
:param truncate_length: Truncate values for all message fields to this length. | ||
This does not truncate the list of message fields. | ||
:param no_arr: Exclude array fields of the message | ||
:param no_str: Exclude string fields of the message |
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.
@vinnamkim missing period at the end of the sentence.
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.
Fixed.
""" | ||
Convert a ROS message to a YAML string. | ||
|
||
:param msg: The ROS message to convert. | ||
:param truncate_length: Truncate values for all message fields to this length. | ||
This does not truncate the list of message fields. | ||
:param no_arr: Exclude array fields of the message |
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.
@vinnamkim missing period at the end of the sentence.
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.
Fixed.
""" | ||
Convert a ROS message to string of comma-separated values. | ||
|
||
:param msg: The ROS message to convert. | ||
:param truncate_length: Truncate values for all message fields to this length. | ||
This does not truncate the list of message fields. | ||
:param no_arr: Exclude array fields of the message |
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.
@vinnamkim missing period at the end of the sentence.
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.
Fixed.
""" | ||
Convert a ROS message to string of comma-separated values. | ||
|
||
:param msg: The ROS message to convert. | ||
:param truncate_length: Truncate values for all message fields to this length. | ||
This does not truncate the list of message fields. | ||
:param no_arr: Exclude array fields of the message | ||
:param no_str: Exclude string fields of the message |
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.
@vinnamkim missing period at the end of the sentence.
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.
Fixed.
break | ||
r += to_string(v) | ||
if no_arr is True and field_type is not None: | ||
if(callable(has_maximum_size) and has_maximum_size()): |
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.
@vinnamkim why the outer parenthesis?
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.
Fixed.
""" | ||
Convert a ROS message to an OrderedDict. | ||
|
||
:param msg: The ROS message to convert. | ||
:param truncate_length: Truncate values for all message fields to this length. | ||
This does not truncate the list of fields (ie. the dictionary keys). | ||
:param no_arr: Exclude array fields of the message |
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.
@vinnamkim missing period at the end of the sentence.
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.
Fixed.
""" | ||
Convert a ROS message to an OrderedDict. | ||
|
||
:param msg: The ROS message to convert. | ||
:param truncate_length: Truncate values for all message fields to this length. | ||
This does not truncate the list of fields (ie. the dictionary keys). | ||
:param no_arr: Exclude array fields of the message | ||
:param no_str: Exclude string fields of the message |
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.
@vinnamkim missing period at the end of the sentence.
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.
Fixed.
value = value[:truncate_length] + '...' | ||
elif isinstance(value, (list, tuple, array.array, numpy.ndarray)): | ||
# Since arrays and ndarrays can't contain mixed types convert to list | ||
typename = tuple if isinstance(value, tuple) else list | ||
if truncate_length is not None and len(value) > truncate_length: | ||
if no_arr is True and field_type is not None: | ||
if(callable(has_maximum_size) and has_maximum_size()): |
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.
@vinnamkim meta: I think you can derive both field_type
and maximum_size
from the value type, but that doesn't do much to the actual functionality. @dirk-thomas I'd like to know what you think.
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 guess field_type
is well defined in _fields_and_field_types
of the parent of the value
. It would be more complicated to derive field_type
from the value
directly.
@hidmic updated PR with your comments. |
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.
LGTM but for one detail. Arrays show like e.g.
'<array type: <uint64[3]>>'
Bounded sequences show like e.g.:
'<array type: <sequence<uint64, 3>>>'
Unbounded sequences show like e.g.:
'<array type: <sequence<uint64>>, length: <3>>'
Thus, I wonder if the array type
prefix isn't somewhat confusing when dealing with sequences.
@jacobperron thoughts about that? If you think it's fine, let's just merge this PR and ros2/ros2cli#216. |
I think it would be nice if the first part of the output would distinguish between
Aside: can we drop the angle brackets for the type and length? E.g.
|
@hidmic @jacobperron Updated PR with fixing the prefix to distinguish among
|
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.
LGTM. The PR needs a rebase and then I'll trigger CI.
Thank you for iterating with us!
- For the issue : ros2/ros2cli#136 Signed-off-by: vinnamkim <vinnam.kim@gmail.com>
Signed-off-by: vinnamkim <vinnam.kim@gmail.com>
Signed-off-by: vinnamkim <vinnam.kim@gmail.com>
Signed-off-by: vinnamkim <vinnam.kim@gmail.com>
891f902
to
4322ed2
Compare
Signed-off-by: vinnamkim <vinnam.kim@gmail.com>
4322ed2
to
dda23d4
Compare
Rebased PR. Thank you. |
CI up to rosidl_runtime_py and CLI packages (includes ros2/ros2cli#216): |
Signed-off-by: vinnamkim <vinnam.kim@gmail.com>
@vinnamkim Thanks for the feature! |
* Add no_arr and no_str params - For the issue : ros2/ros2cli#136 Signed-off-by: vinnamkim <vinnam.kim@gmail.com> * Fix formats on --noarr and --nostr Signed-off-by: vinnamkim <vinnam.kim@gmail.com> * Fix review Signed-off-by: vinnamkim <vinnam.kim@gmail.com> * Fix comments and remove outer parenthesis Signed-off-by: vinnamkim <vinnam.kim@gmail.com> * Distinguish between array, sequence and unbounded sequence Signed-off-by: vinnamkim <vinnam.kim@gmail.com> * Fix test failure Signed-off-by: vinnamkim <vinnam.kim@gmail.com>
Connects to ros2/ros2cli#136
Signed-off-by: vinnamkim vinnam.kim@gmail.com