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.
This commit is contained in:
parent
0290170935
commit
90756d0428
4 changed files with 34 additions and 15 deletions
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -822,7 +822,7 @@ def remove(self, query_spec, list_name=user_speclist_name, force=False):
|
|||
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 @@ def concretize(self, force=False, _display=True):
|
|||
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 @@ def concretize(self, force=False, _display=True):
|
|||
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 @@ def __exit__(self, exc_type, exc_val, exc_tb):
|
|||
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
|
||||
|
|
|
@ -736,7 +736,7 @@ def noop(*args):
|
|||
_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 @@ def noop(*args):
|
|||
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')
|
||||
|
|
Loading…
Reference in a new issue