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

Improve argument parsing in Actions #663

Merged
merged 2 commits into from
Dec 11, 2024

Conversation

azeey
Copy link
Contributor

@azeey azeey commented Dec 10, 2024

🦟 Bug fix

Summary

The RosGzBridge and GzServer now support different spellings for boolean arguments (True, true). This also simplifies how conditionals are used to create composable nodes by evaluating the conditionals and using them as regular Python booleans instead of relying on PythonExpression. It was actually the PythonExpression that was preventing support of boolean arguments spelled true/false.

This came up in #632
The launch file in XML can now use lower case boolean strings:
https://github.com/gazebosim/ros_gz/blob/25b6644b644183e09f517170ce41b5dc6f16d6b8/ros_gz_sim_demos/launch/air_pressure.launch.xml#L1C1-L15C10

The equivalent python launch file for just gzserver and the bridge would be:

from launch import LaunchDescription
from launch_ros.substitutions import FindPackageShare
from ros_gz_sim.actions import GzServer
from ros_gz_bridge.actions import RosGzBridge

def generate_launch_description():

    return LaunchDescription([
        GzServer(world_sdf_file='sensors.sdf', use_composition=True, create_own_container=True),
        RosGzBridge(bridge_name='bridge1', 
                    config_file=[FindPackageShare('ros_gz_sim_demos'), '/config/air_pressure.yaml'],
                    use_composition='true'
                    )
    ])

Note the use_composition argument can be a python boolean or a string (True or true). We should probably deprecate the string input at some point since that's not very Pythonic

Checklist

  • Signed all commits for DCO
  • Added tests
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

The `RosGzBridge` and `GzServer` now support different spellings for
boolean arguments (`True`, `true`). This also simplifies how
conditionals are used to create composable nodes by evaluating the
conditionals and using them as regular Python booleans instead of
relying on `PythonExpression`. It was actually the `PythonExpression`
that was preventing support of boolean arguments spelled `true`/`false`.

Signed-off-by: Addisu Z. Taddese <[email protected]>
@azeey azeey requested a review from ahcorde as a code owner December 10, 2024 17:17
@azeey azeey requested review from caguero and ahcorde and removed request for ahcorde December 10, 2024 17:17
Copy link
Collaborator

@ahcorde ahcorde left a comment

Choose a reason for hiding this comment

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

10:  - /opt/ros/rolling/bin/ament_flake8 --xunit-file /github/home/ws/build/ros_gz_bridge/test_results/ros_gz_bridge/flake8.xunit.xml
10:         # This is here to allow using strings or booleans as values for boolean variables when the Action is used from Python
10:                                                                                                    ^
10:         # Note that use_composition is set to a string while create_own_container is set to a boolean. The reverse would also work.
10:                                                                                                    ^
10:         # At some point, we might want to deprecate this and only allow setting booleans since that's
10:                                                                                                    ^
10:             self.__create_own_container = normalize_typed_substitution(TextSubstitution(text=create_own_container), bool)
10:                                                                                                    ^
10:             self.__use_composition = normalize_typed_substitution(TextSubstitution(text=use_composition), bool)
10:                                                                                                    ^
10:         kwargs:Dict = super().parse(entity, parser)[1]
10:               ^
10:         create_own_container_eval = perform_typed_substitution(context, self.__create_own_container, bool)
10:                                                                                                    ^
10: 1     E231 missing whitespace after ':'
10: 6     E501 line too long (125 > 99 characters)

Signed-off-by: Addisu Z. Taddese <[email protected]>
@azeey azeey mentioned this pull request Dec 10, 2024
8 tasks
@ahcorde ahcorde merged commit c2b51ff into gazebosim:ros2 Dec 11, 2024
4 checks passed
@ahcorde
Copy link
Collaborator

ahcorde commented Dec 11, 2024

https://github.com/Mergifyio backport jazzy

Copy link
Contributor

mergify bot commented Dec 11, 2024

backport jazzy

✅ Backports have been created

ahcorde added a commit that referenced this pull request Dec 11, 2024
[backport Jazzy] Improve argument parsing in Actions (#663)
@mergify mergify bot mentioned this pull request Dec 11, 2024
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants