spack graph allows plotting specific packages.
This commit is contained in:
parent
9dabcc8703
commit
860f834aad
@ -269,6 +269,28 @@ def in_function(function_name):
|
|||||||
del stack
|
del stack
|
||||||
|
|
||||||
|
|
||||||
|
def check_kwargs(kwargs, fun):
|
||||||
|
"""Helper for making functions with kwargs. Checks whether the kwargs
|
||||||
|
are empty after all of them have been popped off. If they're
|
||||||
|
not, raises an error describing which kwargs are invalid.
|
||||||
|
|
||||||
|
Example::
|
||||||
|
|
||||||
|
def foo(self, **kwargs):
|
||||||
|
x = kwargs.pop('x', None)
|
||||||
|
y = kwargs.pop('y', None)
|
||||||
|
z = kwargs.pop('z', None)
|
||||||
|
check_kwargs(kwargs, self.foo)
|
||||||
|
|
||||||
|
# This raises a TypeError:
|
||||||
|
foo(w='bad kwarg')
|
||||||
|
"""
|
||||||
|
if kwargs:
|
||||||
|
raise TypeError(
|
||||||
|
"'%s' is an invalid keyword argument for function %s()."
|
||||||
|
% (next(kwargs.iterkeys()), fun.__name__))
|
||||||
|
|
||||||
|
|
||||||
class RequiredAttributeError(ValueError):
|
class RequiredAttributeError(ValueError):
|
||||||
def __init__(self, message):
|
def __init__(self, message):
|
||||||
super(RequiredAttributeError, self).__init__(message)
|
super(RequiredAttributeError, self).__init__(message)
|
||||||
|
@ -22,9 +22,18 @@
|
|||||||
# along with this program; if not, write to the Free Software Foundation,
|
# along with this program; if not, write to the Free Software Foundation,
|
||||||
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
from external import argparse
|
||||||
import spack
|
import spack
|
||||||
|
import spack.cmd
|
||||||
|
|
||||||
description = "Write out inter-package dependencies in dot graph format"
|
description = "Write out inter-package dependencies in dot graph format"
|
||||||
|
|
||||||
|
def setup_parser(subparser):
|
||||||
|
subparser.add_argument(
|
||||||
|
'specs', nargs=argparse.REMAINDER,
|
||||||
|
help="specs of packages to graph. Default is all packages.")
|
||||||
|
|
||||||
|
|
||||||
def graph(parser, args):
|
def graph(parser, args):
|
||||||
spack.db.graph_dependencies()
|
specs = spack.cmd.parse_specs(args.specs)
|
||||||
|
spack.db.graph_dependencies(*specs)
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
import llnl.util.tty as tty
|
import llnl.util.tty as tty
|
||||||
from llnl.util.filesystem import join_path
|
from llnl.util.filesystem import join_path
|
||||||
from llnl.util.lang import memoized
|
from llnl.util.lang import *
|
||||||
|
|
||||||
import spack.error
|
import spack.error
|
||||||
import spack.spec
|
import spack.spec
|
||||||
@ -214,9 +214,12 @@ def get_class_for_package_name(self, pkg_name):
|
|||||||
return cls
|
return cls
|
||||||
|
|
||||||
|
|
||||||
def graph_dependencies(self, out=sys.stdout):
|
def graph_dependencies(self, *specs, **kwargs):
|
||||||
"""Print out a graph of all the dependencies between package.
|
"""Print out a graph of all the dependencies between package.
|
||||||
Graph is in dot format."""
|
Graph is in dot format."""
|
||||||
|
out = kwargs.pop('out', sys.stdout)
|
||||||
|
check_kwargs(kwargs, self.graph_dependencies)
|
||||||
|
|
||||||
out.write('digraph G {\n')
|
out.write('digraph G {\n')
|
||||||
out.write(' label = "Spack Dependencies"\n')
|
out.write(' label = "Spack Dependencies"\n')
|
||||||
out.write(' labelloc = "b"\n')
|
out.write(' labelloc = "b"\n')
|
||||||
@ -227,8 +230,15 @@ def graph_dependencies(self, out=sys.stdout):
|
|||||||
def quote(string):
|
def quote(string):
|
||||||
return '"%s"' % string
|
return '"%s"' % string
|
||||||
|
|
||||||
|
if not specs:
|
||||||
|
packages = self.all_packages()
|
||||||
|
else:
|
||||||
|
packages = []
|
||||||
|
for spec in specs:
|
||||||
|
packages.extend(s.package for s in spec.normalized().traverse())
|
||||||
|
|
||||||
deps = []
|
deps = []
|
||||||
for pkg in self.all_packages():
|
for pkg in packages:
|
||||||
out.write(' %-30s [label="%s"]\n' % (quote(pkg.name), pkg.name))
|
out.write(' %-30s [label="%s"]\n' % (quote(pkg.name), pkg.name))
|
||||||
|
|
||||||
# Add edges for each depends_on in the package.
|
# Add edges for each depends_on in the package.
|
||||||
|
@ -858,7 +858,7 @@ def normalize(self, **kwargs):
|
|||||||
def normalized(self):
|
def normalized(self):
|
||||||
"""Return a normalized copy of this spec without modifying this spec."""
|
"""Return a normalized copy of this spec without modifying this spec."""
|
||||||
clone = self.copy()
|
clone = self.copy()
|
||||||
clone.normalized()
|
clone.normalize()
|
||||||
return clone
|
return clone
|
||||||
|
|
||||||
|
|
||||||
@ -1289,12 +1289,13 @@ def __str__(self):
|
|||||||
def tree(self, **kwargs):
|
def tree(self, **kwargs):
|
||||||
"""Prints out this spec and its dependencies, tree-formatted
|
"""Prints out this spec and its dependencies, tree-formatted
|
||||||
with indentation."""
|
with indentation."""
|
||||||
color = kwargs.get('color', False)
|
color = kwargs.pop('color', False)
|
||||||
depth = kwargs.get('depth', False)
|
depth = kwargs.pop('depth', False)
|
||||||
showid = kwargs.get('ids', False)
|
showid = kwargs.pop('ids', False)
|
||||||
cover = kwargs.get('cover', 'nodes')
|
cover = kwargs.pop('cover', 'nodes')
|
||||||
indent = kwargs.get('indent', 0)
|
indent = kwargs.pop('indent', 0)
|
||||||
format = kwargs.get('format', '$_$@$%@$+$=')
|
fmt = kwargs.pop('format', '$_$@$%@$+$=')
|
||||||
|
check_kwargs(kwargs, self.tree)
|
||||||
|
|
||||||
out = ""
|
out = ""
|
||||||
cur_id = 0
|
cur_id = 0
|
||||||
@ -1311,7 +1312,7 @@ def tree(self, **kwargs):
|
|||||||
out += (" " * d)
|
out += (" " * d)
|
||||||
if d > 0:
|
if d > 0:
|
||||||
out += "^"
|
out += "^"
|
||||||
out += node.format(format, color=color) + "\n"
|
out += node.format(fmt, color=color) + "\n"
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user