Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for p in n.calls:
if p not in hopNodes:
hopNodes.add(p)
hopEdges.append((n, p, 'solid', colour))
for p in getattr(n, 'interfaces', []):
if p not in hopNodes:
hopNodes.add(p)
hopEdges.append((n, p, 'dashed', colour))
# add nodes, edges and attributes to the graph if maximum number of
# nodes is not exceeded
if self.add_to_graph(hopNodes, hopEdges, nesting):
self.dot.attr('graph', size='11.875,1000.0')
self.dot.attr('graph', concentrate='false')
class CallsGraph(FortranGraph):
RANKDIR = 'LR'
def get_key(self):
colour_notice = COLOURED_NOTICE if _coloured_edges else ''
return CALL_GRAPH_KEY.format(colour_notice)
def add_nodes(self, nodes, nesting=1):
"""
Adds nodes for modules using or descended from those listed in
nodes. Adds appropriate edges between them.
"""
hopNodes = set() # nodes in this hop
hopEdges = [] # edges in this hop
# get nodes and edges for this hop
for i, n in zip(range(len(nodes)), nodes):
r, g, b = rainbowcolour(i, len(nodes))
colour = '#%02X%02X%02X' % (r, g, b)
for c in getattr(n, 'children', []):
if c not in self.added:
hopNodes.add(c)
hopEdges.append((c, n, 'solid', colour))
# add nodes and edges for this hop to the graph if maximum number of
# nodes is not exceeded
if not self.add_to_graph(hopNodes, hopEdges, nesting):
return
elif len(hopNodes) > 0:
if nesting < self.max_nesting:
self.add_nodes(hopNodes, nesting=nesting+1)
else:
self.truncated = nesting
class FileGraph(FortranGraph):
def get_key(self):
colour_notice = COLOURED_NOTICE if _coloured_edges else ''
return FILE_GRAPH_KEY.format(colour_notice)
def add_nodes(self, nodes, nesting=1):
"""
Adds edges showing dependencies between source files listed in
the nodes.
"""
hopNodes = set() # nodes in this hop
hopEdges = [] # edges in this hop
# get nodes and edges for this hop
for i, n in zip(range(len(nodes)), nodes):
r, g, b = rainbowcolour(i, len(nodes))
colour = '#%02X%02X%02X' % (r, g, b)
for ne in n.efferent:
for ne in n.efferent:
if ne not in self.added:
hopNodes.add(ne)
hopEdges.append((n, ne, 'dashed', colour))
# add nodes and edges for this hop to the graph if maximum number of
# nodes is not exceeded
if not self.add_to_graph(hopNodes, hopEdges, nesting):
return
elif len(hopNodes) > 0:
if nesting < self.max_nesting:
self.add_nodes(hopNodes, nesting=nesting+1)
else:
self.truncated = nesting
class AfferentGraph(FortranGraph):
def get_key(self):
colour_notice = COLOURED_NOTICE if _coloured_edges else ''
return FILE_GRAPH_KEY.format(colour_notice)
def add_nodes(self, nodes, nesting=1):
"""
Adds nodes for files which depend upon this one. Adds appropriate
edges between them.
"""
hopNodes = set() # nodes in this hop
hopEdges = [] # edges in this hop
# get nodes and edges for this hop
for i, n in zip(range(len(nodes)), nodes):
r, g, b = rainbowcolour(i, len(nodes))
colour = '#%02X%02X%02X' % (r, g, b)
for na in n.afferent:
if hasattr(n, 'ancestor'):
if n.ancestor not in self.added:
hopNodes.add(n.ancestor)
hopEdges.append((n, n.ancestor, 'solid', colour))
# add nodes and edges for this hop to the graph if maximum number of
# nodes is not exceeded
if not self.add_to_graph(hopNodes, hopEdges, nesting):
return
elif len(hopNodes) > 0:
if nesting < self.max_nesting:
self.add_nodes(hopNodes, nesting=nesting+1)
else:
self.truncated = nesting
class UsedByGraph(FortranGraph):
def get_key(self):
colour_notice = COLOURED_NOTICE if _coloured_edges else ''
return MOD_GRAPH_KEY.format(colour_notice)
def add_nodes(self, nodes, nesting=1):
"""
Adds nodes for modules using or descended from those listed in
nodes. Adds appropriate edges between them.
"""
hopNodes = set() # nodes in this hop
hopEdges = [] # edges in this hop
# get nodes and edges for this hop
for i, n in zip(range(len(nodes)), nodes):
r, g, b = rainbowcolour(i, len(nodes))
colour = '#%02X%02X%02X' % (r, g, b)
for nu in getattr(n, 'used_by', []):
for na in n.afferent:
if na not in self.added:
hopNodes.add(na)
hopEdges.append((na, n, 'dashed', colour))
# add nodes and edges for this hop to the graph if maximum number of
# nodes is not exceeded
if not self.add_to_graph(hopNodes, hopEdges, nesting):
return
elif len(hopNodes) > 0:
if nesting < self.max_nesting:
self.add_nodes(hopNodes, nesting=nesting+1)
else:
self.truncated = nesting
class TypeGraph(FortranGraph):
def get_key(self):
colour_notice = COLOURED_NOTICE if _coloured_edges else ''
return TYPE_GRAPH_KEY.format(colour_notice)
def add_nodes(self, nodes, nesting=1):
"""
Adds edges showing inheritance and composition relationships
between derived types listed in the nodes.
"""
hopNodes = set() # nodes in this hop
hopEdges = [] # edges in this hop
# get nodes and edges for this hop
for i, n in zip(range(len(nodes)), nodes):
r, g, b = rainbowcolour(i, len(nodes))
colour = '#%02X%02X%02X' % (r, g, b)
for keys in n.comp_types.keys():
if p not in self.added:
hopNodes.add(p)
hopEdges.append((n, p, 'dashed', colour))
# add nodes, edges and atrributes for this hop to the graph if
# maximum number of nodes is not exceeded
if not self.add_to_graph(hopNodes, hopEdges, nesting):
return
elif len(hopNodes) > 0:
if nesting < self.max_nesting:
self.dot.attr('graph', concentrate='false')
self.add_nodes(hopNodes, nesting=nesting+1)
else:
self.truncated = nesting
class CalledByGraph(FortranGraph):
RANKDIR = 'LR'
def get_key(self):
colour_notice = COLOURED_NOTICE if _coloured_edges else ''
return CALL_GRAPH_KEY.format(colour_notice)
def add_nodes(self, nodes, nesting=1):
"""
Adds nodes for modules using or descended from those listed in
nodes. Adds appropriate edges between them.
"""
hopNodes = set() # nodes in this hop
hopEdges = [] # edges in this hop
# get nodes and edges for this hop
for i, n in zip(range(len(nodes)), nodes):
r, g, b = rainbowcolour(i, len(nodes))
colour = '#%02X%02X%02X' % (r, g, b)
hopNodes.add(keys)
for c in n.comp_types:
if c not in self.added:
hopNodes.add(c)
hopEdges.append((n, c, 'dashed', colour, n.comp_types[c]))
if n.ancestor:
if n.ancestor not in self.added:
hopNodes.add(n.ancestor)
hopEdges.append((n, n.ancestor, 'solid', colour))
# add nodes, edges and attributes to the graph if maximum number of
# nodes is not exceeded
if self.add_to_graph(hopNodes, hopEdges, nesting):
self.dot.attr('graph', size='11.875,1000.0')
class InheritsGraph(FortranGraph):
def get_key(self):
colour_notice = COLOURED_NOTICE if _coloured_edges else ''
return TYPE_GRAPH_KEY.format(colour_notice)
def add_nodes(self, nodes, nesting=1):
"""
Adds nodes for modules using or descended from those listed in
nodes. Adds appropriate edges between them.
"""
hopNodes = set() # nodes in this hop
hopEdges = [] # edges in this hop
# get nodes and edges for this hop
for i, n in zip(range(len(nodes)), nodes):
r, g, b = rainbowcolour(i, len(nodes))
colour = '#%02X%02X%02X' % (r, g, b)
for c in n.comp_types:
@classmethod
def reset(cls):
cls.data = GraphData()
def create_svg(self, out_location):
if len(self.added) > len(self.root):
self._create_image_file(os.path.join(out_location, self.imgfile))
def _create_image_file(self,filename):
if graphviz_installed:
self.dot.render(filename,cleanup=False)
shutil.move(filename,os.path.join(os.path.dirname(filename),
os.path.basename(filename)+'.gv'))
class ModuleGraph(FortranGraph):
def get_key(self):
colour_notice = COLOURED_NOTICE if _coloured_edges else ''
return MOD_GRAPH_KEY.format(colour_notice)
def add_nodes(self, nodes, nesting=1):
"""
Adds nodes and edges for generating the graph showing the relationship
between modules and submodules listed in nodes.
"""
hopNodes = set() # nodes in this hop
hopEdges = [] # edges in this hop
# get nodes and edges for this hop
for i, n in zip(range(len(nodes)), nodes):
r, g, b = rainbowcolour(i, len(nodes))
colour = '#%02X%02X%02X' % (r, g, b)
for nu in n.uses:
colour = '#%02X%02X%02X' % (r, g, b)
for nu in n.uses:
if nu not in self.added:
hopNodes.add(nu)
hopEdges.append((n, nu, 'dashed', colour))
if hasattr(n, 'ancestor'):
if n.ancestor not in self.added:
hopNodes.add(n.ancestor)
hopEdges.append((n, n.ancestor, 'solid', colour))
# add nodes, edges and attributes to the graph if maximum number of
# nodes is not exceeded
if self.add_to_graph(hopNodes, hopEdges, nesting):
self.dot.attr('graph', size='11.875,1000.0')
class UsesGraph(FortranGraph):
def get_key(self):
colour_notice = COLOURED_NOTICE if _coloured_edges else ''
return MOD_GRAPH_KEY.format(colour_notice)
def add_nodes(self, nodes, nesting=1):
"""
Adds nodes for the modules used by those listed in nodes. Adds
edges between them. Also does this for ancestor (sub)modules.
"""
hopNodes = set() # nodes in this hop
hopEdges = [] # edges in this hop
# get nodes and edges for this hop
for i, n in zip(range(len(nodes)), nodes):
r, g, b = rainbowcolour(i, len(nodes))
colour = '#%02X%02X%02X' % (r, g, b)
for nu in n.uses:
if n.ancestor:
if n.ancestor not in self.added:
hopNodes.add(n.ancestor)
hopEdges.append((n, n.ancestor, 'solid', colour))
# add nodes and edges for this hop to the graph if maximum number of
# nodes is not exceeded
if not self.add_to_graph(hopNodes, hopEdges, nesting):
return
elif len(hopNodes) > 0:
if nesting < self.max_nesting:
self.add_nodes(hopNodes, nesting=nesting+1)
else:
self.truncated = nesting
class InheritedByGraph(FortranGraph):
def get_key(self):
colour_notice = COLOURED_NOTICE if _coloured_edges else ''
return TYPE_GRAPH_KEY.format(colour_notice)
def add_nodes(self, nodes, nesting=1):
"""
Adds nodes for modules using or descended from those listed in
nodes. Adds appropriate edges between them.
"""
hopNodes = set() # nodes in this hop
hopEdges = [] # edges in this hop
# get nodes and edges for this hop
for i, n in zip(range(len(nodes)), nodes):
r, g, b = rainbowcolour(i, len(nodes))
colour = '#%02X%02X%02X' % (r, g, b)
for c in n.comp_of: