Skip to content

Configuration scopes: fix severe ordering issue when -C and -e are used together#51461

Merged
tgamblin merged 4 commits intospack:developfrom
alalazo:bugfix/big-scope-issue-command-line
Oct 28, 2025
Merged

Configuration scopes: fix severe ordering issue when -C and -e are used together#51461
tgamblin merged 4 commits intospack:developfrom
alalazo:bugfix/big-scope-issue-command-line

Conversation

@alalazo
Copy link
Copy Markdown
Member

@alalazo alalazo commented Oct 22, 2025

Fixes #51459.

#50853 attempted to make configuration (envs and config scopes) specified on the CLI merge in CLI order, but did not quite succeed. Environments, when loaded, would still appear out of order in the scope stack. This fixes the issues and establishes, after much discussion, the ordering we want for configuration scopes specified on the CLI:

  1. Ordering of scopes will be enforced within the same option on the CLI, e.g. bar is higher precedence in -C foo -C bar;
  2. Ordering across options is counterintuitive, and the -e option (or the active environment via SPACK_ENV) should always be lower priority than -C or -c options; and
  3. -C options have lower priority than -c.

Environments are now added using ConfigScopePriority.ENVIRONMENT in all cases. Since they are the only entity using that scope priority, it's safe to activate and deactivate them.

Documentation has been updated to reflect that the CUSTOM scopes have higher priority than ENVIRONMENT.

@alalazo alalazo requested a review from tgamblin October 22, 2025 17:22
@alalazo alalazo added the bugfix Something wasn't working, here's a fix label Oct 22, 2025
Environments are added using ConfigScopePriority.ENVIRONMENT
in all cases. Since they are the only kind of scope using that
priority, it's safe to activate and deactivate environments.

Documentation has been updated to reflect that the CUSTOM scopes
have higher priority than ENVIRONMENT.

Signed-off-by: Massimiliano Culpo <[email protected]>
@alalazo alalazo force-pushed the bugfix/big-scope-issue-command-line branch from 0e65a80 to 2c61f14 Compare October 22, 2025 18:47
Priority is not needed, it's always ConfigScopePriority.ENVIRONMENT

Signed-off-by: Massimiliano Culpo <[email protected]>
becker33
becker33 previously approved these changes Oct 22, 2025
Signed-off-by: Massimiliano Culpo <[email protected]>
Signed-off-by: Massimiliano Culpo <[email protected]>
alalazo added a commit to alalazo/spack-packages that referenced this pull request Oct 22, 2025
Signed-off-by: Massimiliano Culpo <[email protected]>
@alalazo

This comment was marked as outdated.

@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Oct 23, 2025

For reference, if we had to keep the positional behavior, the solution would be to organize priorities as:

...
LOW_PRIORITY_CUSTOM
ENVIRONMENT
HIGH_PRIORITY_CUSTOM
...

and switch from LOW to HIGH based on where we find _ENV. My impression though is that people don't expect that spack -e ... behaves differently from spack activate ....

@albestro
Copy link
Copy Markdown
Contributor

albestro commented Oct 24, 2025

Just quickly tried with my setup and now it looks consistent both the output of config get repos and what gets concretized. Thanks also for fixing the documentation!

@tgamblin

This comment was marked as outdated.

@alalazo alalazo changed the title Configuration scopes: fix severe ordering issue Configuration scopes: fix severe ordering issue when -C and -E are used together Oct 24, 2025
@alalazo alalazo changed the title Configuration scopes: fix severe ordering issue when -C and -E are used together Configuration scopes: fix severe ordering issue when -C and -e are used together Oct 24, 2025
@tgamblin

This comment was marked as outdated.

@alalazo
Copy link
Copy Markdown
Member Author

alalazo commented Oct 24, 2025

@tgamblin Is there a reason why -C, -D and -e in #50853 are layered according to the cli order, while -c is always higher priority? If we use cli order, shouldn't we use it for every flag dealing with configuration?

(Basically, I'm wondering if in the PR preserving the original intention of #50853 I should also make -c depending on the cli order)

@tgamblin
Copy link
Copy Markdown
Member

After further discussion at the meeting today, I was overruled (which is fine! 😄) . We decided that:

  1. Ordering within the same option is fine, e.g. -C foo -C bar
  2. Ordering across options is counterintuitive, and -e is more like, say, -isystem, which is not ordered with and is always lower priority than -I. -e should always be lower priority than -C.
  3. The active environment (-e, -D, or SPACK_ENVviaspack activate) is lower than -Cand-c`
  4. -C should be lower than -c

I think the ordering here makes sense even if the CLI order doesn't support ordering across args. And if you want an env to override configuration, you can still supply it with -C to have it ordered with other -C arguments.

So we can close the other PR and go with this one as-is. Thanks to @alalazo, @becker33, and @scheibelp for their input on this.

@tgamblin tgamblin added this to the v1.1.0 milestone Oct 27, 2025
@tgamblin tgamblin merged commit c585c6f into spack:develop Oct 28, 2025
32 of 33 checks passed
@tgamblin tgamblin added v1.0.3 PRs to backport for v1.0.3 and removed don't-merge-yet labels Oct 28, 2025
@alalazo alalazo deleted the bugfix/big-scope-issue-command-line branch October 28, 2025 17:39
kshea21 pushed a commit to kshea21/spack that referenced this pull request Nov 4, 2025
…e used together (spack#51461)

Fixes spack#51459.

spack#50853 attempted to make configuration (envs and config scopes) specified on the CLI
merge in CLI order, but did not quite succeed.  Environments, when loaded, would still
appear out of order in the scope stack. This fixes the issues and establishes, after much
discussion, the ordering we want for configuration scopes specified on the CLI:

1. Ordering of scopes will be enforced *within* the same option on the CLI, e.g. bar is higher precedence in `-C foo -C bar`;
2. Ordering *across* options is counterintuitive, and the `-e` option (or the active environment via `SPACK_ENV`) should always be lower priority than `-C` or `-c` options; and
4. `-C` options have lower priority than `-c`.

Environments are now added using `ConfigScopePriority.ENVIRONMENT` in all cases.
Since they are the only entity using that scope priority, it's safe to activate and deactivate them.

Documentation has been updated to reflect that the CUSTOM scopes have higher priority
than ENVIRONMENT.

---------

Signed-off-by: Massimiliano Culpo <[email protected]>
@becker33 becker33 mentioned this pull request Jan 10, 2026
@becker33
Copy link
Copy Markdown
Member

This PR does not apply cleanly to releases/v1.0 and will be dropped from v1.0.3

@becker33 becker33 removed the v1.0.3 PRs to backport for v1.0.3 label Jan 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Something wasn't working, here's a fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Severe issues with config scopes when -C and -e are used together

4 participants