-
Notifications
You must be signed in to change notification settings - Fork 45
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
store types as tuple of abstract types #33
Conversation
fcec207
to
4b5a82d
Compare
@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) |
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.
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?
@[ elif isinstance(type_, NamespacedType)]@ | ||
@('/'.join([type_.namespaces[0], type_.name]))@ | ||
['@("', '".join(type_.namespaces))'], '@(type_.name)')@ |
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.
This is wrong if namespaces
is empty.
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 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) |
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 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.
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.
Sounds good, added coverage for the empty namespaces in b95d02d
Yes it is possible, does this mean adding an explicit dependency on |
Only if they would use any symbols directly from that package. Otherwise no, each message package will already depend on |
Ok so either these packages use what is provided in the message itself ( Do you have a preference for the rqt packages? |
I don't have a preference. Either way is fine with me. |
Sounds good. |
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]) |
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.
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.
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.
added test coverage in ad65970
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.
@@ -33,4 +38,13 @@ def set_message_fields(msg: Any, values: Dict[str, str]) -> None: | |||
except TypeError: | |||
value = field_type() |
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 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).
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 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
@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. In some cases it's unclear if it is a design decision to rely on the 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 |
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.
I am not entirely sure what you mean but I would answer with: no.
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:
|
@mikaelarguedas Friendly ping. |
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.
that was a valuable alternative, I considered this, the current blocker for such an approach is that the |
Signed-off-by: Mikael Arguedas <[email protected]> update tests Signed-off-by: Mikael Arguedas <[email protected]> simplify logic by printing member type directly Signed-off-by: Mikael Arguedas <[email protected]> move dict construction to rosidl_runtime_py Signed-off-by: Mikael Arguedas <[email protected]> add utility to import complex message and add support for nested array in set_message Signed-off-by: Mikael Arguedas <[email protected]> update tests and remove coverage for dict to avoid circular dependency Signed-off-by: Mikael Arguedas <[email protected]> more descriptive variable name Signed-off-by: Mikael Arguedas <[email protected]> refactor import logic according to ros2#35 Signed-off-by: Mikael Arguedas <[email protected]> move imports to top of file Signed-off-by: Mikael Arguedas <[email protected]> string maximum size doesn't need quoting or str conversion Signed-off-by: Mikael Arguedas <[email protected]> update docblock Signed-off-by: Mikael Arguedas <[email protected]> slot_types_dict_from_message -> get_message_slot_types Signed-off-by: Mikael Arguedas <[email protected]> check Abstrct type instead of 'list' Signed-off-by: Mikael Arguedas <[email protected]> use NestedType Signed-off-by: Mikael Arguedas <[email protected]> add conditional is namespaces is an empty list Signed-off-by: Mikael Arguedas <[email protected]> one liner Signed-off-by: Mikael Arguedas <[email protected]> extend test suite to cover NesteTypes of NamespacedTypes Signed-off-by: Mikael Arguedas <[email protected]> single message fixture to use Signed-off-by: Mikael Arguedas <[email protected]> use NestedType Signed-off-by: Mikael Arguedas <[email protected]> add coverage for static array of nested messages Signed-off-by: Mikael Arguedas <[email protected]> restore old API Signed-off-by: Mikael Arguedas <[email protected]> SLOT_TYPES improvement from dirk-thomas Signed-off-by: Mikael Arguedas <[email protected]> resolve conflicts Signed-off-by: Mikael Arguedas <[email protected]>
Signed-off-by: Mikael Arguedas <[email protected]>
Signed-off-by: Mikael Arguedas <[email protected]>
Signed-off-by: Mikael Arguedas <[email protected]>
712d4da
to
64003b6
Compare
As per discussion here and in #52. This PR now does the following:
|
* store types as constant and return ordered dict Signed-off-by: Mikael Arguedas <[email protected]> update tests Signed-off-by: Mikael Arguedas <[email protected]> simplify logic by printing member type directly Signed-off-by: Mikael Arguedas <[email protected]> move dict construction to rosidl_runtime_py Signed-off-by: Mikael Arguedas <[email protected]> add utility to import complex message and add support for nested array in set_message Signed-off-by: Mikael Arguedas <[email protected]> update tests and remove coverage for dict to avoid circular dependency Signed-off-by: Mikael Arguedas <[email protected]> more descriptive variable name Signed-off-by: Mikael Arguedas <[email protected]> refactor import logic according to ros2/rosidl_python#35 Signed-off-by: Mikael Arguedas <[email protected]> move imports to top of file Signed-off-by: Mikael Arguedas <[email protected]> string maximum size doesn't need quoting or str conversion Signed-off-by: Mikael Arguedas <[email protected]> update docblock Signed-off-by: Mikael Arguedas <[email protected]> slot_types_dict_from_message -> get_message_slot_types Signed-off-by: Mikael Arguedas <[email protected]> check Abstrct type instead of 'list' Signed-off-by: Mikael Arguedas <[email protected]> use NestedType Signed-off-by: Mikael Arguedas <[email protected]> add conditional is namespaces is an empty list Signed-off-by: Mikael Arguedas <[email protected]> one liner Signed-off-by: Mikael Arguedas <[email protected]> extend test suite to cover NesteTypes of NamespacedTypes Signed-off-by: Mikael Arguedas <[email protected]> single message fixture to use Signed-off-by: Mikael Arguedas <[email protected]> use NestedType Signed-off-by: Mikael Arguedas <[email protected]> add coverage for static array of nested messages Signed-off-by: Mikael Arguedas <[email protected]> restore old API Signed-off-by: Mikael Arguedas <[email protected]> SLOT_TYPES improvement from dirk-thomas Signed-off-by: Mikael Arguedas <[email protected]> resolve conflicts Signed-off-by: Mikael Arguedas <[email protected]> * add back I100 ignore Signed-off-by: Mikael Arguedas <[email protected]> * use new rosidl_parser.definition types and new test interfaces Signed-off-by: Mikael Arguedas <[email protected]> * restore original test, add test for SLOT_TYPES Signed-off-by: Mikael Arguedas <[email protected]>
Replaces #30 now that #24 has merged
Required by ros2/ros2cli#207
Blocked by #34