diff --git a/lib/spack/spack/environment/environment.py b/lib/spack/spack/environment/environment.py index 7bf32d8f40c..a2670df27a9 100644 --- a/lib/spack/spack/environment/environment.py +++ b/lib/spack/spack/environment/environment.py @@ -77,13 +77,12 @@ #: 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 + return spack.util.path.canonicalize_path( + spack.config.get("config:environments_root", default=env_path), allow_env=False + ) def default_manifest_yaml(): diff --git a/lib/spack/spack/test/config.py b/lib/spack/spack/test/config.py index e457be3b688..75ed622a9cf 100644 --- a/lib/spack/spack/test/config.py +++ b/lib/spack/spack/test/config.py @@ -1444,9 +1444,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 + 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')) + assert env_dir in ev.root("test") + assert os.path.isdir(os.path.join(env_dir, "test")) diff --git a/lib/spack/spack/util/path.py b/lib/spack/spack/util/path.py index 48b647d02e7..b2e12c18a4e 100644 --- a/lib/spack/spack/util/path.py +++ b/lib/spack/spack/util/path.py @@ -262,7 +262,7 @@ def repl(match): return re.sub(r"(\$\w+\b|\$\{\w+\})", repl, path) -def substitute_path_variables(path, allow_env = True): +def substitute_path_variables(path, allow_env=True): """Substitute config vars, expand environment vars, expand user home.""" path = substitute_config_variables(path, allow_env) path = os.path.expandvars(path) @@ -306,7 +306,7 @@ def add_padding(path, length): return os.path.join(path, padding) -def canonicalize_path(path, allow_env = True): +def canonicalize_path(path, allow_env=True): """Same as substitute_path_variables, but also take absolute path. Arguments: