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 way to include other Python launch files #122

Merged
merged 10 commits into from
Aug 6, 2018

Conversation

wjwwood
Copy link
Member

@wjwwood wjwwood commented Jul 31, 2018

Fixes #116

This pull request does a few things in order to make this feature possible:

  • changes LaunchDescriptionSource to take a LaunchContext when sourcing the launch description from it, so that Substitutions can be expanded
  • adds a new source called PythonLaunchDescriptionSource which takes a path to a Python launch file (can be list of substitutions) and loads it to produce a LaunchDescription
  • added a new substitution that gets the directory of the current launch file (requires that this launch file was included with IncludeLaunchDescription
  • adds an example in ros2launch that includes another launch description next to itself

I got side tracked by debugging the issue described in #89 (seems to also be triggered when there's an exception within launch itself), but this pr is still missing tests for the new classes/functions, which I will push soon.

@wjwwood wjwwood added the in progress Actively being worked on (Kanban column) label Jul 31, 2018
@wjwwood wjwwood self-assigned this Jul 31, 2018
@wjwwood wjwwood force-pushed the feature/include_python_launch_files branch from 54aea08 to fed6e3f Compare August 1, 2018 23:33
Signed-off-by: William Woodall <william@osrfoundation.org>
Signed-off-by: William Woodall <william@osrfoundation.org>
Signed-off-by: William Woodall <william@osrfoundation.org>

To do this, moved functions for loading Python launch files into launch.

Signed-off-by: William Woodall <william@osrfoundation.org>
Signed-off-by: William Woodall <william@osrfoundation.org>
Signed-off-by: William Woodall <william@osrfoundation.org>
Signed-off-by: William Woodall <william@osrfoundation.org>
Signed-off-by: William Woodall <william@osrfoundation.org>
Signed-off-by: William Woodall <william@osrfoundation.org>
Signed-off-by: William Woodall <william@osrfoundation.org>
@wjwwood wjwwood force-pushed the feature/include_python_launch_files branch from fed6e3f to a0a4b53 Compare August 1, 2018 23:42
@wjwwood wjwwood added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Aug 1, 2018
except Exception as exc:
msg = 'Caught exception in launch (see debug for traceback): {}'.format(exc)
_logger.error(msg)
_logger.debug(traceback.format_exc())
Copy link
Contributor

Choose a reason for hiding this comment

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

Is debug saved to disk by default? If not, it might be hard to debug launch issues that happen infrequently in a production system. Why not error or warn?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, I missed the error call right above this line. Nevermind.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right now debug doesn't go to a file, but perhaps it will in the future (perhaps related #104).

Do you think it's good enough to have the traceback in debug until that happens?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think it's good enough to have the traceback in debug until that happens?

I do.

"""Launch the example.launch.py launch file."""
return LaunchDescription([
LogInfo(msg=[
'Including launch file located at: ', ThisLaunchFileDir(), '/example.launch.py'
Copy link
Contributor

Choose a reason for hiding this comment

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

When is it better to use ThisLaunchFileDir() versus

os.path.abspath(os.path.dirname(__file__))

?

Copy link
Member Author

Choose a reason for hiding this comment

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

You should always, because when introspecting it will be the difference /abs/path/to/example.launch.py and ThisLaunchFileDir('/abs/path/to') + '/example.launch.py'. Which seems trivial, but it indicates that if you moved the launch file it would work, as opposed to it being a hard coded path.

lc = LaunchContext()
with pytest.raises(SubstitutionFailure):
tlfp.perform(lc)
lc.extend_locals({'current_launch_file_directory': 'foo'})
Copy link
Contributor

Choose a reason for hiding this comment

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

I half expected the current LaunchDescription and LaunchDescriptionSource to be in the context already. Sort of like inspect.currentframe().f_code.co_filename. I don't have a use case for doing that, and I'm not sure how much work it would be.

Copy link
Member Author

Choose a reason for hiding this comment

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

They're not part of the context, though that might be a good thing to do at some point. This line, however, is putting the file location of the current launch file (which is based on the location member of the current LaunchDescriptionSource).

@@ -14,6 +14,10 @@

"""Tests for the IncludeLaunchDescription action class."""

import os

from launch import Action
Copy link
Contributor

Choose a reason for hiding this comment

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

I get a flake8 warning here about an unused import

Signed-off-by: William Woodall <william@osrfoundation.org>
@wjwwood
Copy link
Member Author

wjwwood commented Aug 3, 2018

CI after fixing linter issue:

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

@wjwwood wjwwood merged commit ae281ce into master Aug 6, 2018
@wjwwood wjwwood deleted the feature/include_python_launch_files branch August 6, 2018 18:20
@wjwwood wjwwood removed the in review Waiting for review (Kanban column) label Aug 6, 2018
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