Compare commits

...

1 Commits

Author SHA1 Message Date
Todd Gamblin
f85f50d64e
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 <tgamblin@llnl.gov>
2025-05-21 16:39:58 -07:00
4 changed files with 5 additions and 21 deletions

View File

@ -0,0 +1,4 @@
include:
- path: "${platform}"
optional: true
- path: base

View File

@ -13,8 +13,7 @@
#. ``site``
#. ``user``
And corresponding :ref:`per-platform scopes <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.

View File

@ -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}")