env: spack env destroy is now spack env remove

This commit is contained in:
Todd Gamblin 2018-10-27 22:52:29 -07:00
parent 8b549f664c
commit e62506571f
2 changed files with 28 additions and 25 deletions

View File

@ -30,7 +30,7 @@
'activate',
'deactivate',
'create',
'destroy',
['remove', 'rm'],
['list', 'ls'],
['status', 'st'],
'loads',
@ -210,33 +210,36 @@ def _env_create(name_or_path, init_file=None, dir=False):
#
# env remove
#
def env_destroy_setup_parser(subparser):
"""destroy an existing environment"""
def env_remove_setup_parser(subparser):
"""remove an existing environment"""
subparser.add_argument(
'env', nargs='+', help='environment(s) to destroy')
'env', nargs='+', help='environment(s) to remove')
arguments.add_common_arguments(subparser, ['yes_to_all'])
def env_destroy(args):
if not args.yes_to_all:
answer = tty.get_yes_or_no(
'Really destroy %s %s?' % (
string.plural(len(args.env), 'environment', show_n=False),
string.comma_and(args.env)),
default=False)
if not answer:
tty.die("Will not destroy any environments")
def env_remove(args):
for env_name in args.env:
env = ev.disambiguate(env_name)
if not env:
tty.die('no such environment: %s' % env_name)
if not args.yes_to_all:
answer = tty.get_yes_or_no(
'Really remove %s %s?' % (
string.plural(len(args.env), 'environment', show_n=False),
string.comma_and(args.env)),
default=False)
if not answer:
tty.die("Will not remove any environments")
for env_name in args.env:
env = ev.disambiguate(env_name)
if ev.active and ev.active.path == env.path:
tty.die("Environment %s can't be destroyed while activated.")
tty.die("Environment %s can't be removed while activated.")
env.destroy()
tty.msg("Successfully destroyed environment '%s'" % env)
tty.msg("Successfully removed environment '%s'" % env)
#

View File

@ -46,7 +46,7 @@ def test_env_list():
assert 'baz' in out
def test_env_destroy(capfd):
def test_env_remove(capfd):
env('create', 'foo')
env('create', 'bar')
@ -58,21 +58,21 @@ def test_env_destroy(capfd):
with foo:
with pytest.raises(spack.main.SpackCommandError):
with capfd.disabled():
env('destroy', '-y', 'foo')
env('remove', '-y', 'foo')
assert 'foo' in env('list')
env('destroy', '-y', 'foo')
env('remove', '-y', 'foo')
out = env('list')
assert 'foo' not in out
assert 'bar' in out
env('destroy', '-y', 'bar')
env('remove', '-y', 'bar')
out = env('list')
assert 'foo' not in out
assert 'bar' not in out
def test_destroy_env_dir(capfd):
def test_remove_env_dir(capfd):
env('create', '-d', 'foo')
assert os.path.isdir('foo')
@ -80,9 +80,9 @@ def test_destroy_env_dir(capfd):
with foo:
with pytest.raises(spack.main.SpackCommandError):
with capfd.disabled():
env('destroy', '-y', 'foo')
env('remove', '-y', 'foo')
env('destroy', '-y', './foo')
env('remove', '-y', './foo')
assert not os.path.isdir('foo')
@ -310,7 +310,7 @@ def test_init_with_file_and_remove(tmpdir):
out = env('status', 'test')
assert 'mpileaks' in out
env('destroy', '-y', 'test')
env('remove', '-y', 'test')
out = env('list')
assert 'test' not in out
@ -535,7 +535,7 @@ def test_env_commands_die_with_no_env_arg():
with pytest.raises(SystemExit):
env('create')
with pytest.raises(SystemExit):
env('destroy')
env('remove')
# these have an optional env arg and raise errors via tty.die
with pytest.raises(spack.main.SpackCommandError):