summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorpsakievich <psakiev@sandia.gov>2022-11-14 11:13:30 -0700
committerGitHub <noreply@github.com>2022-11-14 10:13:30 -0800
commit2460c4fc28a8b807fd3f4ca04a10a6c49f496455 (patch)
tree4bd6d1bf66477b2d0bfe0300db9089223d47baa6 /lib
parent6e39efbb9accf888cdb7d7bc4e08eb477c6f93e0 (diff)
downloadspack-2460c4fc28a8b807fd3f4ca04a10a6c49f496455.tar.gz
spack-2460c4fc28a8b807fd3f4ca04a10a6c49f496455.tar.bz2
spack-2460c4fc28a8b807fd3f4ca04a10a6c49f496455.tar.xz
spack-2460c4fc28a8b807fd3f4ca04a10a6c49f496455.zip
Add `$date` option to the list of config variables (#33875)
I'm finding I often want the date in my paths and it would be nice if spack had a config variable for this. Co-authored-by: Tamara Dahlgren <35777542+tldahlgren@users.noreply.github.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/docs/configuration.rst2
-rw-r--r--lib/spack/spack/test/config.py8
-rw-r--r--lib/spack/spack/util/path.py3
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