From 9b6a109c7e6f73f063aa2702b8629465a3d85a3c Mon Sep 17 00:00:00 2001 From: psakiev Date: Wed, 7 Dec 2022 22:24:18 -0700 Subject: [PATCH] Remove constraint on environments_root creation --- lib/spack/spack/environment/environment.py | 12 +---------- lib/spack/spack/test/cmd/env.py | 23 ---------------------- lib/spack/spack/test/config.py | 14 ++++++++++--- 3 files changed, 12 insertions(+), 37 deletions(-) diff --git a/lib/spack/spack/environment/environment.py b/lib/spack/spack/environment/environment.py index 34dc997b7b3..2d66c72b9e3 100644 --- a/lib/spack/spack/environment/environment.py +++ b/lib/spack/spack/environment/environment.py @@ -261,17 +261,7 @@ def read(name): def create(name, init_file=None, with_view=None, keep_relative=False): """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 - # we need to be a bit more pedantic and not create automatically since this is a user - # configurable path that can be subject to user input errors - if env_root_path() == default_env_path: - # we can just create the default path since it is internal to spack - os.mkdir(default_env_path) - else: - 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()) - ) + os.mkdir(env_root_path()) validate_env_name(name) if exists(name): raise SpackEnvironmentError("'%s': environment already exists" % name) diff --git a/lib/spack/spack/test/cmd/env.py b/lib/spack/spack/test/cmd/env.py index 2e4f30b68ec..258d125c6f6 100644 --- a/lib/spack/spack/test/cmd/env.py +++ b/lib/spack/spack/test/cmd/env.py @@ -3183,17 +3183,6 @@ def test_env_include_packages_url( assert "openmpi" in cfg["all"]["providers"]["mpi"] -def test_config_file_read_invalid_yaml(tmpdir, mutable_empty_config): - """Test reading a configuration file with invalid (unparseable) YAML - raises a ConfigFileError.""" - filename = tmpdir.join("test.yaml") - with open(filename, "w") as f: - f.write("spack:\nview") - - with pytest.raises(spack.config.ConfigFileError, match="parsing yaml"): - spack.config.read_config_file(filename) - - def test_environment_created_in_users_location(mutable_config, tmpdir): """Test that an environment is created in a location based on the config""" spack.config.set("config:environments_root", str(tmpdir.join("envs"))) @@ -3202,21 +3191,9 @@ def test_environment_created_in_users_location(mutable_config, tmpdir): assert tmpdir.strpath in env_dir assert not os.path.isdir(env_dir) - os.makedirs(env_dir) env("create", "test") out = env("list") assert "test" in out assert env_dir in ev.root("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") diff --git a/lib/spack/spack/test/config.py b/lib/spack/spack/test/config.py index 7988f261bef..efa6c1d2b89 100644 --- a/lib/spack/spack/test/config.py +++ b/lib/spack/spack/test/config.py @@ -30,9 +30,6 @@ import spack.schema.repos import spack.util.path as spack_path import spack.util.spack_yaml as syaml -from spack.main import SpackCommand - -env = SpackCommand("env") # sample config data config_low = { @@ -1451,3 +1448,14 @@ def test_config_file_read_perms_failure(tmpdir, mutable_empty_config): with pytest.raises(spack.config.ConfigFileError, match="not readable"): spack.config.read_config_file(filename) + + +def test_config_file_read_invalid_yaml(tmpdir, mutable_empty_config): + """Test reading a configuration file with invalid (unparseable) YAML + raises a ConfigFileError.""" + filename = tmpdir.join("test.yaml") + with open(filename, "w") as f: + f.write("spack:\nview") + + with pytest.raises(spack.config.ConfigFileError, match="parsing yaml"): + spack.config.read_config_file(filename)