Skip to content

Commit

Permalink
macholib, altgraph: update vendored dependency (spack#28664)
Browse files Browse the repository at this point in the history
  • Loading branch information
alalazo authored Jan 28, 2022
1 parent 4bd761d commit bc06c12
Show file tree
Hide file tree
Showing 25 changed files with 1,345 additions and 1,253 deletions.
4 changes: 2 additions & 2 deletions lib/spack/external/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Homepage: https://altgraph.readthedocs.io/en/latest/index.html
* Usage: dependency of macholib
* Version: 0.16.1
* Version: 0.17.2
archspec
--------
Expand Down Expand Up @@ -96,7 +96,7 @@
* Homepage: https://macholib.readthedocs.io/en/latest/index.html#
* Usage: Manipulation of Mach-o binaries for relocating macOS buildcaches on Linux
* Version: 1.12
* Version: 1.15.2
markupsafe
----------
Expand Down
100 changes: 56 additions & 44 deletions lib/spack/external/altgraph/Dot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''
"""
altgraph.Dot - Interface to the dot language
============================================
Expand Down Expand Up @@ -107,33 +107,42 @@
- for more details on how to control the graph drawing process see the
`graphviz reference
<http://www.research.att.com/sw/tools/graphviz/refs.html>`_.
'''
"""
import os
import warnings

from altgraph import GraphError


class Dot(object):
'''
"""
A class providing a **graphviz** (dot language) representation
allowing a fine grained control over how the graph is being
displayed.
If the :command:`dot` and :command:`dotty` programs are not in the current
system path their location needs to be specified in the contructor.
'''
"""

def __init__(
self, graph=None, nodes=None, edgefn=None, nodevisitor=None,
edgevisitor=None, name="G", dot='dot', dotty='dotty',
neato='neato', graphtype="digraph"):
'''
self,
graph=None,
nodes=None,
edgefn=None,
nodevisitor=None,
edgevisitor=None,
name="G",
dot="dot",
dotty="dotty",
neato="neato",
graphtype="digraph",
):
"""
Initialization.
'''
"""
self.name, self.attr = name, {}

assert graphtype in ['graph', 'digraph']
assert graphtype in ["graph", "digraph"]
self.type = graphtype

self.temp_dot = "tmp_dot.dot"
Expand All @@ -148,8 +157,10 @@ def __init__(
if graph is not None and nodes is None:
nodes = graph
if graph is not None and edgefn is None:

def edgefn(node, graph=graph):
return graph.out_nbrs(node)

if nodes is None:
nodes = ()

Expand Down Expand Up @@ -177,20 +188,19 @@ def edgefn(node, graph=graph):
self.edge_style(head, tail, **edgestyle)

def style(self, **attr):
'''
"""
Changes the overall style
'''
"""
self.attr = attr

def display(self, mode='dot'):
'''
def display(self, mode="dot"):
"""
Displays the current graph via dotty
'''
"""

if mode == 'neato':
if mode == "neato":
self.save_dot(self.temp_neo)
neato_cmd = "%s -o %s %s" % (
self.neato, self.temp_dot, self.temp_neo)
neato_cmd = "%s -o %s %s" % (self.neato, self.temp_dot, self.temp_neo)
os.system(neato_cmd)
else:
self.save_dot(self.temp_dot)
Expand All @@ -199,24 +209,24 @@ def display(self, mode='dot'):
os.system(plot_cmd)

def node_style(self, node, **kwargs):
'''
"""
Modifies a node style to the dot representation.
'''
"""
if node not in self.edges:
self.edges[node] = {}
self.nodes[node] = kwargs

def all_node_style(self, **kwargs):
'''
"""
Modifies all node styles
'''
"""
for node in self.nodes:
self.node_style(node, **kwargs)

def edge_style(self, head, tail, **kwargs):
'''
"""
Modifies an edge style to the dot representation.
'''
"""
if tail not in self.nodes:
raise GraphError("invalid node %s" % (tail,))

Expand All @@ -229,22 +239,22 @@ def edge_style(self, head, tail, **kwargs):

def iterdot(self):
# write graph title
if self.type == 'digraph':
yield 'digraph %s {\n' % (self.name,)
elif self.type == 'graph':
yield 'graph %s {\n' % (self.name,)
if self.type == "digraph":
yield "digraph %s {\n" % (self.name,)
elif self.type == "graph":
yield "graph %s {\n" % (self.name,)

else:
raise GraphError("unsupported graphtype %s" % (self.type,))

# write overall graph attributes
for attr_name, attr_value in sorted(self.attr.items()):
yield '%s="%s";' % (attr_name, attr_value)
yield '\n'
yield "\n"

# some reusable patterns
cpatt = '%s="%s",' # to separate attributes
epatt = '];\n' # to end attributes
cpatt = '%s="%s",' # to separate attributes
epatt = "];\n" # to end attributes

# write node attributes
for node_name, node_attr in sorted(self.nodes.items()):
Expand All @@ -256,25 +266,24 @@ def iterdot(self):
# write edge attributes
for head in sorted(self.edges):
for tail in sorted(self.edges[head]):
if self.type == 'digraph':
if self.type == "digraph":
yield '\t"%s" -> "%s" [' % (head, tail)
else:
yield '\t"%s" -- "%s" [' % (head, tail)
for attr_name, attr_value in \
sorted(self.edges[head][tail].items()):
for attr_name, attr_value in sorted(self.edges[head][tail].items()):
yield cpatt % (attr_name, attr_value)
yield epatt

# finish file
yield '}\n'
yield "}\n"

def __iter__(self):
return self.iterdot()

def save_dot(self, file_name=None):
'''
"""
Saves the current graph representation into a file
'''
"""

if not file_name:
warnings.warn(DeprecationWarning, "always pass a file_name")
Expand All @@ -284,19 +293,18 @@ def save_dot(self, file_name=None):
for chunk in self.iterdot():
fp.write(chunk)

def save_img(self, file_name=None, file_type="gif", mode='dot'):
'''
def save_img(self, file_name=None, file_type="gif", mode="dot"):
"""
Saves the dot file as an image file
'''
"""

if not file_name:
warnings.warn(DeprecationWarning, "always pass a file_name")
file_name = "out"

if mode == 'neato':
if mode == "neato":
self.save_dot(self.temp_neo)
neato_cmd = "%s -o %s %s" % (
self.neato, self.temp_dot, self.temp_neo)
neato_cmd = "%s -o %s %s" % (self.neato, self.temp_dot, self.temp_neo)
os.system(neato_cmd)
plot_cmd = self.dot
else:
Expand All @@ -305,5 +313,9 @@ def save_img(self, file_name=None, file_type="gif", mode='dot'):

file_name = "%s.%s" % (file_name, file_type)
create_cmd = "%s -T%s %s -o %s" % (
plot_cmd, file_type, self.temp_dot, file_name)
plot_cmd,
file_type,
self.temp_dot,
file_name,
)
os.system(create_cmd)
34 changes: 18 additions & 16 deletions lib/spack/external/altgraph/Graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
#--Nathan Denny, May 27, 1999
"""

from altgraph import GraphError
from collections import deque

from altgraph import GraphError


class Graph(object):
"""
Expand Down Expand Up @@ -58,8 +59,10 @@ def __init__(self, edges=None):
raise GraphError("Cannot create edge from %s" % (item,))

