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

Python typesupport for Actions #21

Merged
merged 4 commits into from
Jan 14, 2019
Merged

Conversation

apojomovsky
Copy link
Contributor

Closes #14
This PR:

  • Adds the required rosidl_python/rosidl_generator_py/resource/_action.py.em template file with the proper imports for the generated action messages/services.
  • Adds action typesupport bits to the _msg_pkg_typesupport_entry_point.c.em script.
  • Adds logic to the rosidl_generator_py so that it can handle the new action's template.

@tfoote tfoote added the in progress Actively being worked on (Kanban column) label Nov 15, 2018
@brawner
Copy link

brawner commented Dec 21, 2018

The fork this PR is coming from is not accessible. Was it dropped, or just not made public?

@apojomovsky
Copy link
Contributor Author

Hi @brawner , I think the branch name has lead to confusion here. Actually, this PR is coming from a local branch to the rcl repo and can be found here: https://github.com/ros2/rosidl_python/tree/apojomovsky/typesupport_for_actions

@brawner
Copy link

brawner commented Dec 21, 2018 via email

@brawner
Copy link

brawner commented Dec 27, 2018

I've tested this out on my system. Is there a reason why no high-level action class is created? Something like:

from test_msgs.action import Fibonacci

as opposed to

from test_msgs.action import Fibonacci_Goal, Fibonacci_Result, Fibonacci_Feedback

@jacobperron
Copy link
Member

jacobperron commented Jan 7, 2019

I've tested this out on my system. Is there a reason why no high-level action class is created? Something like:

 from test_msgs.action import Fibonacci

It would appear that the _action.py.em template is not being invoked. It's possibly because of current rosidl pipeline where (I think) .action files are being broken into services/messages prior to being passed to the generators. @apojomovsky Can you confirm?

@apojomovsky
Copy link
Contributor Author

Hi @jacobperron , I've just verified and it's exactly as you say. With the current pipeline, action files are broken into services and messages prior to being passed to the generator.

