Skip to content

store types as tuple of abstract types#33

Merged
dirk-thomas merged 4 commits intoros2:masterfrom
mikaelarguedas:get_slot_types_2
May 3, 2019
Merged

store types as tuple of abstract types#33
dirk-thomas merged 4 commits intoros2:masterfrom
mikaelarguedas:get_slot_types_2

Conversation

@mikaelarguedas
Copy link
Member

@mikaelarguedas mikaelarguedas commented Mar 13, 2019

Replaces #30 now that #24 has merged

Required by ros2/ros2cli#207

Blocked by #34

@mikaelarguedas mikaelarguedas added the in progress Actively being worked on (Kanban column) label Mar 13, 2019
@mikaelarguedas mikaelarguedas added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Mar 13, 2019
@dirk-thomas dirk-thomas added in progress Actively being worked on (Kanban column) and removed in review Waiting for review (Kanban column) labels Mar 15, 2019
@mikaelarguedas
Copy link
Member Author

@dirk-thomas this has been rebased and modified to match changes from #34 and #35.

In order to test that it fixes ros2/ros2cli#59, it needs to be used along ros2/ros2cli#209 (commit ros2/ros2cli@571d1eb)

@mikaelarguedas mikaelarguedas added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Mar 29, 2019
Copy link
Member

@dirk-thomas dirk-thomas left a comment

Choose a reason for hiding this comment

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

A few other packages are currently using get_fields_and_field_types: rqt_py_common, rqt_plot, rqt_publisher, rqt_service_caller. Do you think it is possible to update those to use the new API too?

'@(str(type_.maximum_size))')@
@[ elif isinstance(type_, NamespacedType)]@
@('/'.join([type_.namespaces[0], type_.name]))@
['@("', '".join(type_.namespaces))'], '@(type_.name)')@
Copy link
Member

Choose a reason for hiding this comment

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

This is wrong if namespaces is empty.

Copy link
Member Author

Choose a reason for hiding this comment

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

In which scenario would someone use a NamespacedType without namespace?


Is the expected syntax the following ?

NamespacedType([], 'myname')

instead of

NamespacedType([''], 'myname')

I can fix it in here, wouldn't the other places in this file using this logic need to be updated as well ?
e.g.

from @('.'.join(type_.namespaces)) import @(type_.name)

Copy link
Member

Choose a reason for hiding this comment

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

In which scenario would someone use a NamespacedType without namespace?

There isn't a specific case where it is used atm but the code could be defensive and not rely on that assumption.

NamespacedType([], 'myname')

Correct.

wouldn't the other places in this file using this logic need to be updated as well ?

Probably, doesn't have to happen in this PR though. It's more a future proofing thing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good, added coverage for the empty namespaces in b95d02d

@mikaelarguedas
Copy link
Member Author

A few other packages are currently using get_fields_and_field_types: rqt_py_common, rqt_plot, rqt_publisher, rqt_service_caller. Do you think it is possible to update those to use the new API too?

Yes it is possible, does this mean adding an explicit dependency on rosidl_runtime_py in all these packages ?

@dirk-thomas
Copy link
Member

does this mean adding an explicit dependency on rosidl_runtime_py in all these packages ?

Only if they would use any symbols directly from that package. Otherwise no, each message package will already depend on rosidl_runtime_py.

@mikaelarguedas
Copy link
Member Author

Only if they would use any symbols directly from that package. Otherwise no, each message package will already depend on rosidl_runtime_py.

Ok so either these packages use what is provided in the message itself (__slots__ and SLOT_TYPES) or they depend explicitely on rosidl_runtime_py to be able to use the dictionary directly.

Do you have a preference for the rqt packages?

@dirk-thomas
Copy link
Member

Do you have a preference for the rqt packages?

I don't have a preference. Either way is fine with me.

@mikaelarguedas
Copy link
Member Author

Do you have a preference for the rqt packages?

I don't have a preference. Either way is fine with me.

Sounds good.
I don't know when I'll be able to allocate time for these, in case anyone else is interested in updating them in the meantime

field_elem_type = import_message_from_namespaced_type(rosidl_type)
for n in range(len(value)):
submsg = field_elem_type()
set_message_fields(submsg, value[n])
Copy link
Member

Choose a reason for hiding this comment

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

value[n] looks weird here? Can you please extend the existing test of set_message_fields to cover this case of a nested namespaced type to make sure this works as expected.

Copy link
Member Author

Choose a reason for hiding this comment

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

added test coverage in ad65970

Copy link
Member

@dirk-thomas dirk-thomas left a comment

Choose a reason for hiding this comment

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

I triggered a set of builds to check if the current state passes:

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

@@ -33,4 +38,13 @@ def set_message_fields(msg: Any, values: Dict[str, str]) -> None:
except TypeError:
value = field_type()
Copy link
Member

Choose a reason for hiding this comment

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

I am surprised this works in cases where the field type is numpy.ndarray or array.array. Can you please also add a test with a static array (which would cover the numpy case).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah it surprised me as well that the code comparing to list didn't need to be updated after the numpy array PR..

Static array test case added in 712d4da

@mikaelarguedas
Copy link
Member Author

@dirk-thomas looking briefly at the impacted rqt packages:

