Support conditional and optional includes#46792
Support conditional and optional includes#46792scheibelp wants to merge 48 commits intospack:developfrom
Conversation
tgamblin
left a comment
There was a problem hiding this comment.
This looks awesome to me.
I think the PR description is not quite specific enough:
If this were part of the site config scope, or added with spack -C, then all Spack commands would run with the config from /path/to/a/config-dir-or-file (e.g. spack config blame).
I think it needs "when on macOS Ventura".
Other than that a few cosmetic requests below.
|
Thanks for this, @scheibelp. I've asked the rest of the team for their comments, but my $0.02: At first glance, this looks great, thank you! My one thought is that a Spack config for a CVMFS area supporting multiple OSes and/or targets could get pretty verbose unless we were able to have evaluable paths (e.g. |
That sounds like a good idea: for this PR in its current form you would need a long list of would allow for a compact include file. |
That is now supported (and tested) - that took less time than I originally assumed. |
|
Requesting a review from @tldahlgren and @becker33 as I think they should give this a glance to see if it introduces any tricky config layering issues. They dealt with these from working on #33768. |
73a1699 to
0e01a4e
Compare
b54925b to
4e5e087
Compare
|
@scheibelp Does this only allow |
|
@greenc-FNAL the plan is to make |
It its current form, you can include any config section you want: an That will also be true when it is updated as Todd mentions. |
4e5e087 to
5254868
Compare
d21a886 to
0b257f1
Compare
30c32bc to
38fa694
Compare
|
Closing since superseded by #48784 . |
…ntries (#48784) Supersedes #46792. Closes #40018. Closes #31026. Closes #2700. There were a number of feature requests for os-specific config. This enables os-specific config without adding a lot of special sub-scopes. Support `include:` as an independent configuration schema, allowing users to include configuration scopes from files or directories. Includes can be: * conditional (similar to definitions in environments), and/or * optional (i.e., the include will be skipped if it does not exist). Includes can be paths or URLs (`ftp`, `https`, `http` or `file`). Paths can be absolute or relative . Environments can include configuration files using the same schema. Remote includes must be checked by `sha256`. Includes can also be recursive, and this modifies the config system accordingly so that we push included configuration scopes on the stack *before* their including scopes, and we remove configuration scopes from the stack when their including scopes are removed. For example, you could have an `include.yaml` file (e.g., under `$HOME/.spack`) to specify global includes: ``` include: - ./enable_debug.yaml - path: https://github.com/spack/spack-configs/blob/main/NREL/configs/mac/config.yaml sha256: 37f982915b03de18cc4e722c42c5267bf04e46b6a6d6e0ef3a67871fcb1d258b ``` Or an environment `spack.yaml`: ``` spack: include: - path: "/path/to/a/config-dir-or-file" when: os == "ventura" - ./path/relative/to/containing/file/that/is/required - path: "/path/with/spack/variables/$os/$target" optional: true - path: https://raw.githubusercontent.com/spack/spack-configs/refs/heads/main/path/to/required/raw/config.yaml sha256: 26e871804a92cd07bb3d611b31b4156ae93d35b6a6d6e0ef3a67871fcb1d258b ``` Updated TODO: - [x] Get existing unit tests to pass with Todd's changes - [x] Resolve new (or old) circular imports - [x] Ensure remote includes (global) work - [x] Ensure remote includes for environments work (note: caches remote files under user cache root) - [x] add sha256 field to include paths, validate, and require for remote includes - [x] add sha256 remote file unit tests - [x] revisit how diamond includes should work - [x] support recursive includes - [x] add recursive include unit tests - [x] update docs and unit test to indicate ordering of recursive includes with conflicting options is deferred to follow-on work --------- Signed-off-by: Todd Gamblin <[email protected]> Co-authored-by: Peter Scheibel <[email protected]> Co-authored-by: Todd Gamblin <[email protected]>
UPDATE: Instead of the original idea of supporting
include:as a subsection ofconfig:, this PR has changed to supportinclude:as an independent schema while retaining the new capabilities of supporting conditional, unconditional, and optional includes. The features are supported throughspack:include:with essentially the same include syntax, i.e.:This PR also supports conditional and optional includes for environment include paths.
TODO
config: include:withinclude:supportspack commands(fish scopes) completion message to note that user's includes need to be left off@greenc-FNAL @tgamblin
This adds an
include:subsection toconfig:. Theinclude:subsection specifies a list of config paths (either directories or single files) that should be added as scopes to the configuration. For example:If this were part of the site config scope, or added with
spack -C, then all Spack commands would run with the config from/path/to/a/config-dir-or-file(e.g.spack config blame) when on Mac Ventura.Inclusion is currently not recursive: if you include another
config.yamlthat itself defines includes, you will not get those includes.This includes support for conditional activation of configs, using
when, which functions likewhen:for spec list definitions (see: https://spack.readthedocs.io/en/latest/environments.html#spec-list-references). Thewhenstring isevaled, so can support something likeos == "ventura" and target == ....Altogether, this is intended as a more general alternative to #40018: you could conditionally activate a config for each os and/or target.