diff options
Diffstat (limited to 'lib/spack/spack/cmd/env.py')
-rw-r--r-- | lib/spack/spack/cmd/env.py | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/lib/spack/spack/cmd/env.py b/lib/spack/spack/cmd/env.py index cf5671aafa..4ca98dcdcc 100644 --- a/lib/spack/spack/cmd/env.py +++ b/lib/spack/spack/cmd/env.py @@ -380,28 +380,35 @@ def env_remove(args): and manifests embedded in repositories should be removed manually. """ read_envs = [] + bad_envs = [] for env_name in args.rm_env: - env = ev.read(env_name) - read_envs.append(env) - - if not args.yes_to_all: - answer = tty.get_yes_or_no( - "Really remove %s %s?" - % ( - string.plural(len(args.rm_env), "environment", show_n=False), - string.comma_and(args.rm_env), - ), - default=False, - ) - if not answer: - tty.die("Will not remove any environments") - - for env in read_envs: - if env.active: - tty.die("Environment %s can't be removed while activated." % env.name) - - env.destroy() - tty.msg("Successfully removed environment '%s'" % env.name) + try: + env = ev.read(env_name) + read_envs.append(env) + except spack.config.ConfigFormatError: + bad_envs.append(env_name) + + if not args.yes_to_all: + environments = string.plural(len(args.rm_env), "environment", show_n=False) + envs = string.comma_and(args.rm_env) + answer = tty.get_yes_or_no(f"Really remove {environments} {envs}?", default=False) + if not answer: + tty.die("Will not remove any environments") + + for env in read_envs: + name = env.name + if env.active: + tty.die(f"Environment {name} can't be removed while activated.") + env.destroy() + tty.msg(f"Successfully removed environment {name}") + + for bad_env_name in bad_envs: + shutil.rmtree( + spack.environment.environment.environment_dir_from_name( + bad_env_name, exists_ok=True + ) + ) + tty.msg(f"Successfully removed environment '{bad_env_name}'") # |