diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/docs/configuration.rst | 2 | ||||
-rw-r--r-- | lib/spack/spack/test/config.py | 8 | ||||
-rw-r--r-- | lib/spack/spack/util/path.py | 3 |
3 files changed, 13 insertions, 0 deletions
diff --git a/lib/spack/docs/configuration.rst b/lib/spack/docs/configuration.rst index 26df115567..6bf48beb68 100644 --- a/lib/spack/docs/configuration.rst +++ b/lib/spack/docs/configuration.rst @@ -416,6 +416,8 @@ Spack understands several special variables. These are: ArchSpec. E.g. ``skylake`` or ``neoverse-n1``. * ``$target_family``. The target family for the current host, as detected by ArchSpec. E.g. ``x86_64`` or ``aarch64``. +* ``$date``: the current date in the format YYYY-MM-DD + Note that, as with shell variables, you can write these as ``$varname`` or with braces to distinguish the variable from surrounding characters: diff --git a/lib/spack/spack/test/config.py b/lib/spack/spack/test/config.py index 03f358acd1..f8b1e44547 100644 --- a/lib/spack/spack/test/config.py +++ b/lib/spack/spack/test/config.py @@ -8,6 +8,7 @@ import getpass import os import sys import tempfile +from datetime import date import pytest from six import StringIO @@ -443,6 +444,13 @@ def test_substitute_tempdir(mock_low_high_config): ) +def test_substitute_date(mock_low_high_config): + test_path = os.path.join("hello", "world", "on", "$date") + new_path = spack_path.canonicalize_path(test_path) + assert "$date" in test_path + assert date.today().strftime("%Y-%m-%d") in new_path + + PAD_STRING = spack.util.path.SPACK_PATH_PADDING_CHARS MAX_PATH_LEN = spack.util.path.get_system_path_max() MAX_PADDED_LEN = MAX_PATH_LEN - spack.util.path.SPACK_MAX_INSTALL_PATH_LENGTH diff --git a/lib/spack/spack/util/path.py b/lib/spack/spack/util/path.py index d18d719c8f..49794429d3 100644 --- a/lib/spack/spack/util/path.py +++ b/lib/spack/spack/util/path.py @@ -14,6 +14,7 @@ import re import subprocess import sys import tempfile +from datetime import date from six.moves.urllib.parse import urlparse @@ -70,6 +71,7 @@ def replacements(): "os": str(arch.os), "target": str(arch.target), "target_family": str(arch.target.microarchitecture.family), + "date": date.today().strftime("%Y-%m-%d"), } @@ -285,6 +287,7 @@ def substitute_config_variables(path): - $operating_system The OS of the current system - $target The ISA target detected for the system - $target_family The family of the target detected for the system + - $date The current date (YYYY-MM-DD) These are substituted case-insensitively into the path, and users can use either ``$var`` or ``${var}`` syntax for the variables. $env is only |