Skip to content

Cache Shell Script of spack load and spack env activate#47755

Draft
RikkiButler20 wants to merge 146 commits into
spack:developfrom
RikkiButler20:feature/cache-spack-load-and-activate
Draft

Cache Shell Script of spack load and spack env activate#47755
RikkiButler20 wants to merge 146 commits into
spack:developfrom
RikkiButler20:feature/cache-spack-load-and-activate

Conversation

@RikkiButler20

@RikkiButler20 RikkiButler20 commented Nov 23, 2024

Copy link
Copy Markdown
Contributor

Fixes #47603
Fixes #21413

This will fix the problem of spack load and spack env activate taking too long and currently iterating over all the package's dependency's python package files. This will also prevents the drifting of the installed spec from the current, updated version on Spack

  • Create a new hook that will save shell script at install time
  • Shell scripts for bash
  • Shell scripts for csh
  • Shell scripts for fish
  • Shell scripts for pwsh
  • Shell scripts for bat
  • Execute shell script when spack load is run
  • Check if there is shell script is cached and if any of the specs have changed when activated environment is installed
  • Create shell script when environment is created
  • Execute shell script when environment is activated/deactivated
  • Add & update tests
  • Update documentation
  • Needs to be more robust to loading/unloading an environment missing its scripts
  • Environment load/unload scripts need to be able to be created from the cached repo without the package in the normal repo
  • load/unload/activate/deactivate scripts for sh/csh/fish are identical, need to unify them

@RikkiButler20 RikkiButler20 added feature A feature is missing in Spack commands shell-support labels Nov 23, 2024
@RikkiButler20 RikkiButler20 self-assigned this Nov 23, 2024
@spackbot-app spackbot-app Bot added core PR affects Spack core functionality tests General test capability(ies) labels Nov 23, 2024
@adamjstewart

Copy link
Copy Markdown
Member

Very excited for this and happy to test on fish!

@adamjstewart adamjstewart added this to the v0.24 milestone Nov 23, 2024
@aweits

aweits commented Nov 24, 2024

Copy link
Copy Markdown
Contributor

What if we cached the environment changes at install-time instead? That would also solve issues related to allowing older installs to still function/load... (willing to help with this, would allow me to jettison some local code that is getting harder and harder to maintain)

@tgamblin

tgamblin commented Nov 24, 2024

Copy link
Copy Markdown
Member

What if we cached the environment changes at install-time instead?

This is the plan. There are some details in the slack discussion linked from #47603, and the bit about “package drift” there.

i think @RikkiButler20 is doing this in steps (see checklist) — probably need one or two more to move the logic to package install time and env install time.

@aweits I think if you want to help, iterating on reviews would be great so we can get this in for 1.0!

@RikkiButler20

Copy link
Copy Markdown
Contributor Author

@spackbot Fix style

@spackbot-app

spackbot-app Bot commented Nov 27, 2024

Copy link
Copy Markdown

Let me see if I can fix that for you!

@spackbot-app

spackbot-app Bot commented Nov 27, 2024

Copy link
Copy Markdown

I was able to run spack style --fix for you!

spack style --fix
==> Running style checks on spack
  selected: import, isort, black, flake8, mypy
==> Modified files
  lib/spack/spack/cmd/load.py
  lib/spack/spack/test/cmd/load.py
==> Running import checks
import check requires Python 3.9 or later
  import checks were clean
==> Running isort checks
  isort checks were clean
==> Running black checks
reformatted lib/spack/spack/cmd/load.py
reformatted lib/spack/spack/test/cmd/load.py
All done! ✨ 🍰 ✨
2 files reformatted.
  black checks were clean
==> Running flake8 checks
  flake8 checks were clean
