Skip to content

Commit

Permalink
RosTimer -> ROSTimer and PushRosNamespace -> PushROSNamespace, to fol…
Browse files Browse the repository at this point in the history
…low PEP8 (#326)

Signed-off-by: William Woodall <[email protected]>

Signed-off-by: William Woodall <[email protected]>
  • Loading branch information
wjwwood authored Sep 28, 2022
1 parent 1ec2fe6 commit 73098cf
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 32 deletions.
8 changes: 6 additions & 2 deletions launch_ros/launch_ros/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
from .lifecycle_node import LifecycleNode
from .load_composable_nodes import LoadComposableNodes
from .node import Node
from .push_ros_namespace import PushRosNamespace
from .ros_timer import RosTimer
from .push_ros_namespace import PushROSNamespace
from .push_ros_namespace import PushROSNamespace as PushRosNamespace
from .ros_timer import ROSTimer
from .ros_timer import ROSTimer as RosTimer
from .set_parameter import SetParameter
from .set_parameters_from_file import SetParametersFromFile
from .set_remap import SetRemap
Expand All @@ -32,7 +34,9 @@
'LifecycleNode',
'LoadComposableNodes',
'Node',
'PushROSNamespace',
'PushRosNamespace',
'ROSTimer',
'RosTimer',
'SetParameter',
'SetParametersFromFile',
Expand Down
8 changes: 4 additions & 4 deletions launch_ros/launch_ros/actions/push_ros_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""Module for the `PushRosNamespace` action."""
"""Module for the `PushROSNamespace` action."""

from typing import List

Expand All @@ -35,7 +35,7 @@

@expose_action('push_ros_namespace')
@expose_action('push-ros-namespace')
class PushRosNamespace(Action):
class PushROSNamespace(Action):
"""
Action that pushes the ros namespace.
Expand All @@ -48,13 +48,13 @@ def __init__(
namespace: SomeSubstitutionsType,
**kwargs
) -> None:
"""Create a PushRosNamespace action."""
"""Create a PushROSNamespace action."""
super().__init__(**kwargs)
self.__namespace = normalize_to_list_of_substitutions(namespace)

@classmethod
def parse(cls, entity: Entity, parser: Parser):
"""Return `PushRosNamespace` action and kwargs for constructing it."""
"""Return `PushROSNamespace` action and kwargs for constructing it."""
_, kwargs = super().parse(entity, parser)
kwargs['namespace'] = parser.parse_substitution(entity.get_attr('namespace'))
return cls, kwargs
Expand Down
16 changes: 8 additions & 8 deletions launch_ros/launch_ros/actions/ros_timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""Module for the RosTimer action."""
"""Module for the ROSTimer action."""

import asyncio
import collections.abc
Expand All @@ -39,7 +39,7 @@


@expose_action('ros_timer')
class RosTimer(TimerAction):
class ROSTimer(TimerAction):
"""
Action that defers other entities until a period of time has passed, unless canceled.
Expand All @@ -56,15 +56,15 @@ def __init__(
**kwargs
) -> None:
"""
Create a RosTimer.
Create a ROSTimer.
:param period: is the time (in seconds) to set the timer for.
:param actions: is an iterable containing actions to be executed upon on timeout.
"""
super().__init__(period=period, actions=actions, **kwargs)
period_types = list(SomeSubstitutionsType_types_tuple) + [float]
ensure_argument_type(period, period_types, 'period', 'RosTimer')
ensure_argument_type(actions, collections.abc.Iterable, 'actions', 'RosTimer')
ensure_argument_type(period, period_types, 'period', 'ROSTimer')
ensure_argument_type(actions, collections.abc.Iterable, 'actions', 'ROSTimer')
self.__period = type_utils.normalize_typed_substitution(period, float)
self.__timer_future: Optional[asyncio.Future] = None

Expand Down Expand Up @@ -94,16 +94,16 @@ def parse(
entity: Entity,
parser: Parser,
):
"""Return the `RosTimer` action and kwargs for constructing it."""
"""Return the `ROSTimer` action and kwargs for constructing it."""
_, kwargs = super().parse(entity, parser)
kwargs['period'] = parser.parse_if_substitutions(
entity.get_attr('period', data_type=float, can_be_str=True))
kwargs['actions'] = [parser.parse_action(child) for child in entity.children]
return cls, kwargs

def describe(self) -> Text:
"""Return a description of this RosTimer."""
return 'RosTimer(period={}, actions=<actions>)'.format(self.__period)
"""Return a description of this ROSTimer."""
return 'ROSTimer(period={}, actions=<actions>)'.format(self.__period)

def execute(self, context: LaunchContext):
self.__timer_future = create_future(context.asyncio_loop)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from launch import LaunchService
from launch.actions import GroupAction
from launch_ros.actions import LoadComposableNodes
from launch_ros.actions import PushRosNamespace
from launch_ros.actions import PushROSNamespace
from launch_ros.actions import SetRemap
from launch_ros.descriptions import ComposableNode
from launch_ros.utilities import get_node_name_count
Expand Down Expand Up @@ -414,7 +414,7 @@ def test_load_node_with_param_file(mock_component_container):
# Node name with namespace from launch
# Params file has no namespace
context = _assert_launch_no_errors([
PushRosNamespace('ns'),
PushROSNamespace('ns'),
_load_composable_node(
package='foo_package',
plugin='bar_plugin',
Expand All @@ -433,7 +433,7 @@ def test_load_node_with_param_file(mock_component_container):
# Node name with namespace from launch
# Params file has expected namespace
context = _assert_launch_no_errors([
PushRosNamespace('ns'),
PushROSNamespace('ns'),
_load_composable_node(
package='foo_package',
plugin='bar_plugin',
Expand Down Expand Up @@ -490,7 +490,7 @@ def test_load_node_with_namespace_in_group(mock_component_container):
context = _assert_launch_no_errors([
GroupAction(
[
PushRosNamespace('foo'),
PushROSNamespace('foo'),
_load_composable_node(
package='foo_package',
plugin='bar_plugin',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tests for the PushRosNamespace Action."""
"""Tests for the PushROSNamespace Action."""

from launch_ros.actions import Node
from launch_ros.actions import PushRosNamespace
from launch_ros.actions import PushROSNamespace
from launch_ros.actions.load_composable_nodes import get_composable_node_load_request
from launch_ros.descriptions import ComposableNode

Expand Down Expand Up @@ -105,10 +105,10 @@ def get_test_cases():
def test_push_ros_namespace(config):
lc = MockContext()
if config.push_ns is not None:
pns1 = PushRosNamespace(config.push_ns)
pns1 = PushROSNamespace(config.push_ns)
pns1.execute(lc)
if config.second_push_ns is not None:
pns2 = PushRosNamespace(config.second_push_ns)
pns2 = PushROSNamespace(config.second_push_ns)
pns2.execute(lc)
node = Node(
package='dont_care',
Expand All @@ -132,10 +132,10 @@ def test_push_ros_namespace(config):
def test_push_ros_namespace_with_composable_node(config):
lc = MockContext()
if config.push_ns is not None:
pns1 = PushRosNamespace(config.push_ns)
pns1 = PushROSNamespace(config.push_ns)
pns1.execute(lc)
if config.second_push_ns is not None:
pns2 = PushRosNamespace(config.second_push_ns)
pns2 = PushROSNamespace(config.second_push_ns)
pns2.execute(lc)
node_description = ComposableNode(
package='asd',
Expand Down
16 changes: 8 additions & 8 deletions test_launch_ros/test/test_launch_ros/actions/test_ros_timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.


"""Tests for the RosTimer Action."""
"""Tests for the ROSTimer Action."""
from functools import partial
import threading
import time
Expand All @@ -23,7 +23,7 @@
from launch.actions import DeclareLaunchArgument
import launch.event_handlers
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import RosTimer
from launch_ros.actions import ROSTimer
from launch_ros.actions import SetUseSimTime
import pytest
import rclpy
Expand Down Expand Up @@ -57,7 +57,7 @@ def test_multiple_launch_with_timers():
def generate_launch_description():
return launch.LaunchDescription([

RosTimer(
ROSTimer(
period=1.,
actions=[]
),
Expand All @@ -76,7 +76,7 @@ def test_timer_with_launch_configuration():
def generate_launch_description():
return launch.LaunchDescription([
DeclareLaunchArgument('my_period', default_value='0.1'),
RosTimer(
ROSTimer(
period=LaunchConfiguration('my_period'),
actions=[]
),
Expand All @@ -98,7 +98,7 @@ def test_timer_action_sanity_check():

launch.actions.OpaqueFunction(function=set_start_time),

RosTimer(
ROSTimer(
period=1.,
actions=[
launch.actions.OpaqueFunction(function=set_end_time),
Expand All @@ -125,14 +125,14 @@ def test_shutdown_preempts_timers():

ld = launch.LaunchDescription([

RosTimer(
ROSTimer(
period=1.,
actions=[
launch.actions.Shutdown(reason='fast shutdown')
]
),

RosTimer(
ROSTimer(
period=2.,
actions=[
launch.actions.Shutdown(reason='slow shutdown')
Expand Down Expand Up @@ -179,7 +179,7 @@ def timer_callback(publisher, time_msg):

launch.actions.OpaqueFunction(function=set_start_time),

RosTimer(
ROSTimer(
period=200.,
actions=[
launch.actions.OpaqueFunction(function=set_end_time)
Expand Down

0 comments on commit 73098cf

Please sign in to comment.