From 75e37c6db561effad5fd7362c7fe06e985dc979e Mon Sep 17 00:00:00 2001 From: Peter Scheibel Date: Sun, 9 Mar 2025 21:31:56 -0700 Subject: [PATCH] use default modify scope if no scope contains key (#48777) If you use `spack config change` to modify a `require:` section that did not exist before, Spack was inserting the merged configuration into the highest modification scope (which for example would clutter the environment's `spack.yaml` with a bunch of configuration details from the defaults). --- lib/spack/spack/cmd/config.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/spack/spack/cmd/config.py b/lib/spack/spack/cmd/config.py index 90652e94316..a3ba9b6a9dc 100644 --- a/lib/spack/spack/cmd/config.py +++ b/lib/spack/spack/cmd/config.py @@ -350,9 +350,12 @@ def _config_change(config_path, match_spec_str=None): if spack.config.get(key_path, scope=scope): ideal_scope_to_modify = scope break + # If we find our key in a specific scope, that's the one we want + # to modify. Otherwise we use the default write scope. + write_scope = ideal_scope_to_modify or spack.config.default_modify_scope() update_path = f"{key_path}:[{str(spec)}]" - spack.config.add(update_path, scope=ideal_scope_to_modify) + spack.config.add(update_path, scope=write_scope) else: raise ValueError("'config change' can currently only change 'require' sections")