From 290f57c77939c7f2a8f8e651d9b97ff5610b2f9a Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Wed, 3 Nov 2021 15:09:45 +0100 Subject: spack spec: add --reuse argument --- lib/spack/spack/cmd/common/arguments.py | 8 ++++++++ lib/spack/spack/cmd/solve.py | 6 ++---- lib/spack/spack/cmd/spec.py | 21 +++++++++++++-------- lib/spack/spack/spec.py | 14 ++++++++++---- share/spack/spack-completion.bash | 4 ++-- 5 files changed, 35 insertions(+), 18 deletions(-) diff --git a/lib/spack/spack/cmd/common/arguments.py b/lib/spack/spack/cmd/common/arguments.py index 1b173bf584..bea8ccea90 100644 --- a/lib/spack/spack/cmd/common/arguments.py +++ b/lib/spack/spack/cmd/common/arguments.py @@ -320,3 +320,11 @@ the build yourself. Format: %%Y%%m%%d-%%H%%M-[cdash-track]""" default=None, help=cdash_help['buildstamp'] ) + + +@arg +def reuse(): + return Args( + '--reuse', action='store_true', default=False, + help='reuse installed dependencies' + ) diff --git a/lib/spack/spack/cmd/solve.py b/lib/spack/spack/cmd/solve.py index 897eebfa4b..dc1fcf4ced 100644 --- a/lib/spack/spack/cmd/solve.py +++ b/lib/spack/spack/cmd/solve.py @@ -44,7 +44,8 @@ def setup_parser(subparser): # Below are arguments w.r.t. spec display (like spack spec) arguments.add_common_arguments( - subparser, ['long', 'very_long', 'install_status']) + subparser, ['long', 'very_long', 'install_status', 'reuse'] + ) subparser.add_argument( '-y', '--yaml', action='store_const', dest='format', default=None, const='yaml', help='print concrete spec as yaml') @@ -67,9 +68,6 @@ def setup_parser(subparser): subparser.add_argument( '--stats', action='store_true', default=False, help='print out statistics from clingo') - subparser.add_argument( - '--reuse', action='store_true', default=False, - help='reuse installed dependencies') subparser.add_argument( 'specs', nargs=argparse.REMAINDER, help="specs of packages") diff --git a/lib/spack/spack/cmd/spec.py b/lib/spack/spack/cmd/spec.py index 592da60388..7c1375210a 100644 --- a/lib/spack/spack/cmd/spec.py +++ b/lib/spack/spack/cmd/spec.py @@ -28,7 +28,8 @@ for further documentation regarding the spec syntax, see: spack help --spec """ arguments.add_common_arguments( - subparser, ['long', 'very_long', 'install_status']) + subparser, ['long', 'very_long', 'install_status', 'reuse'] + ) subparser.add_argument( '-y', '--yaml', action='store_const', dest='format', default=None, const='yaml', help='print concrete spec as YAML') @@ -64,7 +65,7 @@ def spec(parser, args): name_fmt = '{namespace}.{name}' if args.namespaces else '{name}' fmt = '{@version}{%compiler}{compiler_flags}{variants}{arch=architecture}' install_status_fn = spack.spec.Spec.install_status - kwargs = { + tree_kwargs = { 'cover': args.cover, 'format': name_fmt + fmt, 'hashlen': None if args.very_long else 7, @@ -81,11 +82,15 @@ def spec(parser, args): if not args.specs: tty.die("spack spec requires at least one spec") + concretize_kwargs = { + 'reuse': args.reuse + } + for spec in spack.cmd.parse_specs(args.specs): # With -y, just print YAML to output. if args.format: if spec.name in spack.repo.path or spec.virtual: - spec.concretize() + spec.concretize(**concretize_kwargs) # The user can specify the hash type to use hash_type = getattr(ht, args.hash_type) @@ -98,13 +103,13 @@ def spec(parser, args): continue with tree_context(): - kwargs['hashes'] = False # Always False for input spec + tree_kwargs['hashes'] = False # Always False for input spec print("Input spec") print("--------------------------------") - print(spec.tree(**kwargs)) + print(spec.tree(**tree_kwargs)) - kwargs['hashes'] = args.long or args.very_long + tree_kwargs['hashes'] = args.long or args.very_long print("Concretized") print("--------------------------------") - spec.concretize() - print(spec.tree(**kwargs)) + spec.concretize(**concretize_kwargs) + print(spec.tree(**tree_kwargs)) diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py index 08625eaa82..7268142537 100644 --- a/lib/spack/spack/spec.py +++ b/lib/spack/spack/spec.py @@ -2597,7 +2597,7 @@ class Spec(object): msg += " For each package listed, choose another spec\n" raise SpecDeprecatedError(msg) - def _new_concretize(self, tests=False): + def _new_concretize(self, tests=False, reuse=False): import spack.solver.asp if not self.name: @@ -2607,7 +2607,7 @@ class Spec(object): if self._concrete: return - result = spack.solver.asp.solve([self], tests=tests) + result = spack.solver.asp.solve([self], tests=tests, reuse=reuse) result.raise_if_unsat() # take the best answer @@ -2625,17 +2625,23 @@ class Spec(object): self._dup(concretized) self._mark_concrete() - def concretize(self, tests=False): + def concretize(self, tests=False, reuse=False): """Concretize the current spec. Args: tests (bool or list): if False disregard 'test' dependencies, if a list of names activate them for the packages in the list, if True activate 'test' dependencies for all packages. + reuse (bool): if True try to maximize reuse of already installed + specs, if False don't account for installation status. """ if spack.config.get('config:concretizer') == "clingo": - self._new_concretize(tests) + self._new_concretize(tests, reuse=reuse) else: + if reuse: + msg = ('maximizing reuse of installed specs is not ' + 'possible with the original concretizer') + raise spack.error.SpecError(msg) self._old_concretize(tests) def _mark_root_concrete(self, value=True): diff --git a/share/spack/spack-completion.bash b/share/spack/spack-completion.bash index a36366295f..38589ed3ea 100755 --- a/share/spack/spack-completion.bash +++ b/share/spack/spack-completion.bash @@ -1635,7 +1635,7 @@ _spack_restage() { _spack_solve() { if $list_options then - SPACK_COMPREPLY="-h --help --show --models -l --long -L --very-long -I --install-status -y --yaml -j --json -c --cover -N --namespaces -t --types --timers --stats --reuse" + SPACK_COMPREPLY="-h --help --show --models -l --long -L --very-long -I --install-status --reuse -y --yaml -j --json -c --cover -N --namespaces -t --types --timers --stats" else _all_packages fi @@ -1644,7 +1644,7 @@ _spack_solve() { _spack_spec() { if $list_options then - SPACK_COMPREPLY="-h --help -l --long -L --very-long -I --install-status -y --yaml -j --json -c --cover -N --namespaces --hash-type -t --types" + SPACK_COMPREPLY="-h --help -l --long -L --very-long -I --install-status --reuse -y --yaml -j --json -c --cover -N --namespaces --hash-type -t --types" else _all_packages fi -- cgit v1.2.3-60-g2f50