Add check that env_root dir exists
This commit is contained in:
parent
9ecdafd8de
commit
076d60ce35
@ -248,6 +248,12 @@ def read(name):
|
|||||||
|
|
||||||
def create(name, init_file=None, with_view=None, keep_relative=False):
|
def create(name, init_file=None, with_view=None, keep_relative=False):
|
||||||
"""Create a named environment in Spack."""
|
"""Create a named environment in Spack."""
|
||||||
|
if not os.path.isdir(env_root_path()):
|
||||||
|
# double check that the root path exists before we check the full environment name
|
||||||
|
raise SpackEnvironmentError(
|
||||||
|
"The environments_root '{er}' does not exist. Please create the directory or provide "
|
||||||
|
"a valid path in the config.yaml".format(er=env_root_path())
|
||||||
|
)
|
||||||
validate_env_name(name)
|
validate_env_name(name)
|
||||||
if exists(name):
|
if exists(name):
|
||||||
raise SpackEnvironmentError("'%s': environment already exists" % name)
|
raise SpackEnvironmentError("'%s': environment already exists" % name)
|
||||||
|
@ -1441,12 +1441,25 @@ def test_environment_created_in_users_location(mutable_config, tmpdir):
|
|||||||
"""Test that an environment is created in a location based on the config"""
|
"""Test that an environment is created in a location based on the config"""
|
||||||
spack.config.set("config:environments_root", str(tmpdir.join("envs")))
|
spack.config.set("config:environments_root", str(tmpdir.join("envs")))
|
||||||
env_dir = spack.config.get("config:environments_root")
|
env_dir = spack.config.get("config:environments_root")
|
||||||
|
|
||||||
assert tmpdir.strpath in env_dir
|
assert tmpdir.strpath in env_dir
|
||||||
assert not os.path.isdir(env_dir)
|
assert not os.path.isdir(env_dir)
|
||||||
|
|
||||||
os.makedirs(env_dir)
|
os.makedirs(env_dir)
|
||||||
env("create", "test")
|
env("create", "test")
|
||||||
out = env("list")
|
out = env("list")
|
||||||
assert "test" in out
|
|
||||||
|
|
||||||
|
assert "test" in out
|
||||||
assert env_dir in ev.root("test")
|
assert env_dir in ev.root("test")
|
||||||
assert os.path.isdir(os.path.join(env_dir, "test"))
|
assert os.path.isdir(os.path.join(env_dir, "test"))
|
||||||
|
|
||||||
|
|
||||||
|
def test_environment_errors_if_root_missing(mutable_config, tmpdir):
|
||||||
|
spack.config.set("config:environments_root", str(tmpdir.join("envs")))
|
||||||
|
env_dir = spack.config.get("config:environments_root")
|
||||||
|
|
||||||
|
assert tmpdir.strpath in env_dir
|
||||||
|
assert not os.path.isdir(env_dir)
|
||||||
|
|
||||||
|
with pytest.raises(ev.SpackEnvironmentError, match=env_dir):
|
||||||
|
env("create", "test")
|
||||||
|
Loading…
Reference in New Issue
Block a user