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

Make namespace parameter mandatory in LifecycleNode constructor #157

Merged
merged 8 commits into from
Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions launch_ros/examples/lifecycle_pub_sub_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def main(argv=sys.argv[1:]):

# Prepare the talker node.
talker_node = launch_ros.actions.LifecycleNode(
node_name='talker',
name='talker', namespace='',
package='lifecycle', executable='lifecycle_talker', output='screen')

# When the talker reaches the 'inactive' state, make it take the 'activate' transition.
Expand All @@ -62,7 +62,7 @@ def main(argv=sys.argv[1:]):
launch.actions.LogInfo(
msg="node 'talker' reached the 'active' state, launching 'listener'."),
launch_ros.actions.LifecycleNode(
node_name='listener',
name='listener', namespace='',
package='lifecycle', executable='lifecycle_listener', output='screen'),
],
)
Expand Down
9 changes: 5 additions & 4 deletions launch_ros/launch_ros/actions/lifecycle_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
from typing import cast
from typing import List
from typing import Optional
from typing import Text
import warnings

import launch
from launch import SomeSubstitutionsType
from launch.action import Action
import launch.logging

Expand All @@ -42,8 +42,9 @@ class LifecycleNode(Node):
def __init__(
self,
*,
name: Optional[Text] = None,
node_name: Optional[Text] = None,
name: Optional[SomeSubstitutionsType] = None,
namespace: SomeSubstitutionsType,
node_name: Optional[SomeSubstitutionsType] = None,
sloretz marked this conversation as resolved.
Show resolved Hide resolved
hidmic marked this conversation as resolved.
Show resolved Hide resolved
**kwargs
) -> None:
"""
Expand Down Expand Up @@ -87,7 +88,7 @@ def __init__(
# TODO(jacobperron): Remove default value and this check when deprecated API is removed
if name is None:
raise RuntimeError("'name' must not be None.'")
super().__init__(name=name, **kwargs)
super().__init__(name=name, namespace=namespace, **kwargs)
ivanpauno marked this conversation as resolved.
Show resolved Hide resolved
self.__logger = launch.logging.get_logger(__name__)
self.__rclpy_subscription = None
self.__current_state = \
Expand Down
33 changes: 31 additions & 2 deletions test_launch_ros/test/test_launch_ros/actions/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import unittest
import warnings

from launch import LaunchContext
from launch import LaunchDescription
from launch import LaunchService
from launch.actions import Shutdown
Expand All @@ -44,8 +45,6 @@ def _assert_launch_no_errors(self, actions):
def _create_node(self, *, parameters=None, remappings=None):
return launch_ros.actions.Node(
package='demo_nodes_py', executable='talker_qos', output='screen',
# The node name is required for parameter dicts.
# See https://github.com/ros2/launch/issues/139.
name='my_node', namespace='my_ns',
exec_name='my_node_process',
arguments=['--number_of_cycles', '1'],
Expand Down Expand Up @@ -300,3 +299,33 @@ def test_launch_node_with_invalid_parameter_dicts(self):
},
},
}])


def test_node_name():
node_without_ns = launch_ros.actions.Node(
package='asd',
executable='bsd',
name='my_node',
)
lc = LaunchContext()
node_without_ns._perform_substitutions(lc)
assert not node_without_ns.is_node_name_fully_specified()

node_without_name = launch_ros.actions.Node(
package='asd',
executable='bsd',
namespace='my_ns',
)
lc = LaunchContext()
node_without_name._perform_substitutions(lc)
assert not node_without_name.is_node_name_fully_specified()

node_with_fqn = launch_ros.actions.Node(
package='asd',
executable='bsd',
name='my_node',
namespace='my_ns',
)
lc = LaunchContext()
node_with_fqn._perform_substitutions(lc)
assert node_with_fqn.is_node_name_fully_specified()
ivanpauno marked this conversation as resolved.
Show resolved Hide resolved