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):
|
def concretize(parser, args):
|
||||||
env = ev.get_env(args, 'concretize', required=True)
|
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()
|
env.write()
|
||||||
|
|
|
@ -223,7 +223,8 @@ def install(parser, args, **kwargs):
|
||||||
env = ev.get_env(args, 'install')
|
env = ev.get_env(args, 'install')
|
||||||
if env:
|
if env:
|
||||||
if not args.only_concrete:
|
if not args.only_concrete:
|
||||||
env.concretize()
|
concretized_specs = env.concretize()
|
||||||
|
ev.display_specs(concretized_specs)
|
||||||
env.write()
|
env.write()
|
||||||
tty.msg("Installing environment %s" % env.name)
|
tty.msg("Installing environment %s" % env.name)
|
||||||
env.install_all(args)
|
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.concretized_order[i]
|
||||||
del self.specs_by_hash[dag_hash]
|
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.
|
"""Concretize user_specs in this environment.
|
||||||
|
|
||||||
Only concretizes specs that haven't been concretized yet unless
|
Only concretizes specs that haven't been concretized yet unless
|
||||||
|
@ -834,6 +834,10 @@ def concretize(self, force=False, _display=True):
|
||||||
Arguments:
|
Arguments:
|
||||||
force (bool): re-concretize ALL specs, even those that were
|
force (bool): re-concretize ALL specs, even those that were
|
||||||
already concretized
|
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:
|
if force:
|
||||||
# Clear previously concretized specs
|
# Clear previously concretized specs
|
||||||
|
@ -855,21 +859,15 @@ def concretize(self, force=False, _display=True):
|
||||||
concrete = old_specs_by_hash[h]
|
concrete = old_specs_by_hash[h]
|
||||||
self._add_concrete_spec(s, concrete, new=False)
|
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(
|
for uspec, uspec_constraints in zip(
|
||||||
self.user_specs, self.user_specs.specs_as_constraints):
|
self.user_specs, self.user_specs.specs_as_constraints):
|
||||||
if uspec not in old_concretized_user_specs:
|
if uspec not in old_concretized_user_specs:
|
||||||
tty.msg('Concretizing %s' % uspec)
|
|
||||||
concrete = _concretize_from_constraints(uspec_constraints)
|
concrete = _concretize_from_constraints(uspec_constraints)
|
||||||
self._add_concrete_spec(uspec, concrete)
|
self._add_concrete_spec(uspec, concrete)
|
||||||
|
concretized_specs.append((uspec, concrete))
|
||||||
if _display:
|
return concretized_specs
|
||||||
# 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)
|
|
||||||
)
|
|
||||||
|
|
||||||
def install(self, user_spec, concrete_spec=None, **install_args):
|
def install(self, user_spec, concrete_spec=None, **install_args):
|
||||||
"""Install a single spec into an environment.
|
"""Install a single spec into an environment.
|
||||||
|
@ -1300,6 +1298,25 @@ def __exit__(self, exc_type, exc_val, exc_tb):
|
||||||
activate(self._previous_active)
|
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):
|
def _concretize_from_constraints(spec_constraints):
|
||||||
# Accept only valid constraints from list and concretize spec
|
# Accept only valid constraints from list and concretize spec
|
||||||
# Get the named spec even if out of order
|
# Get the named spec even if out of order
|
||||||
|
|
|
@ -736,7 +736,7 @@ def noop(*args):
|
||||||
_env_create('test', with_view=False)
|
_env_create('test', with_view=False)
|
||||||
e = ev.read('test')
|
e = ev.read('test')
|
||||||
e.add(x_spec)
|
e.add(x_spec)
|
||||||
e.concretize(_display=False)
|
e.concretize()
|
||||||
e.write()
|
e.write()
|
||||||
|
|
||||||
e_read = ev.read('test')
|
e_read = ev.read('test')
|
||||||
|
@ -788,7 +788,7 @@ def noop(*args):
|
||||||
e = ev.read('test')
|
e = ev.read('test')
|
||||||
e.add(y_spec)
|
e.add(y_spec)
|
||||||
e.add(x_spec)
|
e.add(x_spec)
|
||||||
e.concretize(_display=False)
|
e.concretize()
|
||||||
e.write()
|
e.write()
|
||||||
|
|
||||||
e_read = ev.read('test')
|
e_read = ev.read('test')
|
||||||
|
|
Loading…
Reference in a new issue