Skip to content

Commit

Permalink
Fix linter errors
Browse files Browse the repository at this point in the history
Signed-off-by: Addisu Z. Taddese <[email protected]>
  • Loading branch information
azeey committed Dec 10, 2024
1 parent a0c04de commit ff96f97
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 21 deletions.
33 changes: 22 additions & 11 deletions ros_gz_bridge/ros_gz_bridge/actions/ros_gz_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,26 @@ def __init__(
self.__container_name = container_name
self.__namespace = namespace

# This is here to allow using strings or booleans as values for boolean variables when the Action is used from Python
# i.e., this allows users to do:
# This is here to allow using strings or booleans as values for boolean variables when
# the Action is used from Python i.e., this allows users to do:
# RosGzBridge(bridge_name='bridge1', use_composition='true', create_own_container=True)
# Note that use_composition is set to a string while create_own_container is set to a boolean. The reverse would also work.
# At some point, we might want to deprecate this and only allow setting booleans since that's
# what users would expect when calling this from Python
# Note that use_composition is set to a string while create_own_container is set to a
# boolean. The reverse would also work.
# At some point, we might want to deprecate this and only allow setting booleans since
# that's what users would expect when calling this from Python
if isinstance(create_own_container, str):
self.__create_own_container = normalize_typed_substitution(TextSubstitution(text=create_own_container), bool)
self.__create_own_container = normalize_typed_substitution(
TextSubstitution(text=create_own_container), bool
)
else:
self.__create_own_container = normalize_typed_substitution(create_own_container, bool)
self.__create_own_container = normalize_typed_substitution(
create_own_container, bool
)

if isinstance(use_composition, str):
self.__use_composition = normalize_typed_substitution(TextSubstitution(text=use_composition), bool)
self.__use_composition = normalize_typed_substitution(
TextSubstitution(text=use_composition), bool
)
else:
self.__use_composition = normalize_typed_substitution(use_composition, bool)

Expand All @@ -87,7 +94,7 @@ def __init__(
@classmethod
def parse(cls, entity: Entity, parser: Parser):
"""Parse ros_gz_bridge."""
kwargs:Dict = super().parse(entity, parser)[1]
kwargs: Dict = super().parse(entity, parser)[1]

bridge_name = entity.get_attr(
'bridge_name', data_type=str,
Expand Down Expand Up @@ -183,8 +190,12 @@ def execute(self, context: LaunchContext) -> Optional[List[Action]]:
bridge_params_pairs = simplified_bridge_params.split(',')
parsed_bridge_params = dict(pair.split(':') for pair in bridge_params_pairs)

use_composition_eval = perform_typed_substitution(context, self.__use_composition, bool)
create_own_container_eval = perform_typed_substitution(context, self.__create_own_container, bool)
use_composition_eval = perform_typed_substitution(
context, self.__use_composition, bool
)
create_own_container_eval = perform_typed_substitution(
context, self.__create_own_container, bool
)

launch_descriptions: List[Action] = []

Expand Down
28 changes: 18 additions & 10 deletions ros_gz_sim/ros_gz_sim/actions/gzserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,28 @@ def __init__(
self.__world_sdf_string = world_sdf_string
self.__container_name = container_name


# This is here to allow using strings or booleans as values for boolean variables when the Action is used from Python
# See the RosGzBridge.__init__ function for more details.
# This is here to allow using strings or booleans as values for boolean variables when
# the Action is used from Python See the RosGzBridge.__init__ function for more details.
if isinstance(create_own_container, str):
self.__create_own_container = normalize_typed_substitution(TextSubstitution(text=create_own_container), bool)
self.__create_own_container = normalize_typed_substitution(
TextSubstitution(text=create_own_container), bool
)
else:
self.__create_own_container = normalize_typed_substitution(create_own_container, bool)
self.__create_own_container = normalize_typed_substitution(
create_own_container, bool
)

if isinstance(use_composition, str):
self.__use_composition = normalize_typed_substitution(TextSubstitution(text=use_composition), bool)
self.__use_composition = normalize_typed_substitution(
TextSubstitution(text=use_composition), bool
)
else:
self.__use_composition = normalize_typed_substitution(use_composition, bool)

@classmethod
def parse(cls, entity: Entity, parser: Parser):
"""Parse gz_server."""
kwargs:Dict = super().parse(entity, parser)[1]
kwargs: Dict = super().parse(entity, parser)[1]

world_sdf_file = entity.get_attr(
'world_sdf_file', data_type=str,
Expand Down Expand Up @@ -177,7 +182,6 @@ def parse(cls, entity: Entity, parser: Parser):

def execute(self, context: LaunchContext) -> Optional[List[Action]]:
"""Execute the action."""

launch_descriptions: List[Action] = []

model_paths, plugin_paths = GazeboRosPaths.get_paths()
Expand All @@ -195,8 +199,12 @@ def execute(self, context: LaunchContext) -> Optional[List[Action]]:
model_paths,
])))

use_composition_eval = perform_typed_substitution(context, self.__use_composition, bool)
create_own_container_eval = perform_typed_substitution(context, self.__create_own_container, bool)
use_composition_eval = perform_typed_substitution(
context, self.__use_composition, bool
)
create_own_container_eval = perform_typed_substitution(
context, self.__create_own_container, bool
)
if not use_composition_eval:
# Standard node configuration
launch_descriptions.append(Node(
Expand Down

0 comments on commit ff96f97

Please sign in to comment.