==> Running mypy checks
lib/spack/spack/version/version_types.py:145: error: Argument 2 to "StandardVersion" has incompatible type "*Tuple[Tuple[Any, ...], Tuple[Any, ...]]"; expected "Tuple[Tuple[Any, ...], Tuple[Any, ...]]"  [arg-type]
lib/spack/spack/version/version_types.py:452: error: Argument 2 to "StandardVersion" has incompatible type "*Tuple[Tuple[Any, ...], Tuple[Any, ...]]"; expected "Tuple[Tuple[Any, ...], Tuple[Any, ...]]"  [arg-type]
lib/spack/spack/version/version_types.py:481: error: Argument 2 to "StandardVersion" has incompatible type "*Tuple[Tuple[Any, ...], Tuple[Any, ...]]"; expected "Tuple[Tuple[Any, ...], Tuple[Any, ...]]"  [arg-type]
lib/spack/spack/variant.py:131: error: Unsupported right operand type for in ("Union[Collection[Any], Callable[..., Any]]")  [operator]
Found 4 errors in 2 files (checked 624 source files)
  mypy found errors
Keep in mind that I cannot fix your flake8 or mypy errors, so if you have any you'll need to fix them and update the pull request. If I was able to push to your branch, if you make further changes you will need to pull from your updated branch before pushing again.

I've updated the branch with style fixes.

Comment thread lib/spack/spack/cmd/load.py Outdated
@RikkiButler20

Copy link
Copy Markdown
Contributor Author

@spackbot Fix style

@spackbot-app

spackbot-app Bot commented Dec 5, 2024

Copy link
Copy Markdown

Let me see if I can fix that for you!

@spackbot-app

spackbot-app Bot commented Dec 5, 2024

Copy link
Copy Markdown

I was able to run spack style --fix for you!

spack style --fix
==> Running style checks on spack
  selected: import, isort, black, flake8, mypy
==> Modified files
  lib/spack/spack/cmd/load.py
  lib/spack/spack/test/cmd/load.py
==> Running import checks
import check requires Python 3.9 or later
  import checks were clean
==> Running isort checks
  isort checks were clean
==> Running black checks
reformatted lib/spack/spack/test/cmd/load.py
All done! ✨ 🍰 ✨
1 file reformatted, 1 file left unchanged.
  black checks were clean
==> Running flake8 checks
  flake8 checks were clean
==> Running mypy checks
lib/spack/spack/version/version_types.py:145: error: Argument 2 to "StandardVersion" has incompatible type "*Tuple[Tuple[Any, ...], Tuple[Any, ...]]"; expected "Tuple[Tuple[Any, ...], Tuple[Any, ...]]"  [arg-type]
lib/spack/spack/version/version_types.py:452: error: Argument 2 to "StandardVersion" has incompatible type "*Tuple[Tuple[Any, ...], Tuple[Any, ...]]"; expected "Tuple[Tuple[Any, ...], Tuple[Any, ...]]"  [arg-type]
lib/spack/spack/version/version_types.py:481: error: Argument 2 to "StandardVersion" has incompatible type "*Tuple[Tuple[Any, ...], Tuple[Any, ...]]"; expected "Tuple[Tuple[Any, ...], Tuple[Any, ...]]"  [arg-type]
lib/spack/spack/variant.py:131: error: Unsupported right operand type for in ("Union[Collection[Any], Callable[..., Any]]")  [operator]
Found 4 errors in 2 files (checked 624 source files)
  mypy found errors
Keep in mind that I cannot fix your flake8 or mypy errors, so if you have any you'll need to fix them and update the pull request. If I was able to push to your branch, if you make further changes you will need to pull from your updated branch before pushing again.

I've updated the branch with style fixes.

@spackbot-app spackbot-app Bot added the documentation Improvements or additions to documentation label Jan 3, 2025
Comment thread lib/spack/spack/hooks/cache_shell_script.py Outdated
Comment thread lib/spack/spack/test/hooks/cache_shell_script.py Outdated
@adamjstewart

Copy link
Copy Markdown
Member

Going to unsubscribe from this PR while it's still a WIP (too many notifications) but please ping me to review fish support once it is complete.

@RikkiButler20 RikkiButler20 marked this pull request as draft January 16, 2025 20:26
@RikkiButler20

Copy link
Copy Markdown
Contributor Author

@spackbot Fix style

@spackbot-app

spackbot-app Bot commented Jan 16, 2025

Copy link
Copy Markdown

Let me see if I can fix that for you!

@spackbot-app

spackbot-app Bot commented Jan 16, 2025

Copy link
Copy Markdown

I was able to run spack style --fix for you!

