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>
This commit is contained in:
parent
6e39efbb9a
commit
2460c4fc28
@ -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:
|
||||
|
@ -8,6 +8,7 @@
|
||||
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
|
||||
|
@ -14,6 +14,7 @@
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user