summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/spack/spack/environment.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py
index bb7a50143d..06791ea2be 100644
--- a/lib/spack/spack/environment.py
+++ b/lib/spack/spack/environment.py
@@ -155,10 +155,15 @@ def config_dict(yaml_data):
def list_environments():
"""List the names of environments that currently exist."""
+ # just return empty if the env path does not exist. A read-only
+ # operation like list should not try to create a directory.
+ if not os.path.exists(env_path):
+ return []
+
candidates = sorted(os.listdir(env_path))
names = []
for candidate in candidates:
- yaml_path = os.path.join(env_path, candidate, env_yaml_name)
+ yaml_path = os.path.join(root(candidate), env_yaml_name)
if valid_env_name(candidate) and os.path.exists(yaml_path):
names.append(candidate)
return names