Skip to content

Injection of Modules over Checks#295

Merged
CodeGat merged 42 commits intodev-v6from
169-inject-projections
Jul 24, 2025
Merged

Injection of Modules over Checks#295
CodeGat merged 42 commits intodev-v6from
169-inject-projections

Conversation

@CodeGat
Copy link
Copy Markdown
Member

@CodeGat CodeGat commented Jul 9, 2025

Closes #169
References #276

Background

Having to update versions of packages in multiple places (spack.packages.*.require[0] and spack.modules.tcl.default.projections mostly) has long been a source of errors and annoyance for users.

Rather than checking user manifests and reporting errors, we will now inject the relevant projections and includes into the manifest, and not override existing user projections.

As a little bonus, I've also added a module version of the prerelease modifications that are done in CD, too, so it's independently testable.

The PR

  • Add modules injection module
  • Add requirements for injection modules
  • Add tests for injection projection module, and inputs/requirements
  • Add prerelease injection module
  • Add tests for prerelease injection module
  • deploy-2-start: Run injection.modules and injection.prerelease modules
  • deploy-1-setup: Remove projection checks

Testing

Python Unit Tests

I've added tests for all the important functions in the scripts.spack_manifest.injection.modules and scripts.spack_manifest.injection.prerelease scripts.

These can be invoked with python3 -m pytest to run the full suite of build-cd tests, or python3 -m pytest tests/scripts/spack_manifest for just the new ones.

Local Module Runthrough

Can be done via the following commands. They will be most representative if the projections section is removed, or using your own manifests.

