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

Conversation

schmerl
Copy link
Collaborator

@schmerl schmerl commented Oct 29, 2021

Nodes in a LaunchConfig were sets, which breaks the ordering required for starting nodelets after nodelet managers.

@@ -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

@@ -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

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)

@@ -31,7 +31,7 @@

@attr.s(frozen=True, slots=True)
class LaunchConfig:
nodes: Sequence[NodeConfig] = attr.ib(default=())
nodes: Tuple[NodeConfig, ...] = attr.ib(default=())
Copy link
Member

Choose a reason for hiding this comment

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

why this change? (tuples are sequences)

Copy link
Collaborator Author

@schmerl schmerl Oct 30, 2021

Choose a reason for hiding this comment

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

If I make it a Sequence, mypy doesn't like the '+' operation.

src/roswire/common/launch/config/launch.py:140: error: Unsupported left operand type for + ("Sequence[NodeConfig]")

Is there a way around this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants