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

Convert node to list so that they are processed in order. #507

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 2 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
17 changes: 7 additions & 10 deletions src/roswire/common/launch/config/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand All @@ -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)
Expand All @@ -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()))
Copy link
Member

Choose a reason for hiding this comment

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

prefer (immutable) tuple over list

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done


def with_env(self, name: str, value: str) -> "LaunchConfig":
"""Adds an environment variable to this configuration."""
Expand Down Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

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

beware: nodes is a list here; we probably want to convert it to a tuple before passing it to evolve (otherwise we'll get a crash on line 140)


def with_executable(self, executable: str) -> "LaunchConfig":
"""Specify an executable that should be run at launch."""
Expand All @@ -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 | list(node)
Copy link
Member

Choose a reason for hiding this comment

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

I haven't looked at the mypy output yet, but I suspect that this is the line that's causing it to fail. The set union operator doesn't make sense for a list here. This line can just be replaced by:

nodes = self.nodes + [node]

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I completely misread what this line was doing. Changed it to extend the tuple

return attr.evolve(self, nodes=nodes)

def to_xml_tree(self) -> ET.ElementTree:
Expand Down