spack style --fix
==> Running style checks on spack
  selected: import, isort, black, flake8, mypy
==> Modified files
  lib/spack/spack/cmd/load.py
  lib/spack/spack/hooks/__init__.py
  lib/spack/spack/hooks/cache_shell_script.py
  lib/spack/spack/test/environment_modifications.py
  lib/spack/spack/test/hooks/cache_shell_script.py
  lib/spack/spack/test/util/environment.py
  lib/spack/spack/util/environment.py
==> Running import checks
import check requires Python 3.9 or later
  import checks were clean
==> Running isort checks
Fixing /tmp/tmpu87evsa3/spack/lib/spack/spack/test/hooks/cache_shell_script.py
  isort checks were clean
==> Running black checks
reformatted lib/spack/spack/test/hooks/cache_shell_script.py
reformatted lib/spack/spack/util/environment.py
All done! ✨ 🍰 ✨
2 files reformatted, 5 files left unchanged.
  black checks were clean
==> Running flake8 checks
lib/spack/spack/cmd/load.py:12: [F401] 'spack.user_environment as uenv' imported but unused
lib/spack/spack/cmd/load.py:13: [F401] 'spack.util.environment' imported but unused
  flake8 found errors
==> Running mypy checks
lib/spack/spack/util/environment.py:662: error: Item "NameModifier" of "Union[NameModifier, NameValueModifier]" has no attribute "_cache_str"  [union-attr]
lib/spack/spack/util/environment.py:662: error: Item "NameValueModifier" of "Union[NameModifier, NameValueModifier]" has no attribute "_cache_str"  [union-attr]
lib/spack/spack/version/version_types.py:135: error: Incompatible types in assignment (expression has type "Tuple[Any, ...]", variable has type "Tuple[str]")  [assignment]
lib/spack/spack/variant.py:130: error: Unsupported right operand type for in ("Union[Collection[Any], Callable[..., Any]]")  [operator]
lib/spack/spack/build_environment.py:171: error: Overloaded function signatures 1 and 2 overlap with incompatible return types  [misc]
lib/spack/spack/build_environment.py:171: error: Overloaded function signatures 1 and 3 overlap with incompatible return types  [misc]
Found 6 errors in 4 files (checked 636 source files)
  mypy found errors
Keep in mind that I cannot fix your flake8 or mypy errors, so if you have any you'll need to fix them and update the pull request. If I was able to push to your branch, if you make further changes you will need to pull from your updated branch before pushing again.

I've updated the branch with style fixes.

@RikkiButler20 RikkiButler20 force-pushed the feature/cache-spack-load-and-activate branch from 4a2d1ce to a8b77fc Compare June 4, 2026 22:07
Remove dead arguments
hace windows shells use _spack_env_set & unset

Signed-off-by: Kayla Butler <butler59@llnl.gov>
Signed-off-by: Kayla Butler <butler59@llnl.gov>
Signed-off-by: Kayla Butler <butler59@llnl.gov>
Fix style
Regenerate deactivation script when lockfile is updated

Signed-off-by: Kayla Butler <butler59@llnl.gov>
Signed-off-by: Kayla Butler <butler59@llnl.gov>
@RikkiButler20

Copy link
Copy Markdown
Contributor Author

@spackbot fix style

@spackbot-app

spackbot-app Bot commented Jun 5, 2026

Copy link
Copy Markdown

Let me see if I can fix that for you!

@spackbot-app

spackbot-app Bot commented Jun 5, 2026

Copy link
Copy Markdown

I was able to run spack style --fix for you!

spack style --fix
==> Running style checks on spack
  selected: import, ruff-format, ruff-check, mypy
==> Running import checks
  import checks were clean
==> Running ruff-format checks
  ruff-format checks were clean
==> Running ruff-check checks
  ruff-check checks were clean
==> Running mypy checks
Success: no issues found in 639 source files
  mypy checks were clean
==> spack style checks were clean
Keep in mind that I cannot fix your flake8 or mypy errors, so if you have any you'll need to fix them and update the pull request. If I was able to push to your branch, if you make further changes you will need to pull from your updated branch before pushing again.

I've updated the branch with style fixes.