@@ -23,7 +23,8 @@ add_custom_command(
COMMAND ${PYTHON_EXECUTABLE} ${rosidl_generator_py_BIN}
--generator-arguments-file "${generator_arguments_file}"
--typesupport-impls "${_typesupport_impls}"
DEPENDS ${target_dependencies} ${rosidl_generate_interfaces_TARGET}
${extra_generator_arguments}
Copy link
Member

Choose a reason for hiding this comment

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

Where is this variable being defined?

Copy link
Contributor

Choose a reason for hiding this comment

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

A left over from a previous attempt. Thanks for pointing it out. Removed.

@hidmic hidmic force-pushed the apojomovsky/typesupport_for_actions branch from cb12148 to 615e6a2 Compare January 10, 2019 16:05
@hidmic hidmic added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Jan 10, 2019
@hidmic
Copy link
Contributor

hidmic commented Jan 10, 2019

Alright, it seems to be working now. Or at least I'm able to import the Fibonacci class from test_msgs.action and get its C type support with Fibonacci.__import_type_support__().

Having said that, I'm not very proud of this patch. It works, but it's fragile, if you know what I mean. The split pipeline does no good to the Python generator implementation, and this is the solution I came up with that minimized the amount of changes necessary. Hopefully, we'll get to replace it with a more robust implementation once Dirk's work lands.

@jacobperron this is ready for you to implement actions in rclpy (and catch bugs, if any, that's the ultimate test).

@hidmic
Copy link
Contributor

hidmic commented Jan 10, 2019

Running CI on this one in the meantime:

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

@hidmic hidmic removed their request for review January 10, 2019 16:21
print('%sif %s.Metaclass._TYPE_SUPPORT is None:' % (' ' * 4 * 3, '_cancel_goal'))
print('%s%s.Metaclass.__import_type_support__()' % (' ' * 4 * 4, '_cancel_goal'))
}@

Copy link
Contributor

Choose a reason for hiding this comment

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

Need an extra blank line to have two between top-level definitions

Copy link
Contributor

Choose a reason for hiding this comment

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

True. Fixed.

content = re.sub(
r"# BEGIN %s$.*^# END %s" % (block_name, block_name),
'', content, 0, re.M | re.S
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this part where it modifies the previously generated __init__.py the fragile part you were referring to?

Copy link
Contributor

Choose a reason for hiding this comment

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

That and adding _action to the package name whenever necessary (but not everywhere) to avoid name collisions.

@hidmic hidmic force-pushed the apojomovsky/typesupport_for_actions branch from 2e51b21 to 161faf0 Compare January 11, 2019 15:58
Copy link
Contributor

@sloretz sloretz left a comment

Choose a reason for hiding this comment

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

LGTM with green CI. I think this could be merged now, but shouldn't be released until rclpy actions are ready in case there are bugs not caught by review.

@hidmic
Copy link
Contributor

hidmic commented Jan 11, 2019

@sloretz fully agree.

@hidmic
Copy link
Contributor

hidmic commented Jan 11, 2019

If this thread is right, 3e212cb should fix our little issue.

@hidmic
Copy link
Contributor

hidmic commented Jan 14, 2019

Re-running Windows CI, last one failed for unrelated reasons:

20:56:50 II> Using workspace: ws
20:56:50 WW> Deleting the folder at 'ws'.
20:56:50 Traceback (most recent call last):
20:56:50   File "C:\Python37\lib\shutil.py", line 389, in _rmtree_unsafe
20:56:50     os.unlink(fullname)
20:56:50 PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'ws\\log\\test_2019-01-10_22-14-13\\logger_all.log'
20:56:50 
20:56:50 During handling of the above exception, another exception occurred:
20:56:50 
20:56:50 Traceback (most recent call last):
20:56:50   File "run_ros2_batch.py", line 32, in <module>
20:56:50     sys.exit(main())
20:56:50   File "C:\J\workspace\ci_windows\ros2_batch_job\__main__.py", line 132, in main
20:56:50     return run(args, build_function, blacklisted_package_names=blacklisted_package_names)
20:56:50   File "C:\J\workspace\ci_windows\ros2_batch_job\__main__.py", line 404, in run
20:56:50     remove_folder(args.workspace)
20:56:50   File "C:\J\workspace\ci_windows\ros2_batch_job\util.py", line 114, in remove_folder
20:56:50     shutil.rmtree(path, onerror=del_rw)
20:56:50   File "C:\Python37\lib\shutil.py", line 507, in rmtree
20:56:50     return _rmtree_unsafe(path, onerror)
20:56:50   File "C:\Python37\lib\shutil.py", line 386, in _rmtree_unsafe
20:56:50     _rmtree_unsafe(fullname, onerror)
20:56:50   File "C:\Python37\lib\shutil.py", line 386, in _rmtree_unsafe
20:56:50     _rmtree_unsafe(fullname, onerror)
20:56:50   File "C:\Python37\lib\shutil.py", line 391, in _rmtree_unsafe
20:56:50     onerror(os.unlink, fullname, sys.exc_info())
20:56:50   File "C:\J\workspace\ci_windows\ros2_batch_job\util.py", line 113, in del_rw
20:56:50     os.remove(name)
20:56:50 PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'ws\\log\\test_2019-01-10_22-14-13\\logger_all.log'

@hidmic
Copy link
Contributor

hidmic commented Jan 14, 2019

Alright!! All green. Going in.

@hidmic hidmic merged commit 29848db into master Jan 14, 2019
@tfoote tfoote removed the in review Waiting for review (Kanban column) label Jan 14, 2019
@hidmic hidmic deleted the apojomovsky/typesupport_for_actions branch January 14, 2019 18:45
else:
cls._TYPE_SUPPORT = module.type_support_action__@(subfolder)_@(module_name)
@{
preffix = '_' + convert_camel_case_to_lower_case_underscore(spec.action_name) + '__'
Copy link
Member

Choose a reason for hiding this comment

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

Spelling: prefix.

Copy link
Member

Choose a reason for hiding this comment

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

Fixed in #28

nuclearsandwich pushed a commit that referenced this pull request Mar 10, 2019
* Adds Python typesupport for Actions (#21)

* Add _action.py.em; Makes rosidl_generator_py handle action files
properly

* Adds CMake pipeline bits for action generation.

* Fixes all linter issues.

* Attempts to fix CMake warnings in Windows.

* Fix flake8 error (#27)

* Provide type support for 'goal_status_array' in action type support

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Fix spelling typo

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Ignore import order on generated imports (#29)

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
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

7 participants