From 1a379215da4fd26f52ead9b5e4be2d5617f14ab5 Mon Sep 17 00:00:00 2001 From: jgraciahlrs Date: Thu, 8 May 2025 21:23:02 +0200 Subject: [PATCH] Allow usage of config variables and env variables with `include_concrete` (#45871) * Allow usage of spack config vars in concrete env path * Update docs on usage of spack config vars in concrete env path --- lib/spack/docs/environments.rst | 6 ++++-- lib/spack/spack/environment/environment.py | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/spack/docs/environments.rst b/lib/spack/docs/environments.rst index 27f9a772e23..d37bf98d7cd 100644 --- a/lib/spack/docs/environments.rst +++ b/lib/spack/docs/environments.rst @@ -539,7 +539,9 @@ from the command line. You can also include an environment directly in the ``spack.yaml`` file. It involves adding the ``include_concrete`` heading in the yaml followed by the -absolute path to the independent environments. +absolute path to the independent environments. Note, that you may use Spack +config variables such as ``$spack`` or environment variables as long as the +expression expands to an absolute path. .. code-block:: yaml @@ -549,7 +551,7 @@ absolute path to the independent environments. unify: true include_concrete: - /absolute/path/to/environment1 - - /absolute/path/to/environment2 + - $spack/../path/to/environment2 Once the ``spack.yaml`` has been updated you must concretize the environment to diff --git a/lib/spack/spack/environment/environment.py b/lib/spack/spack/environment/environment.py index 95476677986..38c54b0c23d 100644 --- a/lib/spack/spack/environment/environment.py +++ b/lib/spack/spack/environment/environment.py @@ -1049,7 +1049,11 @@ def add_view(name, values): def _process_concrete_includes(self): """Extract and load into memory included concrete spec data.""" - self.included_concrete_envs = self.manifest[TOP_LEVEL_KEY].get(included_concrete_name, []) + _included_concrete_envs = self.manifest[TOP_LEVEL_KEY].get(included_concrete_name, []) + # Expand config and environment variables + self.included_concrete_envs = [ + spack.util.path.canonicalize_path(_env) for _env in _included_concrete_envs + ] if self.included_concrete_envs: if os.path.exists(self.lock_path):