# For testing projection injection into the manifest
python3 -m scripts.spack_manifest.injection.modules --manifest tests/scripts/spack_manifest/injection/inputs/spack.yaml --root-spec access-om2 --packages "mom5 cice5 oasis3-mct libaccessom2"`

# For testing prerelease modifications to the manifest
python3 -m scripts.spack_manifest.injection.prerelease --manifest tests/scripts/spack_manifest/injection/inputs/prerelease.spack.yaml --root-spec access-om2 --version pr12-12

E2E Workflow Tests

For E2E tests, I used an ephemeral branch 169-inject-projections_TEST that used the same refs for all intra-pipeline workflow calls, and tested in on ACCESS-TEST. See ACCESS-NRI/ACCESS-TEST#48.

Inject Projections As Prerelease

In this run, you can see the original manifest both after projections are injected (done both in Prerelease and Release) and then after prerelease modifications are made. The injections are also visible in the artifacts generated by the run, see at the bottom of the summary in the metadata artifact - https://github.com/ACCESS-NRI/ACCESS-TEST/actions/runs/16161252034?pr=48

Inject Projections Where They Already Exist

I also tested injecting projections where they were already defined, and it succeeded - see ACCESS-NRI/ACCESS-ESM1.5#38. This could be for the case where users haven't got around to deleting the projections section.

@CodeGat CodeGat added type:enhancement Improvements to existing features priority:high version:MINOR Doesn't require update to Model Deployment Repositories for:v5 Applies to `v5` labels Jul 9, 2025
@CodeGat CodeGat self-assigned this Jul 9, 2025
@github-project-automation github-project-automation bot moved this to New Issues 🌅 in Model Release Jul 9, 2025
@aidanheerdegen
Copy link
Copy Markdown
Member

In the test run the pre-release injection results in the following change to projections:

         projections:
-          access-test: '{name}/2025.06.001'
+          access-test: '{name}/pr48-7'
           access-test-component: '{name}/main-{hash:7}'

So only the main spec is modified. Is that how we're currently doing it? Do we not get module namespace collisions because the components have their spack hash included, so if they're the same then it's all cool? What about when we delete the environment, do the module files get cleaned up too?

I'm just wondering if we're doing this, maybe we should add the PR namespace to the component as well, e.g.

access-test-component: '{name}/pr48-7/main-{hash:7}'

Then we could cleanly remove all module files within the pr48-* directories.

@CodeGat
Copy link
Copy Markdown
Member Author

CodeGat commented Jul 9, 2025

Yep, that's how we're currently doing it. And yeah, we don't get collisions because of the spack hash.

When we delete the environment, the modulefiles are not cleaned up, unfortunately. See #155 - still finding a way to clean them up. I've tried a bunch of spacks ways to remove the modulefiles (spack module tcl rm, etc) but it seems to mess with existing modulefiles as well. Maybe doing a spack -e ENV module tcl rm?

And yes it could be good to put the PR namespace into the components - I'll investigate that. If we can do an environment-aware module tcl rm we may not need to, though.

@aidanheerdegen
Copy link
Copy Markdown
Member

And yes it could be good to put the PR namespace into the components - I'll investigate that.

👍

If we can do an environment-aware module tcl rm we may not need to, though.

True. As long as spack knows which environments are using a tcl module file. If there are multiple, and it doesn't know this, then removing for one environment could break another.

The nice thing about using the name-space is that it would avoid above, and if you can't get spack to do what you want, then it's simple to remove them manually.

@CodeGat
Copy link
Copy Markdown
Member Author

CodeGat commented Jul 10, 2025

Should this forced namespacing be the case for projections supplied by the user?

If so, this goes against the rationale of not overriding user projections.
And if not, we don't really have a way of knowing what projections are specified by the user in the prerelease module (since projection injection happens first). .

@aidanheerdegen
Copy link
Copy Markdown
Member

Should this forced namespacing be the case for projections supplied by the user?

I guess not.

If so, this goes against the rationale of not overriding user projections. And if not, we don't really have a way of knowing what projections are specified by the user in the prerelease module (since projection injection happens first). .

It's going to be vanishingly rare for people to bother specifying their own projections. So in that case we live with there being some funky modules sitting around I suppose. Can always clean up anything older than, say, 12 months.

@CodeGat CodeGat requested a review from aidanheerdegen July 17, 2025 01:53
Copy link
Copy Markdown
Member

@aidanheerdegen aidanheerdegen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reviewed some ... still some more to look through.

Edit: not sure actually, so I'll leave it as-is and let me know if you need another review.

@CodeGat CodeGat requested a review from aidanheerdegen July 21, 2025 02:12
@CodeGat CodeGat marked this pull request as draft July 23, 2025 00:19
@CodeGat
Copy link
Copy Markdown
Member Author

CodeGat commented Jul 23, 2025

There is potential to need to move vars.BUILD_DB_PACKAGES into a file rather than a var

Copy link
Copy Markdown
Member

@aidanheerdegen aidanheerdegen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@CodeGat CodeGat added version:MAJOR Requires an update to Model Deployment Repositories CI for:v6 Applies to v6 and removed version:MINOR Doesn't require update to Model Deployment Repositories for:v5 Applies to `v5` labels Jul 24, 2025
@CodeGat CodeGat changed the base branch from v5 to dev-v6 July 24, 2025 03:51
@CodeGat CodeGat marked this pull request as ready for review July 24, 2025 03:51
@CodeGat CodeGat merged commit 424ba3c into dev-v6 Jul 24, 2025
@github-project-automation github-project-automation bot moved this from Review 👏 to Done ✅ in Model Release Jul 24, 2025
@CodeGat CodeGat deleted the 169-inject-projections branch July 24, 2025 05:17
@CodeGat CodeGat mentioned this pull request Jul 29, 2025
CodeGat added a commit that referenced this pull request Aug 11, 2025
* Injection of Modules over Checks (#295)

* Add projection injection module

* Add requirements for injection modules

* Add tests for injection projection module, and inputs/requirements

* Add prerelease injection module

* Add tests for prerelease injection module

* Run injection.projection and injection.prerelease modules

* deploy-1-setup: Remove projection checks

* Remove unneeded mergedeep requirement

* Add module inits to folders

* Add step for installing dependencies, update names for checkout steps

* Used cd module prefix rather than custom working-directory so we can find the manifest

* Added required input for prerelease modification, always print out updated manifest at end

* Add back EOT

* Update non-root-spec projections to namespaced `{name}/prX-Y/VERSION` format

* Updated tests for namespaced non-root-spec projections

* Update prerelease module argument from --root-spec-version to --version

* Pass in sys.argv to parse_args, add tests

* Refactor workflow to split generation of root spec and packages

* Rename projections script to modules

* Add inject_includes function

* For test inputs, comment what is expected

* Reordered functions

* Updated tests after code updates

* Apply suggestions from code review

Co-authored-by: Aidan Heerdegen <[email protected]>
Signed-off-by: Tommy Gatti <[email protected]>

* Add root_spec to includes set, but remove it later when alphabetically sorting the includelist since it always comes first

* Updated output of manifest

* Ran black

* Added getter module for accessing various parts of a spack manifest

* Update `[test_]modules.py` to use new getter module

* Update `[test_]prerelease.py` to use getter module, update deploy-2-start to remove --root-spec arg

* Ran black again

* Raise NotImplementedErrors, add comments for successful matches

* Remove comments of old code

* Apply suggestions from code review

Co-authored-by: Aidan Heerdegen <[email protected]>
Signed-off-by: Tommy Gatti <[email protected]>

* Add example to multi-target spec to test function

* Parameterized tests

* Fixes following more test cases

* Converted manifest with no packages to fixture

* Improved from_file classmethod tests

* Parameterized valid and mistakenly invalid tests

* Remove `root-spec` arg and instead get from manifest directly, update tests

* Add new prerelease script flag `--keep-root-spec-intact`, that doesn't remove version information

---------

Signed-off-by: Tommy Gatti <[email protected]>
Co-authored-by: Aidan Heerdegen <[email protected]>

* `vars` to File-Based Special Packages (#305)

* Validate MDR config/packages.json

* Pass info from MDR config/packages.json to module injection script

* Update variable name to `vars.CONFIG_PACKAGES_SCHEMA_VERSION`

* Change cwd relative to build-cd rather than model for scripts

* Add output of packages to be injected/added to provenance DB

* Update prerelease projection to `ROOT_SPEC/prX-Y/{name}/VERSION`

* Update tests for new prerelease injection logic

* Replace all internal refs with v6

* Dump quoted strings for prerelease projections, updated expected output

* Schema Versions as Entrypoint Inputs Over `vars` (#310)

* Change schema vars to required inputs, add optional spack manifest schema path for potentially different schemas

* Add required schema version inputs, and optional spack manifest schema paths to entrypoint workflows

* Get packages for provenance from an earlier step

* Update prerelease injection to the form `ROOT_SPEC/.dependencies/PRX-Y/VERSION-{hash:7}`

* Fixed up an unused variable

* Remove `.` from `dependencies directory

---------

Signed-off-by: Tommy Gatti <[email protected]>
Co-authored-by: Aidan Heerdegen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

for:v6 Applies to v6 priority:high type:enhancement Improvements to existing features version:MAJOR Requires an update to Model Deployment Repositories CI

Projects

Status: Done ✅

Development

Successfully merging this pull request may close these issues.

Inject Values for spack.modules.default.tcl.projections

2 participants