def __repr__(self):
return '<Graph: %d nodes, %d edges>' % (
self.number_of_nodes(), self.number_of_edges())
return "<Graph: %d nodes, %d edges>" % (
self.number_of_nodes(),
self.number_of_edges(),
)

def add_node(self, node, node_data=None):
"""
Expand Down Expand Up @@ -111,7 +114,7 @@ def add_edge(self, head_id, tail_id, edge_data=1, create_nodes=True):
self.nodes[tail_id][0].append(edge)
self.nodes[head_id][1].append(edge)
except KeyError:
raise GraphError('Invalid nodes %s -> %s' % (head_id, tail_id))
raise GraphError("Invalid nodes %s -> %s" % (head_id, tail_id))

# store edge information
self.edges[edge] = (head_id, tail_id, edge_data)
Expand All @@ -124,13 +127,12 @@ def hide_edge(self, edge):
time.
"""
try:
head_id, tail_id, edge_data = \
self.hidden_edges[edge] = self.edges[edge]
head_id, tail_id, edge_data = self.hidden_edges[edge] = self.edges[edge]
self.nodes[tail_id][0].remove(edge)
self.nodes[head_id][1].remove(edge)
del self.edges[edge]
except KeyError:
raise GraphError('Invalid edge %s' % edge)
raise GraphError("Invalid edge %s" % edge)

