From f85f50d64eef425ccef739b752953d5703c490a2 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Wed, 21 May 2025 16:29:03 -0700 Subject: [PATCH] configuration: remove platform-specific scopes Spack has historically allowed a platform-specific subdirectory for each configuration scope. e.g., in Spack's own defaults we use this for platform-specific overrides: ``` spack/etc/spack/ packages.yaml spack/etc/spack/linux/ packages.yaml spack/etc/spack/darwin/ packages.yaml ``` This adds specialized `packages.yaml` overrides for linux and darwin. In #48784, we added a much more general facility for an `include:` section in configuration, so you can add your own much more specialized config directories. This PR addresses a couple issues with that, namely: 1. We still hard-code the platform includes in Spack 2. Platform includes are at *higher* precedence than the including scope, while `include:` includes are lower. This makes it impossible for something like: ```yaml include: - include: "${os}" ``` to override the linux subdirectory in a config scope. This PR removes the older platform-specific config scopes in favor of allowing users to add their own such scopes if they need them. So, if you want platform configuration, you can add this to the scope that needs it: ```yaml include: - include: "${platform}" ``` If you want platform to have lower precedence than OS, you can do this: ```yaml include: - include: "${os}" include: - include: "${platform}" ``` And now OS config can override platform. Likewise, you could reverse the list and have platofrm with higher precedence than OS. - [x] remove `_add_platform_scope() from `config` - [x] refactor default config scope to account for new structure - [ ] TBD: docs Signed-off-by: Todd Gamblin --- etc/spack/defaults/{ => base}/packages.yaml | 0 etc/spack/defaults/include.yaml | 4 ++++ lib/spack/spack/config.py | 19 +------------------ lib/spack/spack/main.py | 3 --- 4 files changed, 5 insertions(+), 21 deletions(-) rename etc/spack/defaults/{ => base}/packages.yaml (100%) create mode 100644 etc/spack/defaults/include.yaml diff --git a/etc/spack/defaults/packages.yaml b/etc/spack/defaults/base/packages.yaml similarity index 100% rename from etc/spack/defaults/packages.yaml rename to etc/spack/defaults/base/packages.yaml diff --git a/etc/spack/defaults/include.yaml b/etc/spack/defaults/include.yaml new file mode 100644 index 00000000000..40b7cddcb60 --- /dev/null +++ b/etc/spack/defaults/include.yaml @@ -0,0 +1,4 @@ +include: + - path: "${platform}" + optional: true + - path: base diff --git a/lib/spack/spack/config.py b/lib/spack/spack/config.py index 717dfa0c511..0e06d307da1 100644 --- a/lib/spack/spack/config.py +++ b/lib/spack/spack/config.py @@ -13,8 +13,7 @@ #. ``site`` #. ``user`` -And corresponding :ref:`per-platform scopes `. Important -functions in this module are: +Important functions in this module are: * :func:`~spack.config.Configuration.get_config` * :func:`~spack.config.Configuration.update_config` @@ -819,19 +818,6 @@ def override( assert scope is overrides -def _add_platform_scope( - cfg: Configuration, name: str, path: str, priority: ConfigScopePriority, writable: bool = True -) -> None: - """Add a platform-specific subdirectory for the current platform.""" - import spack.platforms # circular dependency - - platform = spack.platforms.host().name - scope = DirectoryConfigScope( - f"{name}/{platform}", os.path.join(path, platform), writable=writable - ) - cfg.push_scope(scope, priority=priority) - - #: Class for the relevance of an optional path conditioned on a limited #: python code that evaluates to a boolean and or explicit specification #: as optional. @@ -967,9 +953,6 @@ def create_incremental() -> Generator[Configuration, None, None]: # add each scope and its platform-specific directory for name, path in configuration_paths: cfg.push_scope(DirectoryConfigScope(name, path), priority=ConfigScopePriority.CONFIG_FILES) - # Each scope can have per-platform overrides in subdirectories - _add_platform_scope(cfg, name, path, priority=ConfigScopePriority.CONFIG_FILES) - # yield the config incrementally so that each config level's init code can get # data from the one below. This can be tricky, but it enables us to have a # single unified config system. diff --git a/lib/spack/spack/main.py b/lib/spack/spack/main.py index 4a2755209cf..3507e70b85a 100644 --- a/lib/spack/spack/main.py +++ b/lib/spack/spack/main.py @@ -881,9 +881,6 @@ def add_command_line_scopes( spack.config.DirectoryConfigScope(name, path, writable=False), priority=ConfigScopePriority.CUSTOM, ) - spack.config._add_platform_scope( - cfg, name, path, priority=ConfigScopePriority.CUSTOM, writable=False - ) continue else: raise spack.error.ConfigError(f"Invalid configuration scope: {path}")