In multiple instances it looks like the code is meant to be interacting with the user friendly string representing a message and not a Python type per se.
It looks like there is ongoing discussion on what that user friendly str identifying a type should be: ros2/design#220

In some cases it's unclear if it is a design decision to rely on the msg type to be reflected in that dict.
e.g. in rqt_py_common, this API is used to reconstruct a msg file from a class. It looks to diverge significantly from the ROS 1 approach of providing the msg file on disk, and may require quite some custom code to be convert back from abstract type to msg format.
Is it a design decision to reconstruct msg files programmatically in the ROS 2 version?

Overall the amount of code + design in rqt to grasp and maybe rewrite will be significant, and I don't think I will have time to adapt it.

Is there a path forward for this PR without these rqt changes? I can reopen a PR not using the abstract types but the msg ones if this allows a fix for ros2/ros2cli#59 to be merged

@dirk-thomas
Copy link
Member

I don't think this ticket has to consider what might come out of that design ticket. Until that is actually merged this PR can focus on the current state of master.

Is it a design decision to reconstruct msg files programmatically in the ROS 2 version?

I am not entirely sure what you mean but I would answer with: no.

Is there a path forward for this PR without these rqt changes?

As long as the patch removes currently available API which is used by rqt it can only land if it also updates the code using the API.

That being said the alternatives are:

  • keep the old API in parallel to the newly introduced one
  • don't change the API at all and work with what is there

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

@mikaelarguedas Friendly ping.

@mikaelarguedas
Copy link
Member Author

mikaelarguedas commented May 2, 2019

So I looked at this again. as updating all the rqt packages is not something I will be able to do, I moved to a minimal patch not modifying message generation at all but just the runtime functions (a redo of https://github.com/ros2/ros2cli/pull/197/files).

I submitted the patch at #52.


keep the old API in parallel to the newly introduced one

that was a valuable alternative, I considered this, the current blocker for such an approach is that the rosidl_runtime_py package is not a dependency of the message packages by default, and that it cannot be for now because rosidl_runtime_py depends on message_packages such as test_msgs for testing introducing a circular dependency package dependency.
As there seem to be a lot of changes on the testing of packages these days, I discarded making the required changes for now and submitted the least intrusive change.

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

update tests

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

simplify logic by printing member type directly

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

move dict construction to rosidl_runtime_py

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

add utility to import complex message and add support for nested array in set_message

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

update tests and remove coverage for dict to avoid circular dependency

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

more descriptive variable name

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

refactor import logic according to ros2#35

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

move imports to top of file

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

string maximum size doesn't need quoting or str conversion

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

update docblock

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

slot_types_dict_from_message -> get_message_slot_types

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

check Abstrct type instead of 'list'

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

use NestedType

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

add conditional is namespaces is an empty list

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

one liner

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

extend test suite to cover NesteTypes of NamespacedTypes

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

single message fixture to use

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

use NestedType

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

add coverage for static array of nested messages

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

restore old API

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

SLOT_TYPES improvement from dirk-thomas

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

resolve conflicts

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>
Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>
Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>
Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>
@mikaelarguedas
Copy link
Member Author

As per discussion here and in #52.

This PR now does the following:

  • Adds SLOT_TYPES to all messages
  • Does not modify existing _fields_and_field_types or get_fields_and_field_types API
  • Adds import_message_from_namespaced_type and get_message_slot_types to rosidl_runtime_py
  • Update set_message to support Sequence and Arrays of ROS messages
  • Add test to rosidl_generator_py and rosidl_runtime_py to cover new feature

@mikaelarguedas mikaelarguedas requested a review from dirk-thomas May 3, 2019 00:05
@mikaelarguedas mikaelarguedas added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels May 3, 2019
@dirk-thomas
Copy link
Member

Thanks for the patch.

Build Status

@dirk-thomas dirk-thomas merged commit 78b765d into ros2:master May 3, 2019
@dirk-thomas dirk-thomas removed the in review Waiting for review (Kanban column) label May 3, 2019
@mikaelarguedas mikaelarguedas deleted the get_slot_types_2 branch May 3, 2019 09:43
jacobperron pushed a commit to ros2/rosidl_runtime_py that referenced this pull request Sep 19, 2019
* store types as constant and return ordered dict

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

update tests

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

simplify logic by printing member type directly

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

move dict construction to rosidl_runtime_py

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

add utility to import complex message and add support for nested array in set_message

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

update tests and remove coverage for dict to avoid circular dependency

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

more descriptive variable name

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

refactor import logic according to ros2/rosidl_python#35

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

move imports to top of file

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

string maximum size doesn't need quoting or str conversion

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

update docblock

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

slot_types_dict_from_message -> get_message_slot_types

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

check Abstrct type instead of 'list'

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

use NestedType

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

add conditional is namespaces is an empty list

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

one liner

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

extend test suite to cover NesteTypes of NamespacedTypes

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

single message fixture to use

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

use NestedType

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

add coverage for static array of nested messages

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

restore old API

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

SLOT_TYPES improvement from dirk-thomas

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

resolve conflicts

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

* add back I100 ignore

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

* use new rosidl_parser.definition types and new test interfaces

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

* restore original test, add test for SLOT_TYPES

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants