Skip to content
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

Merged
merged 6 commits into from
Jul 9, 2019

Conversation

vinnamkim
Copy link
Contributor

@vinnamkim vinnamkim commented Apr 6, 2019

Connects to ros2/ros2cli#136

Signed-off-by: vinnamkim vinnam.kim@gmail.com

@tfoote tfoote added the in review Waiting for review (Kanban column) label Apr 6, 2019
Copy link
Contributor

@hidmic hidmic left a 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?

@vinnamkim
Copy link
Contributor Author

@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.

@vinnamkim
Copy link
Contributor Author

@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]):
Copy link
Contributor

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))

Copy link
Contributor Author

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:]]
Copy link
Contributor

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

Copy link
Contributor Author

@vinnamkim vinnamkim May 24, 2019

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))
Copy link
Contributor

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.

Copy link
Contributor

@hidmic hidmic left a 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):
Copy link
Contributor

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.

Copy link
Contributor Author

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))
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@jacobperron jacobperron added in progress Actively being worked on (Kanban column) and removed in review Waiting for review (Kanban column) labels Apr 25, 2019
@dirk-thomas
Copy link
Member

@vinnamkim Are you still planning to work on this PR?

@vinnamkim
Copy link
Contributor Author

@hidmic @dirk-thomas
Sorry for the late response, I updated PR.

"""
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
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

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()):
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

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()):
Copy link
Contributor

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.

Copy link
Contributor Author

@vinnamkim vinnamkim Jun 21, 2019

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.

@vinnamkim
Copy link
Contributor Author

@hidmic updated PR with your comments.

@hidmic hidmic added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Jun 24, 2019
Copy link
Contributor

@hidmic hidmic left a 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.

@hidmic
Copy link
Contributor

hidmic commented Jun 28, 2019

@jacobperron thoughts about that? If you think it's fine, let's just merge this PR and ros2/ros2cli#216.

@jacobperron
Copy link
Member

jacobperron commented Jul 1, 2019

I think it would be nice if the first part of the output would distinguish between array and sequence. For example, we could add an extra case if the field_type is a sequence and get output like the following:

# Array
'<array type: <uint64[3]>>'
# Sequence
'<sequence type: <uint64[3]>>'
# Unbounded sequence
'<sequence type: <uint64>, length: <3>>'

Aside: can we drop the angle brackets for the type and length? E.g.

# Array
'<array type: uint64[3]>'`
# Unbouded
'<sequence type: uint64, length: 3>'

@vinnamkim
Copy link
Contributor Author

@hidmic @jacobperron Updated PR with fixing the prefix to distinguish among array, sequence, and unbounded sequence. --no-arr is working now as follows.

array: '<array type: int32[5]>'
sequence: '<sequence type: int32[5], length: 4>'
unbounded_sequence: '<sequence type: int32, length: 3>'
pose_array: '<array type: geometry_msgs/msg/Pose[5]>'
pose_sequence: '<sequence type: geometry_msgs/msg/Pose[5], length: 4>'
pose_unbounded_sequence: '<sequence type: geometry_msgs/msg/Pose, length: 3>'

Copy link
Member

@jacobperron jacobperron left a 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>
Signed-off-by: vinnamkim <vinnam.kim@gmail.com>
@vinnamkim
Copy link
Contributor Author

LGTM. The PR needs a rebase and then I'll trigger CI.

Thank you for iterating with us!

Rebased PR. Thank you.

@jacobperron
Copy link
Member

jacobperron commented Jul 9, 2019

CI up to rosidl_runtime_py and CLI packages (includes ros2/ros2cli#216):

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

Signed-off-by: vinnamkim <vinnam.kim@gmail.com>
@jacobperron
Copy link
Member

  • Linux Build Status
  • aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@jacobperron jacobperron merged commit 3a1bb97 into ros2:master Jul 9, 2019
@jacobperron
Copy link
Member

@vinnamkim Thanks for the feature!

jacobperron pushed a commit to ros2/rosidl_runtime_py that referenced this pull request Sep 19, 2019
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in review Waiting for review (Kanban column)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants