Streamline Python launchfiles to promote best practices #5413
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes robograph-project/docs#9
The changes included in this PR are meant to produce shorter, clearer, and more flexible Python launchfiles. By showing these examples to users, we encourage them to also follow best practices for a better experience and more correct results.
Changes
PythonLaunchDescriptionSource
(and xml, yaml versions) in favor of encoding less explicit knowledge into user facing APIThis makes the code shorter and therefore easier to read, and makes it easier to change out launchfile frontends.
return LaunchDescription([...
as possibleThis matches the XML/YAML style, and removes room for programming errors in launchfiles. I have seen plenty of cases where declared variables are then used out of order, or accidentally missed entirely. When simply declaring everything into the Action list, you can't make those mistakes.
os.path.join
withPathJoinSubstitution
This allows for extension to uses with other Substitutions, such as
LaunchConfiguration
etc. The more flexible and correct way to write launchfiles.get_package_share_directory
withFindPackageShare
This allows the package name to be a substitution, such as from a launch arg. That's a use case I have seen. Plus the pattern allows parsing launchfiles in a context where the package prefix may not yet be known, like in build and tooling scenarios.
TextSubstitution
It's not needed, and therefore is more confusion!