Commit c8854a35 authored by Jameson Rollins's avatar Jameson Rollins

update to support networkx >=2

networkx 2 dropped the {nodes,edges}_iter methods, with the nodes/edges
methods now returning Views.  We can just use the non _iter methods from
earlier versions that just return lists of nodes and edges, as these
methods are available in all versions (although they return lists instead
of Views in versions earlier than 2).
parent b7a6a28e
......@@ -68,7 +68,7 @@ def find_jump_edges(guardstate, module):
def fullgraph(system, find_jumps=False):
"""Return MultiDiGraph copy of system graph with JUMP edges added."""
G = networkx.MultiDiGraph(system.graph)
for node, data in G.nodes_iter(data=True):
for node, data in G.nodes(data=True):
code = data['code']
obj = code()
if find_jumps:
......@@ -107,7 +107,7 @@ def sys2dot(system,
}
# http://www.graphviz.org/content/attrs
for node, data in G.nodes_iter(data=True):
for node, data in G.nodes(data=True):
# node attribute defaults
label = '%s' % (node)
shape = 'oval'
......@@ -164,7 +164,7 @@ def sys2dot(system,
# set edge attributes
remove_edges = []
for edge in G.edges_iter(data=True, keys=True):
for edge in G.edges(data=True, keys=True):
source, sink, key, data = edge
# label edges with their weight
......
......@@ -107,7 +107,7 @@ p.add_argument('-r', '--requests-only', action='store_true',
def print_edges(args):
"""Print transition edges."""
system = cli.init_system(args, load=True)
for edge in system.graph.edges_iter(data=True):
for edge in system.graph.edges(data=True):
source, sink, data = edge
print('({0}, {1}, {2})'.format(source, sink, data['weight']))
......
......@@ -636,7 +636,7 @@ class GuardSystem(object):
for filt in filters:
r &= data[filt[0]] == filt[1]
return r
for state, data in sorted(self._graph.nodes_iter(data=True),
for state, data in sorted(self._graph.nodes(data=True),
key=lambda out: out[1]['index'],
reverse=reverse):
if init_last and state == 'INIT':
......@@ -695,7 +695,7 @@ class GuardSystem(object):
def __iter__(self):
"""Iterator over state names."""
return self._graph.nodes_iter()
return iter(self._graph.nodes())
def _data_for_key(self, key):
"""Return state (key, data) tuple for state.
......@@ -714,7 +714,7 @@ class GuardSystem(object):
raise KeyError("%s is not a state name" % key)
elif isinstance(key, int):
for state, data in self._graph.nodes_iter(data=True):
for state, data in self._graph.nodes(data=True):
if data['index'] == key:
return state, data
raise KeyError("%s is not a state index" % key)
......@@ -731,15 +731,15 @@ class GuardSystem(object):
@property
def indices(self):
"""List of state indices."""
return [data['index'] for state, data in self._graph.nodes_iter(data=True)]
return [data['index'] for state, data in self._graph.nodes(data=True)]
def state_index_dict(self):
"""Return a dict of state:index pairs."""
return {state: data['index'] for state, data in self._graph.nodes_iter(data=True)}
return {state: data['index'] for state, data in self._graph.nodes(data=True)}
def index_state_dict(self):
"""Return a dict of index:state pairs."""
return {data['index']: state for state, data in self._graph.nodes_iter(data=True)}
return {data['index']: state for state, data in self._graph.nodes(data=True)}
def index(self, key):
"""Convert state name to index or vice versa.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment