Document new environment variable expansion in projections (#42963)

Adding docs and test for #42917

Co-authored-by: Alec Scott <hi@alecbcs.com>
This commit is contained in:
psakievich 2024-03-04 12:17:08 -07:00 committed by GitHub
parent 913d79238e
commit d6fd9017c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 0 deletions

View file

@ -952,6 +952,17 @@ function, as shown in the example below:
^mpi: "{name}-{version}/{^mpi.name}-{^mpi.version}-{compiler.name}-{compiler.version}"
all: "{name}-{version}/{compiler.name}-{compiler.version}"
Projections also permit environment and spack configuration variable
expansions as shown below:
.. code-block:: yaml
projections:
all: "{name}-{version}/{compiler.name}-{compiler.version}/$date/$SYSTEM_ENV_VARIBLE"
where ``$date`` is the spack configuration variable that will expand with the ``YYYY-MM-DD``
format and ``$SYSTEM_ENV_VARIABLE`` is an environment variable defined in the shell.
The entries in the projections configuration file must all be either
specs or the keyword ``all``. For each spec, the projection used will
be the first non-``all`` entry that the spec satisfies, or ``all`` if

View file

@ -0,0 +1,19 @@
# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
from datetime import date
import spack.projections
import spack.spec
def test_projection_expansion(mock_packages, monkeypatch):
"""Test that env variables and spack config variables are expanded in projections"""
monkeypatch.setenv("FOO_ENV_VAR", "test-string")
projections = {"all": "{name}-{version}/$FOO_ENV_VAR/$date"}
spec = spack.spec.Spec("fake@1.0")
projection = spack.projections.get_projection(projections, spec)
assert "{name}-{version}/test-string/%s" % date.today().strftime("%Y-%m-%d") == projection