From 68ff6eac29cc909f2c0bd05c011eeaf101174d6d Mon Sep 17 00:00:00 2001 From: Bradley Schmerl Date: Fri, 29 Oct 2021 10:04:06 -0400 Subject: [PATCH 1/7] Convert node to list so that they are processed in order. --- src/roswire/common/launch/config/launch.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/roswire/common/launch/config/launch.py b/src/roswire/common/launch/config/launch.py index db3a97594..7ac5199c0 100644 --- a/src/roswire/common/launch/config/launch.py +++ b/src/roswire/common/launch/config/launch.py @@ -4,14 +4,13 @@ import xml.dom.minidom as minidom import xml.etree.ElementTree as ET from typing import ( - AbstractSet, Any, Collection, Dict, + List, Mapping, Optional, Sequence, - Set, Tuple, ) @@ -32,9 +31,7 @@ @attr.s(frozen=True, slots=True) class LaunchConfig: - nodes: AbstractSet[NodeConfig] = attr.ib( - default=frozenset(), converter=frozenset - ) + nodes: Sequence[NodeConfig] = attr.ib(default=()) executables: Sequence[str] = attr.ib(default=()) roslaunch_files: Sequence[str] = attr.ib(default=()) params: Mapping[str, Any] = attr.ib(factory=dict) @@ -59,7 +56,7 @@ def with_launch_prefixes( nodes: Dict[str, NodeConfig] = {n.name: n for n in self.nodes} for node_name, prefix in prefixes.items(): nodes[node_name] = nodes[node_name].with_launch_prefix(prefix) - return attr.evolve(self, nodes=frozenset(nodes.values())) + return attr.evolve(self, nodes=list(nodes.values())) def with_env(self, name: str, value: str) -> "LaunchConfig": """Adds an environment variable to this configuration.""" @@ -117,12 +114,12 @@ def with_remappings( self, node_to_remappings: Mapping[str, Collection[Tuple[str, str]]], # noqa ) -> "LaunchConfig": - nodes: Set[NodeConfig] = set() + nodes: List[NodeConfig] = [] for node in self.nodes: if node.name in node_to_remappings: node = node.with_remappings(node_to_remappings[node.name]) - nodes.add(node) - return attr.evolve(self, nodes=frozenset(nodes)) + nodes.append(node) + return attr.evolve(self, nodes=nodes) def with_executable(self, executable: str) -> "LaunchConfig": """Specify an executable that should be run at launch.""" @@ -140,7 +137,7 @@ def with_node(self, node: NodeConfig) -> "LaunchConfig": m = "multiple definitions of node [{}] in launch configuration" m = m.format(node.full_name) raise FailedToParseLaunchFile(m) - nodes = self.nodes | frozenset({node}) + nodes = self.nodes | [node] return attr.evolve(self, nodes=nodes) def to_xml_tree(self) -> ET.ElementTree: From 3972da48d1f063b8517339a210192104aa4f5000 Mon Sep 17 00:00:00 2001 From: Bradley Schmerl Date: Fri, 29 Oct 2021 10:22:55 -0400 Subject: [PATCH 2/7] Try random thing --- src/roswire/common/launch/config/launch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/roswire/common/launch/config/launch.py b/src/roswire/common/launch/config/launch.py index 7ac5199c0..fbe3fcd0f 100644 --- a/src/roswire/common/launch/config/launch.py +++ b/src/roswire/common/launch/config/launch.py @@ -137,7 +137,7 @@ def with_node(self, node: NodeConfig) -> "LaunchConfig": m = "multiple definitions of node [{}] in launch configuration" m = m.format(node.full_name) raise FailedToParseLaunchFile(m) - nodes = self.nodes | [node] + nodes = self.nodes | list(node) return attr.evolve(self, nodes=nodes) def to_xml_tree(self) -> ET.ElementTree: From fcf7d56567d9357f7df558ba43ebb64f3e6ee629 Mon Sep 17 00:00:00 2001 From: Bradley Schmerl Date: Fri, 29 Oct 2021 11:08:29 -0400 Subject: [PATCH 3/7] Using tuples instead of list. --- src/roswire/common/launch/config/launch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/roswire/common/launch/config/launch.py b/src/roswire/common/launch/config/launch.py index fbe3fcd0f..6d3e031f4 100644 --- a/src/roswire/common/launch/config/launch.py +++ b/src/roswire/common/launch/config/launch.py @@ -56,7 +56,7 @@ def with_launch_prefixes( nodes: Dict[str, NodeConfig] = {n.name: n for n in self.nodes} for node_name, prefix in prefixes.items(): nodes[node_name] = nodes[node_name].with_launch_prefix(prefix) - return attr.evolve(self, nodes=list(nodes.values())) + return attr.evolve(self, nodes=tuple(nodes.values())) def with_env(self, name: str, value: str) -> "LaunchConfig": """Adds an environment variable to this configuration.""" @@ -137,7 +137,7 @@ def with_node(self, node: NodeConfig) -> "LaunchConfig": m = "multiple definitions of node [{}] in launch configuration" m = m.format(node.full_name) raise FailedToParseLaunchFile(m) - nodes = self.nodes | list(node) + nodes = self.nodes + (node,) return attr.evolve(self, nodes=nodes) def to_xml_tree(self) -> ET.ElementTree: From 06628185f8146013472ae9f5fb71d973ce9e517a Mon Sep 17 00:00:00 2001 From: Bradley Schmerl Date: Fri, 29 Oct 2021 11:31:39 -0400 Subject: [PATCH 4/7] Mypy fixes --- src/roswire/common/launch/config/launch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/roswire/common/launch/config/launch.py b/src/roswire/common/launch/config/launch.py index 6d3e031f4..0295fd75f 100644 --- a/src/roswire/common/launch/config/launch.py +++ b/src/roswire/common/launch/config/launch.py @@ -31,7 +31,7 @@ @attr.s(frozen=True, slots=True) class LaunchConfig: - nodes: Sequence[NodeConfig] = attr.ib(default=()) + nodes: Tuple[NodeConfig, ...] = attr.ib(default=()) executables: Sequence[str] = attr.ib(default=()) roslaunch_files: Sequence[str] = attr.ib(default=()) params: Mapping[str, Any] = attr.ib(factory=dict) @@ -138,7 +138,7 @@ def with_node(self, node: NodeConfig) -> "LaunchConfig": m = m.format(node.full_name) raise FailedToParseLaunchFile(m) nodes = self.nodes + (node,) - return attr.evolve(self, nodes=nodes) + return attr.evolve(self, nodes=tuple(nodes)) def to_xml_tree(self) -> ET.ElementTree: root = ET.Element("launch") From b3005cc8d468037022731c3800c9621e418ac2c0 Mon Sep 17 00:00:00 2001 From: Bradley Schmerl Date: Sat, 30 Oct 2021 14:27:52 -0400 Subject: [PATCH 5/7] Tuple -> Sequence --- src/roswire/common/launch/config/launch.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/roswire/common/launch/config/launch.py b/src/roswire/common/launch/config/launch.py index 0295fd75f..f1c854832 100644 --- a/src/roswire/common/launch/config/launch.py +++ b/src/roswire/common/launch/config/launch.py @@ -11,7 +11,6 @@ Mapping, Optional, Sequence, - Tuple, ) import attr @@ -31,7 +30,7 @@ @attr.s(frozen=True, slots=True) class LaunchConfig: - nodes: Tuple[NodeConfig, ...] = attr.ib(default=()) + nodes: Sequence[NodeConfig, ...] = attr.ib(default=()) executables: Sequence[str] = attr.ib(default=()) roslaunch_files: Sequence[str] = attr.ib(default=()) params: Mapping[str, Any] = attr.ib(factory=dict) From 2118967987c7e610a028a502f9d8736cd75e45d7 Mon Sep 17 00:00:00 2001 From: Bradley Schmerl Date: Sat, 30 Oct 2021 14:29:16 -0400 Subject: [PATCH 6/7] Tuple -> Sequence --- src/roswire/common/launch/config/launch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/roswire/common/launch/config/launch.py b/src/roswire/common/launch/config/launch.py index f1c854832..12230e53e 100644 --- a/src/roswire/common/launch/config/launch.py +++ b/src/roswire/common/launch/config/launch.py @@ -30,7 +30,7 @@ @attr.s(frozen=True, slots=True) class LaunchConfig: - nodes: Sequence[NodeConfig, ...] = attr.ib(default=()) + nodes: Sequence[NodeConfig] = attr.ib(default=()) executables: Sequence[str] = attr.ib(default=()) roslaunch_files: Sequence[str] = attr.ib(default=()) params: Mapping[str, Any] = attr.ib(factory=dict) From 90b1aaece6a9a5e0b76c193cbbb41c6ea4341390 Mon Sep 17 00:00:00 2001 From: Bradley Schmerl Date: Sat, 30 Oct 2021 15:34:56 -0400 Subject: [PATCH 7/7] Added Tuple import --- src/roswire/common/launch/config/launch.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/roswire/common/launch/config/launch.py b/src/roswire/common/launch/config/launch.py index 12230e53e..ac4425c4f 100644 --- a/src/roswire/common/launch/config/launch.py +++ b/src/roswire/common/launch/config/launch.py @@ -11,6 +11,7 @@ Mapping, Optional, Sequence, + Tuple, ) import attr