Fix bugs in spack dependencies
command (#7435)
- transitive dependencies were not being handled correctly - restructure code to do recursion and mark visited packages properly - add `-V` option to *not* expand virtuals in spack dependencies
This commit is contained in:
parent
a1c8ce82f2
commit
b4a9e37a98
@ -43,7 +43,10 @@ def setup_parser(subparser):
|
|||||||
"instead of possible dependencies of a package.")
|
"instead of possible dependencies of a package.")
|
||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
'-t', '--transitive', action='store_true', default=False,
|
'-t', '--transitive', action='store_true', default=False,
|
||||||
help="Show all transitive dependencies.")
|
help="show all transitive dependencies")
|
||||||
|
subparser.add_argument(
|
||||||
|
'-V', '--no-expand-virtuals', action='store_false', default=True,
|
||||||
|
dest="expand_virtuals", help="do not expand virtual dependencies")
|
||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
'spec', nargs=argparse.REMAINDER, help="spec or package name")
|
'spec', nargs=argparse.REMAINDER, help="spec or package name")
|
||||||
|
|
||||||
@ -76,7 +79,8 @@ def dependencies(parser, args):
|
|||||||
dependencies = set()
|
dependencies = set()
|
||||||
for pkg in packages:
|
for pkg in packages:
|
||||||
dependencies.update(
|
dependencies.update(
|
||||||
set(pkg.possible_dependencies(args.transitive)))
|
set(pkg.possible_dependencies(
|
||||||
|
args.transitive, args.expand_virtuals)))
|
||||||
|
|
||||||
if spec.name in dependencies:
|
if spec.name in dependencies:
|
||||||
dependencies.remove(spec.name)
|
dependencies.remove(spec.name)
|
||||||
|
@ -543,7 +543,9 @@ def q(string):
|
|||||||
|
|
||||||
# Static graph includes anything a package COULD depend on.
|
# Static graph includes anything a package COULD depend on.
|
||||||
if static:
|
if static:
|
||||||
names = set.union(*[s.package.possible_dependencies() for s in specs])
|
names = set.union(*[
|
||||||
|
s.package.possible_dependencies(expand_virtuals=False)
|
||||||
|
for s in specs])
|
||||||
specs = [Spec(name) for name in names]
|
specs = [Spec(name) for name in names]
|
||||||
|
|
||||||
labeled = set()
|
labeled = set()
|
||||||
|
@ -627,31 +627,40 @@ def __init__(self, spec):
|
|||||||
|
|
||||||
super(PackageBase, self).__init__()
|
super(PackageBase, self).__init__()
|
||||||
|
|
||||||
def possible_dependencies(self, transitive=True, visited=None):
|
def possible_dependencies(
|
||||||
"""Return set of possible transitive dependencies of this package.
|
self, transitive=True, expand_virtuals=True, visited=None):
|
||||||
|
"""Return set of possible dependencies of this package.
|
||||||
|
|
||||||
|
Note: the set returned *includes* the package itself.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
transitive (bool): include all transitive dependencies if True,
|
transitive (bool): return all transitive dependencies if True,
|
||||||
only direct dependencies if False.
|
only direct dependencies if False.
|
||||||
|
expand_virtuals (bool): expand virtual dependencies into all
|
||||||
|
possible implementations.
|
||||||
|
visited (set): set of names of dependencies visited so far.
|
||||||
"""
|
"""
|
||||||
if visited is None:
|
if visited is None:
|
||||||
visited = set()
|
visited = set([self.name])
|
||||||
|
|
||||||
visited.add(self.name)
|
for i, name in enumerate(self.dependencies):
|
||||||
for name in self.dependencies:
|
if spack.repo.is_virtual(name):
|
||||||
spec = spack.spec.Spec(name)
|
if expand_virtuals:
|
||||||
|
providers = spack.repo.providers_for(name)
|
||||||
if not spec.virtual:
|
dep_names = [spec.name for spec in providers]
|
||||||
visited.add(name)
|
else:
|
||||||
if transitive:
|
visited.add(name)
|
||||||
pkg = spack.repo.get(name)
|
continue
|
||||||
pkg.possible_dependencies(transitive, visited)
|
|
||||||
else:
|
else:
|
||||||
for provider in spack.repo.providers_for(spec):
|
dep_names = [name]
|
||||||
visited.add(provider.name)
|
|
||||||
|
for dep_name in dep_names:
|
||||||
|
if dep_name not in visited:
|
||||||
|
visited.add(dep_name)
|
||||||
if transitive:
|
if transitive:
|
||||||
pkg = spack.repo.get(provider.name)
|
pkg = spack.repo.get(dep_name)
|
||||||
pkg.possible_dependencies(transitive, visited)
|
pkg.possible_dependencies(
|
||||||
|
transitive, expand_virtuals, visited)
|
||||||
|
|
||||||
return visited
|
return visited
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user