summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2019-08-03 02:27:51 +0200
committerPeter Scheibel <scheibel1@llnl.gov>2019-08-02 17:27:51 -0700
commit90756d0428055a172f40dcc1cb1893c51b88ee96 (patch)
tree8a5a5d023b2321504b7e592efefb30a45d25b1c0 /lib
parent02901709351d502123d61d4b60e8a55c3232a6e0 (diff)
downloadspack-90756d0428055a172f40dcc1cb1893c51b88ee96.tar.gz
spack-90756d0428055a172f40dcc1cb1893c51b88ee96.tar.bz2
spack-90756d0428055a172f40dcc1cb1893c51b88ee96.tar.xz
spack-90756d0428055a172f40dcc1cb1893c51b88ee96.zip
Refactor UI logic out of Environment.concretize (#12213)
Environment.concretize returns newly-concretized specs rather than printing them; as a result, the _display argument is removed from Environment.concretize (originally only used to avoid printing specs during unit testing). Command logic which invokes Environment.concretize prints these explicitly.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/cmd/concretize.py3
-rw-r--r--lib/spack/spack/cmd/install.py3
-rw-r--r--lib/spack/spack/environment.py39
-rw-r--r--lib/spack/spack/test/cmd/env.py4
4 files changed, 34 insertions, 15 deletions
diff --git a/lib/spack/spack/cmd/concretize.py b/lib/spack/spack/cmd/concretize.py
index 66b7f5ce7f..dd88fe8534 100644
--- a/lib/spack/spack/cmd/concretize.py
+++ b/lib/spack/spack/cmd/concretize.py
@@ -18,5 +18,6 @@ def setup_parser(subparser):
def concretize(parser, args):
env = ev.get_env(args, 'concretize', required=True)
- env.concretize(force=args.force)
+ concretized_specs = env.concretize(force=args.force)
+ ev.display_specs(concretized_specs)
env.write()
diff --git a/lib/spack/spack/cmd/install.py b/lib/spack/spack/cmd/install.py
index 9fd7c5b2d3..b9923c7e1b 100644
--- a/lib/spack/spack/cmd/install.py
+++ b/lib/spack/spack/cmd/install.py
@@ -223,7 +223,8 @@ def install(parser, args, **kwargs):
env = ev.get_env(args, 'install')
if env:
if not args.only_concrete:
- env.concretize()
+ concretized_specs = env.concretize()
+ ev.display_specs(concretized_specs)
env.write()
tty.msg("Installing environment %s" % env.name)
env.install_all(args)
diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py
index 16f745f9e8..a854800601 100644
--- a/lib/spack/spack/environment.py
+++ b/lib/spack/spack/environment.py
@@ -822,7 +822,7 @@ class Environment(object):
del self.concretized_order[i]
del self.specs_by_hash[dag_hash]
- def concretize(self, force=False, _display=True):
+ def concretize(self, force=False):
"""Concretize user_specs in this environment.
Only concretizes specs that haven't been concretized yet unless
@@ -834,6 +834,10 @@ class Environment(object):
Arguments:
force (bool): re-concretize ALL specs, even those that were
already concretized
+
+ Returns:
+ List of specs that have been concretized. Each entry is a tuple of
+ the user spec and the corresponding concretized spec.
"""
if force:
# Clear previously concretized specs
@@ -855,21 +859,15 @@ class Environment(object):
concrete = old_specs_by_hash[h]
self._add_concrete_spec(s, concrete, new=False)
- # concretize any new user specs that we haven't concretized yet
+ # Concretize any new user specs that we haven't concretized yet
+ concretized_specs = []
for uspec, uspec_constraints in zip(
self.user_specs, self.user_specs.specs_as_constraints):
if uspec not in old_concretized_user_specs:
- tty.msg('Concretizing %s' % uspec)
concrete = _concretize_from_constraints(uspec_constraints)
self._add_concrete_spec(uspec, concrete)
-
- if _display:
- # Display concretized spec to the user
- sys.stdout.write(concrete.tree(
- recurse_dependencies=True,
- status_fn=spack.spec.Spec.install_status,
- hashlen=7, hashes=True)
- )
+ concretized_specs.append((uspec, concrete))
+ return concretized_specs
def install(self, user_spec, concrete_spec=None, **install_args):
"""Install a single spec into an environment.
@@ -1300,6 +1298,25 @@ class Environment(object):
activate(self._previous_active)
+def display_specs(concretized_specs):
+ """Displays the list of specs returned by `Environment.concretize()`.
+
+ Args:
+ concretized_specs (list): list of specs returned by
+ `Environment.concretize()`
+ """
+ def _tree_to_display(spec):
+ return spec.tree(
+ recurse_dependencies=True,
+ status_fn=spack.spec.Spec.install_status,
+ hashlen=7, hashes=True)
+
+ for user_spec, concrete_spec in concretized_specs:
+ tty.msg('Concretized {0}'.format(user_spec))
+ sys.stdout.write(_tree_to_display(concrete_spec))
+ print('')
+
+
def _concretize_from_constraints(spec_constraints):
# Accept only valid constraints from list and concretize spec
# Get the named spec even if out of order
diff --git a/lib/spack/spack/test/cmd/env.py b/lib/spack/spack/test/cmd/env.py
index 2e610e6a8f..80b00bab1d 100644
--- a/lib/spack/spack/test/cmd/env.py
+++ b/lib/spack/spack/test/cmd/env.py
@@ -736,7 +736,7 @@ def test_indirect_build_dep():
_env_create('test', with_view=False)
e = ev.read('test')
e.add(x_spec)
- e.concretize(_display=False)
+ e.concretize()
e.write()
e_read = ev.read('test')
@@ -788,7 +788,7 @@ Dependency:
e = ev.read('test')
e.add(y_spec)
e.add(x_spec)
- e.concretize(_display=False)
+ e.concretize()
e.write()
e_read = ev.read('test')