environment: ignore invalid files names in var/spack/environments (#10198)
This commit is contained in:
parent
d9da7c98a2
commit
39b23d277b
@ -232,10 +232,15 @@ def get_env(args, cmd_name, required=False):
|
|||||||
' spack -e ENV %s ...' % cmd_name)
|
' spack -e ENV %s ...' % cmd_name)
|
||||||
|
|
||||||
|
|
||||||
|
def _root(name):
|
||||||
|
"""Non-validating version of root(), to be used internally."""
|
||||||
|
return os.path.join(env_path, name)
|
||||||
|
|
||||||
|
|
||||||
def root(name):
|
def root(name):
|
||||||
"""Get the root directory for an environment by name."""
|
"""Get the root directory for an environment by name."""
|
||||||
validate_env_name(name)
|
validate_env_name(name)
|
||||||
return os.path.join(env_path, name)
|
return _root(name)
|
||||||
|
|
||||||
|
|
||||||
def exists(name):
|
def exists(name):
|
||||||
@ -288,7 +293,7 @@ def all_environment_names():
|
|||||||
candidates = sorted(os.listdir(env_path))
|
candidates = sorted(os.listdir(env_path))
|
||||||
names = []
|
names = []
|
||||||
for candidate in candidates:
|
for candidate in candidates:
|
||||||
yaml_path = os.path.join(root(candidate), manifest_name)
|
yaml_path = os.path.join(_root(candidate), manifest_name)
|
||||||
if valid_env_name(candidate) and os.path.exists(yaml_path):
|
if valid_env_name(candidate) and os.path.exists(yaml_path):
|
||||||
names.append(candidate)
|
names.append(candidate)
|
||||||
return names
|
return names
|
||||||
|
@ -37,7 +37,7 @@ def test_add():
|
|||||||
assert Spec('mpileaks') in e.user_specs
|
assert Spec('mpileaks') in e.user_specs
|
||||||
|
|
||||||
|
|
||||||
def test_env_list():
|
def test_env_list(mutable_mock_env_path):
|
||||||
env('create', 'foo')
|
env('create', 'foo')
|
||||||
env('create', 'bar')
|
env('create', 'bar')
|
||||||
env('create', 'baz')
|
env('create', 'baz')
|
||||||
@ -48,6 +48,15 @@ def test_env_list():
|
|||||||
assert 'bar' in out
|
assert 'bar' in out
|
||||||
assert 'baz' in out
|
assert 'baz' in out
|
||||||
|
|
||||||
|
# make sure `spack env list` skips invalid things in var/spack/env
|
||||||
|
mutable_mock_env_path.join('.DS_Store').ensure(file=True)
|
||||||
|
out = env('list')
|
||||||
|
|
||||||
|
assert 'foo' in out
|
||||||
|
assert 'bar' in out
|
||||||
|
assert 'baz' in out
|
||||||
|
assert '.DS_Store' not in out
|
||||||
|
|
||||||
|
|
||||||
def test_env_remove(capfd):
|
def test_env_remove(capfd):
|
||||||
env('create', 'foo')
|
env('create', 'foo')
|
||||||
|
@ -703,8 +703,9 @@ def get_rev():
|
|||||||
def mutable_mock_env_path(tmpdir_factory):
|
def mutable_mock_env_path(tmpdir_factory):
|
||||||
"""Fixture for mocking the internal spack environments directory."""
|
"""Fixture for mocking the internal spack environments directory."""
|
||||||
saved_path = spack.environment.env_path
|
saved_path = spack.environment.env_path
|
||||||
spack.environment.env_path = str(tmpdir_factory.mktemp('mock-env-path'))
|
mock_path = tmpdir_factory.mktemp('mock-env-path')
|
||||||
yield spack.environment.env_path
|
spack.environment.env_path = str(mock_path)
|
||||||
|
yield mock_path
|
||||||
spack.environment.env_path = saved_path
|
spack.environment.env_path = saved_path
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user