def hide_node(self, node):
"""
Expand All @@ -144,7 +146,7 @@ def hide_node(self, node):
self.hide_edge(edge)
del self.nodes[node]
except KeyError:
raise GraphError('Invalid node %s' % node)
raise GraphError("Invalid node %s" % node)

def restore_node(self, node):
"""
Expand All @@ -157,7 +159,7 @@ def restore_node(self, node):
self.restore_edge(edge)
del self.hidden_nodes[node]
except KeyError:
raise GraphError('Invalid node %s' % node)
raise GraphError("Invalid node %s" % node)

def restore_edge(self, edge):
"""
Expand All @@ -170,7 +172,7 @@ def restore_edge(self, edge):
self.edges[edge] = head_id, tail_id, data
del self.hidden_edges[edge]
except KeyError:
raise GraphError('Invalid edge %s' % edge)
raise GraphError("Invalid edge %s" % edge)

def restore_all_edges(self):
"""
Expand Down Expand Up @@ -203,7 +205,7 @@ def edge_by_id(self, edge):
head, tail, data = self.edges[edge]
except KeyError:
head, tail = None, None
raise GraphError('Invalid edge %s' % edge)
raise GraphError("Invalid edge %s" % edge)

return (head, tail)

Expand Down Expand Up @@ -339,7 +341,7 @@ def out_edges(self, node):
try:
return list(self.nodes[node][1])
except KeyError:
raise GraphError('Invalid node %s' % node)
raise GraphError("Invalid node %s" % node)

def inc_edges(self, node):
"""
Expand All @@ -348,7 +350,7 @@ def inc_edges(self, node):
try:
return list(self.nodes[node][0])
except KeyError:
raise GraphError('Invalid node %s' % node)
raise GraphError("Invalid node %s" % node)

def all_edges(self, node):
"""
Expand Down Expand Up @@ -488,7 +490,7 @@ def iterdfs(self, start, end=None, forward=True):
The forward parameter specifies whether it is a forward or backward
traversal.
"""
visited, stack = set([start]), deque([start])
visited, stack = {start}, deque([start])

if forward:
get_edges = self.out_edges
Expand All @@ -515,7 +517,7 @@ def iterdata(self, start, end=None, forward=True, condition=None):
condition callback is only called when node_data is not None.
"""

visited, stack = set([start]), deque([start])
visited, stack = {start}, deque([start])

if forward:
get_edges = self.out_edges
Expand Down Expand Up @@ -547,7 +549,7 @@ def _iterbfs(self, start, end=None, forward=True):
traversal. Returns a list of tuples where the first value is the hop
value the second value is the node id.
"""
queue, visited = deque([(start, 0)]), set([start])
queue, visited = deque([(start, 0)]), {start}

# the direction of the bfs depends on the edges that are sampled
if forward:
Expand Down
Loading

0 comments on commit bc06c12

Please sign in to comment.