Signed-off-by: Kayla Butler <butler59@llnl.gov>
Signed-off-by: Kayla Butler <butler59@llnl.gov>
Signed-off-by: Kayla Butler <butler59@llnl.gov>
Signed-off-by: Kayla Butler <butler59@llnl.gov>
Signed-off-by: Kayla Butler <butler59@llnl.gov>
The separator is different for windows scripts

Signed-off-by: Kayla Butler <butler59@llnl.gov>
Signed-off-by: Kayla Butler <butler59@llnl.gov>
@RikkiButler20

Copy link
Copy Markdown
Contributor Author

@spackbot fix style

@spackbot-app

spackbot-app Bot commented Jun 9, 2026

Copy link
Copy Markdown

Let me see if I can fix that for you!

@spackbot-app

spackbot-app Bot commented Jun 9, 2026

Copy link
Copy Markdown

I was able to run spack style --fix for you!

spack style --fix
==> Running style checks on spack
  selected: import, ruff-format, ruff-check, mypy
==> Running import checks
  import checks were clean
==> Running ruff-format checks
  ruff-format checks were clean
==> Running ruff-check checks
E501 Line too long (100 > 99)
   --> lib/spack/spack/test/hooks/generate_spec_scripts.py:104:100
    |
102 |         )
103 |         assert re.search(
104 |             f"_spack_env_remove_value {uenv.spack_loaded_hashes_var} {pkg.dag_hash()} {os.pathsep}",
    |                                                                                                    ^
105 |             unload_script,
106 |         )
    |
  ruff-check found errors
==> Running mypy checks
Success: no issues found in 639 source files
  mypy checks were clean
Keep in mind that I cannot fix your flake8 or mypy errors, so if you have any you'll need to fix them and update the pull request. If I was able to push to your branch, if you make further changes you will need to pull from your updated branch before pushing again.

I've updated the branch with style fixes.

@RikkiButler20

Copy link
Copy Markdown
Contributor Author

@spackbot fix style

@spackbot-app

spackbot-app Bot commented Jun 9, 2026

Copy link
Copy Markdown

Let me see if I can fix that for you!

@spackbot-app

spackbot-app Bot commented Jun 9, 2026

Copy link
Copy Markdown

I was able to run spack style --fix for you!

spack style --fix
==> Running style checks on spack
  selected: import, ruff-format, ruff-check, mypy
==> Running import checks
  import checks were clean
==> Running ruff-format checks
  ruff-format checks were clean
==> Running ruff-check checks
E501 Line too long (100 > 99)
   --> lib/spack/spack/test/hooks/generate_spec_scripts.py:104:100
    |
102 |         )
103 |         assert re.search(
104 |             f"_spack_env_remove_value {uenv.spack_loaded_hashes_var} {pkg.dag_hash()} {os.pathsep}",
    |                                                                                                    ^
105 |             unload_script,
106 |         )
    |
  ruff-check found errors
==> Running mypy checks
Success: no issues found in 639 source files
  mypy checks were clean
Keep in mind that I cannot fix your flake8 or mypy errors, so if you have any you'll need to fix them and update the pull request. If I was able to push to your branch, if you make further changes you will need to pull from your updated branch before pushing again.

I wasn't able to make any further changes, but please see the message above for remaining issues you can fix locally!

Signed-off-by: Kayla Butler <butler59@llnl.gov>
Signed-off-by: Kayla Butler <butler59@llnl.gov>
Signed-off-by: Kayla Butler <butler59@llnl.gov>
@RikkiButler20 RikkiButler20 force-pushed the feature/cache-spack-load-and-activate branch from c1c1829 to 61b45f4 Compare June 10, 2026 19:13
Signed-off-by: Kayla Butler <butler59@llnl.gov>
Signed-off-by: Kayla Butler <butler59@llnl.gov>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

binary-caches binary-packages ci Issues related to Continuous Integration commands core PR affects Spack core functionality docs documentation Improvements or additions to documentation environments feature A feature is missing in Spack shell-support tests General test capability(ies) unit-tests utilities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Increase speed of spack load and spack env activate Sourceable/Module File Generation for Environment Activation

8 participants