Skip to content

Commit

Permalink
Update method calls to get nodes from DiGraph
Browse files Browse the repository at this point in the history
The networkx library has changed some interfaces in v2.x. The node attribute
is no longer a member of DiGraph therefore use nodes attribute instead.
  • Loading branch information
m4dcoder committed Sep 18, 2021
1 parent bba7fcc commit c805e33
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions st2common/st2common/util/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ def _process_defaults(G, schemas):
"""
for schema in schemas:
for name, value in six.iteritems(schema):
absent = name not in G.node
is_none = G.node.get(name, {}).get("value") is None
absent = name not in G.nodes
is_none = G.nodes.get(name, {}).get("value") is None
immutable = value.get("immutable", False)
if absent or is_none or immutable:
_process(G, name, value.get("default"))
Expand All @@ -167,8 +167,8 @@ def _validate(G):
"""
Validates dependency graph to ensure it has no missing or cyclic dependencies
"""
for name in G.nodes():
if "value" not in G.node[name] and "template" not in G.node[name]:
for name in G.nodes:
if "value" not in G.nodes[name] and "template" not in G.nodes[name]:
msg = 'Dependency unsatisfied in variable "%s"' % name
raise ParamException(msg)

Expand Down Expand Up @@ -232,7 +232,7 @@ def _resolve_dependencies(G):
"""
context = {}
for name in nx.topological_sort(G):
node = G.node[name]
node = G.nodes[name]
try:
context[name] = _render(node, context)

Expand Down
6 changes: 3 additions & 3 deletions tools/st2-analyze-links.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ def generate_graph(self, rule_links, out_file):
print(rule_link._source_action_ref)
if rule_link._source_action_ref not in nodes:
nodes.add(rule_link._source_action_ref)
dot.node(rule_link._source_action_ref, rule_link._source_action_ref)
dot.add_node(rule_link._source_action_ref)
if rule_link._dest_action_ref not in nodes:
nodes.add(rule_link._dest_action_ref)
dot.node(rule_link._dest_action_ref, rule_link._dest_action_ref)
dot.edge(
dot.add_node(rule_link._dest_action_ref)
dot.add_edge(
rule_link._source_action_ref,
rule_link._dest_action_ref,
constraint="true",
Expand Down
6 changes: 3 additions & 3 deletions tools/visualize_action_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def main(metadata_path, output_path, print_source=False):
# Add all nodes
node = chain_holder.get_next_node()
while node:
dot.node(node.name, node.name)
dot.add_node(node.name)
node = chain_holder.get_next_node(curr_node_name=node.name)

# Add connections
Expand All @@ -89,7 +89,7 @@ def main(metadata_path, output_path, print_source=False):

# Add success node (if any)
if success_node:
dot.edge(
dot.add_edge(
previous_node.name,
success_node.name,
constraint="true",
Expand All @@ -102,7 +102,7 @@ def main(metadata_path, output_path, print_source=False):

# Add failure node (if any)
if failure_node:
dot.edge(
dot.add_edge(
previous_node.name,
failure_node.name,
constraint="true",
Expand Down

0 comments on commit c805e33

Please sign in to comment.