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

Adding a get_slot_fields_and_types method to python msg classes #19

Merged

Conversation

mlautman
Copy link
Contributor

@mlautman mlautman commented Nov 3, 2018

This adds a _slot_types field to python message classes as was requested here: #16

This attempts to remain as true to the ROS1 functionality as possible

@tfoote tfoote added the in review Waiting for review (Kanban column) label Nov 3, 2018
@mlautman
Copy link
Contributor Author

mlautman commented Nov 3, 2018

@dirk-thomas

@[for field in spec.fields]@
@[ if field.type.is_primitive_type() ]@
@[ if field.type.is_array ]@
'@(get_python_type(field.type))[@(field.type.array_size)]',
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't distinguish between a static array (with a fixed size) and a dynamic array (either with an upper bound or without a bound).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True. Do you have a preferred method to denote the different types of arrays? I didn't have a strong intuition here

Copy link
Member

Choose a reason for hiding this comment

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

I would suggest either the same notation as in the .msg or an object representation. Thinking about it the second one is probably be better in terms of stability with the upcoming change to .idl files since the notation will change (see https://github.com/ros2/design/blob/gh-pages/articles/142_idl.md).

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

Copy link
Member

Choose a reason for hiding this comment

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

Looking at the patch I don't see where the type is being distinguished?

Copy link
Contributor Author

@mlautman mlautman Nov 13, 2018

Choose a reason for hiding this comment

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

My apologies, I got my branches mixed up. All of my changes are in one commit (9454002) but I'm unsure of whether I should cherry pick that commit on top of master or 0.5.2. Since this is targeting master, I assume that I should cherry pick on top of that, but doing so causes the build to fail for unrelated reasons..

/home/mike/ws_rqt2/build/rosidl_generator_py/rosidl_generator_py/rosidl_generator_py/msg/_string_arrays_s.c:12:10: fatal error: rosidl_generator_c/primitives_sequence.h: No such file or directory #include <rosidl_generator_c/primitives_sequence.h> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ compilation terminated. /home/mike/ws_rqt2/build/rosidl_generator_py/rosidl_generator_py/rosidl_generator_py/msg/_nested_s.c:12:10: fatal error: rosidl_generator_c/primitives_sequence.h: No such file or directory #include <rosidl_generator_c/primitives_sequence.h> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ compilation terminated. /home/mike/ws_rqt2/build/rosidl_generator_py/rosidl_generator_py/rosidl_generator_py/msg/_various_s.c:12:10: fatal error: rosidl_generator_c/primitives_sequence.h: No such file or directory #include <rosidl_generator_c/primitives_sequence.h>

Is there a .repos available with the most recent ros2 branches that I should use for making PR's to master?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

It depends on what you are trying to build. I would suggest using the .repos files from the master branch in the ros2/ros2 repo and building everything from source for your use case. Then a patch based on the master of this repo will work.

(The opposite would be to use the bouncy branch of the .repos file and then also target the bouncy branch in this repo. But usually all contributions are targeting the default branch and only in case of severe bug fixes are being considered for backporting afterwards.)

Copy link
Member

Choose a reason for hiding this comment

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

The current state seems to pass on CI: Build Status

@mlautman mlautman force-pushed the adding-slot-types-to-python-msgs branch 2 times, most recently from 7ed6394 to 47cf04c Compare November 5, 2018 22:15
@mlautman
Copy link
Contributor Author

mlautman commented Nov 7, 2018

@dirk-thomas ready for another review

@mlautman mlautman force-pushed the adding-slot-types-to-python-msgs branch 2 times, most recently from 068fe49 to 85aa7b7 Compare November 16, 2018 17:27
@mlautman
Copy link
Contributor Author

@dirk-thomas Changed _slot_types_dict to get_slot_types_dict() and added noqa W504 where appropriate to pass flake8

@mlautman
Copy link
Contributor Author

@dirk-thomas
Copy link
Member

Ignoring W504 all over the place isn't necessary. This has been addressed in the linter configuration already a while ago: ament/ament_lint#110.

@mlautman
Copy link
Contributor Author

@dirk-thomas It still fails locally with colcon build test --package-select rosidl_python without that change

@dirk-thomas
Copy link
Member

It still fails locally

Are you using the latest default branches of all the other ROS 2 repos?

@@ -175,6 +197,10 @@ class @(spec.base_type.type)(metaclass=Metaclass):
return False
@[end for]@
return True

@@classmethod
def get_slot_types_dict(cls):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
def get_slot_types_dict(cls):
def get_slot_fields_and_types(cls):


@@classmethod
def get_fields_and_field_types(cls):
return cls._slot_types_dict
Copy link

Choose a reason for hiding this comment

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

Since this is a getter, should it return a shallow copy so that you can modify the underlying dictionary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Fixed.

@mlautman mlautman force-pushed the adding-slot-types-to-python-msgs branch 2 times, most recently from e820439 to ac9c660 Compare November 19, 2018 20:29
@mlautman mlautman changed the title Adding a slot_type message field to python msg classes Adding a get_slot_fields_and_types method to python msg classes Nov 19, 2018
@mlautman mlautman force-pushed the adding-slot-types-to-python-msgs branch from ac9c660 to 40d4bcc Compare November 19, 2018 20:48
@mlautman
Copy link
Contributor Author

@dirk-thomas I am using the ros2.repos that you passed along to us with the 0.5.2 release.

I went back and removed W504. I also changed the code to return a copy of the dict rather than the dict itself per @brawner's comment

@mlautman mlautman force-pushed the adding-slot-types-to-python-msgs branch from 343ce69 to 706a5dd Compare November 19, 2018 21:40
@dirk-thomas
Copy link
Member

This can be merged as is for now. With the coming change I will likely change this in the following way:

  • Store the types in a class constant, e.g. SLOT_TYPES.
  • Change the data structure from a mutable dict to an immutable tuple of abstract types
  • Either remove the class method (or rename it to get_slot_types which zips __slots__ and SLOT_TYPES and returns an ordered dictionary).

@dirk-thomas dirk-thomas merged commit fc8b868 into ros2:master Nov 19, 2018
@dirk-thomas dirk-thomas removed the in review Waiting for review (Kanban column) label Nov 19, 2018
@mlautman mlautman deleted the adding-slot-types-to-python-msgs branch November 19, 2018 23:06
@mlautman mlautman restored the adding-slot-types-to-python-msgs branch November 26, 2018 21:08
@mlautman mlautman deleted the adding-slot-types-to-python-msgs branch November 26, 2018 21:08
@mlautman mlautman restored the adding-slot-types-to-python-msgs branch November 26, 2018 21:08
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.

None yet

4 participants