diff --git a/etc/spack/defaults/config.yaml b/etc/spack/defaults/config.yaml index ba8f9879bab..37ec464a8b9 100644 --- a/etc/spack/defaults/config.yaml +++ b/etc/spack/defaults/config.yaml @@ -77,7 +77,7 @@ config: ## Directory where spack managed environments are created and stored - environments_root: $spack/var/spack/environments + # environments_root: $spack/var/spack/environments # Cache directory for miscellaneous files, like the package index. diff --git a/lib/spack/spack/environment/environment.py b/lib/spack/spack/environment/environment.py index 2f89548f8d2..7bf32d8f40c 100644 --- a/lib/spack/spack/environment/environment.py +++ b/lib/spack/spack/environment/environment.py @@ -62,11 +62,8 @@ _active_environment = None -#: path where environments are stored in the spack tree -# circular dependency to use canonicalize_path but we want to ignore an active env anyways -# env_path = spack.config.get(os.path.expandvars(os.path.expanduser("config:environments_root"))) -def env_path(): - return spack.util.path.canonicalize_path(spack.config.get("config:environments_root"), False) +#: default path where environments are stored in the spack tree +env_path = os.path.join(spack.paths.var_path, "environments") #: Name of the input yaml file for an environment @@ -80,6 +77,14 @@ def env_path(): #: Name of the directory where environments store repos, logs, views env_subdir_name = ".spack-env" +def env_root_path(): + """Override default root path if the user specified it""" + config_path = spack.config.get("config:environments_root", default = None) + if config_path: + return config_path + else: + return env_path + def default_manifest_yaml(): """default spack.yaml file to put in new environments""" @@ -208,7 +213,7 @@ def active_environment(): def _root(name): """Non-validating version of root(), to be used internally.""" - return os.path.join(env_path(), name) + return os.path.join(env_root_path(), name) def root(name): @@ -260,10 +265,10 @@ def all_environment_names(): """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()): + if not os.path.exists(env_root_path()): return [] - candidates = sorted(os.listdir(env_path())) + candidates = sorted(os.listdir(env_root_path())) names = [] for candidate in candidates: yaml_path = os.path.join(_root(candidate), manifest_name) @@ -845,7 +850,7 @@ def clear(self, re_read=False): @property def internal(self): """Whether this environment is managed by Spack.""" - return self.path.startswith(env_path()) + return self.path.startswith(env_root_path()) @property def name(self): diff --git a/lib/spack/spack/test/conftest.py b/lib/spack/spack/test/conftest.py index 845abae6454..ed8dc0f9bd4 100644 --- a/lib/spack/spack/test/conftest.py +++ b/lib/spack/spack/test/conftest.py @@ -1493,13 +1493,11 @@ def get_rev(): @pytest.fixture() def mutable_mock_env_path(tmpdir_factory): """Fixture for mocking the internal spack environments directory.""" - saved_path_fun = ev.environment.env_path + saved_path = ev.environment.env_path mock_path = tmpdir_factory.mktemp("mock-env-path") - def mock_fun(): - return str(mock_path) - ev.environment.env_path = mock_fun + ev.environment.env_path = str(mock_path) yield mock_path - ev.environment.env_path = saved_path_fun + ev.environment.env_path = saved_path @pytest.fixture()