Add spack short version in config variables (#47016)

This commit is contained in:
Jordan Galby 2024-10-25 07:34:59 +02:00 committed by GitHub
parent 2912d4a661
commit f13d998d21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 35 additions and 14 deletions

View File

@ -511,6 +511,7 @@ Spack understands over a dozen special variables. These are:
* ``$target_family``. The target family for the current host, as * ``$target_family``. The target family for the current host, as
detected by ArchSpec. E.g. ``x86_64`` or ``aarch64``. detected by ArchSpec. E.g. ``x86_64`` or ``aarch64``.
* ``$date``: the current date in the format YYYY-MM-DD * ``$date``: the current date in the format YYYY-MM-DD
* ``$spack_short_version``: the Spack version truncated to the first components.
Note that, as with shell variables, you can write these as ``$varname`` Note that, as with shell variables, you can write these as ``$varname``

View File

@ -69,4 +69,15 @@ def get_version() -> str:
return spack_version return spack_version
__all__ = ["spack_version_info", "spack_version", "get_version", "get_spack_commit"] def get_short_version() -> str:
"""Short Spack version."""
return f"{spack_version_info[0]}.{spack_version_info[1]}"
__all__ = [
"spack_version_info",
"spack_version",
"get_version",
"get_spack_commit",
"get_short_version",
]

View File

@ -472,6 +472,13 @@ def test_substitute_date(mock_low_high_config):
assert date.today().strftime("%Y-%m-%d") in new_path assert date.today().strftime("%Y-%m-%d") in new_path
def test_substitute_spack_version():
version = spack.spack_version_info
assert spack_path.canonicalize_path(
"spack$spack_short_version/test"
) == spack_path.canonicalize_path(f"spack{version[0]}.{version[1]}/test")
PAD_STRING = spack_path.SPACK_PATH_PADDING_CHARS PAD_STRING = spack_path.SPACK_PATH_PADDING_CHARS
MAX_PATH_LEN = spack_path.get_system_path_max() MAX_PATH_LEN = spack_path.get_system_path_max()
MAX_PADDED_LEN = MAX_PATH_LEN - spack_path.SPACK_MAX_INSTALL_PATH_LENGTH MAX_PADDED_LEN = MAX_PATH_LEN - spack_path.SPACK_MAX_INSTALL_PATH_LENGTH

View File

@ -74,6 +74,7 @@ def replacements():
"target_family": lambda: arch.target.family, "target_family": lambda: arch.target.family,
"date": lambda: date.today().strftime("%Y-%m-%d"), "date": lambda: date.today().strftime("%Y-%m-%d"),
"env": lambda: ev.active_environment().path if ev.active_environment() else NOMATCH, "env": lambda: ev.active_environment().path if ev.active_environment() else NOMATCH,
"spack_short_version": lambda: spack.get_short_version(),
} }
@ -154,19 +155,20 @@ def substitute_config_variables(path):
Spack allows paths in configs to have some placeholders, as follows: Spack allows paths in configs to have some placeholders, as follows:
- $env The active Spack environment. - $env The active Spack environment.
- $spack The Spack instance's prefix - $spack The Spack instance's prefix
- $tempdir Default temporary directory returned by tempfile.gettempdir() - $tempdir Default temporary directory returned by tempfile.gettempdir()
- $user The current user's username - $user The current user's username
- $user_cache_path The user cache directory (~/.spack, unless overridden) - $user_cache_path The user cache directory (~/.spack, unless overridden)
- $architecture The spack architecture triple for the current system - $architecture The spack architecture triple for the current system
- $arch The spack architecture triple for the current system - $arch The spack architecture triple for the current system
- $platform The spack platform for the current system - $platform The spack platform for the current system
- $os The OS of the current system - $os The OS of the current system
- $operating_system The OS of the current system - $operating_system The OS of the current system
- $target The ISA target detected for the system - $target The ISA target detected for the system
- $target_family The family of the target detected for the system - $target_family The family of the target detected for the system
- $date The current date (YYYY-MM-DD) - $date The current date (YYYY-MM-DD)
- $spack_short_version The spack short version
These are substituted case-insensitively into the path, and users can These are substituted case-insensitively into the path, and users can
use either ``$var`` or ``${var}`` syntax for the variables. $env is only use either ``$var`` or ``${var}`` syntax for the variables. $env is only