Cache Shell Script of spack load and spack env activate - #47755
Cache Shell Script of spack load and spack env activate#47755RikkiButler20 wants to merge 173 commits into
spack load and spack env activate#47755Conversation
|
Very excited for this and happy to test on fish! |
|
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) |
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! |
|
@spackbot Fix style |
|
Let me see if I can fix that for you! |
|
I was able to run 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
I've updated the branch with style fixes. |
|
@spackbot Fix style |
|
Let me see if I can fix that for you! |
|
I was able to run 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
I've updated the branch with style fixes. |
|
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. |
|
@spackbot Fix style |
|
Let me see if I can fix that for you! |
|
I was able to run 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
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>
d8dedb4 to
2bdcc46
Compare
Signed-off-by: Richarda Butler <39577672+RikkiButler20@users.noreply.github.com>
Signed-off-by: Kayla Butler <butler59@llnl.gov>
…kkiButler20/spack into feature/cache-spack-load-and-activate
Signed-off-by: Kayla Butler <butler59@llnl.gov>
Signed-off-by: Kayla Butler <butler59@llnl.gov>
Signed-off-by: Kayla Butler <butler59@llnl.gov>
Ensures activation scripts are written correctly when locking is disabled Signed-off-by: John Parent <john.parent@kitware.com>
Signed-off-by: John Parent <john.parent@kitware.com>
|
@spackbot re-run pipeline |
|
I've started that pipeline for you! |
Signed-off-by: Richarda Butler <39577672+RikkiButler20@users.noreply.github.com>
Signed-off-by: Richarda Butler <39577672+RikkiButler20@users.noreply.github.com>
Signed-off-by: Kayla Butler <butler59@llnl.gov>
Signed-off-by: Kayla Butler <butler59@llnl.gov>
| The shell scripts contain all the environment modifications needed for the package, including: | ||
|
|
||
| 1. Updating PATH to include the package's bin directory | ||
| 2. Setting LD_LIBRARY_PATH for shared libraries |
There was a problem hiding this comment.
By default we don't do LD_LIBRARY_PATH because it breaks system libraries.
This should probably have a link to the prefix_inspections docs for how to modify the behavior.
There was a problem hiding this comment.
Is this what you mean? https://spack.readthedocs.io/en/latest/configuration.html#environment-modifications
There was a problem hiding this comment.
I was talking about this: https://spack.readthedocs.io/en/latest/module_file_support.html#global-environment-modifications
I don't know that we document it well, but we reuse these module configurations when doing module-like operations (spack load, spack env activate).
| cmds += "function despacktivate;\n" | ||
| cmds += " spack env deactivate;\n" | ||
| cmds += "end;\n" | ||
| if "color" in os.getenv("TERM", ""): |
There was a problem hiding this comment.
These are the commands that are part of env activation, not part of putting the view in the path.
The code is basically taking the cached activation script, and prepending a short header that is computed on the fly. This is the small portion computed on the fly, for things like e.g. spack env activate -p which modifies the behavior of the activation header but not the cached script.
| def generate_script(shell_script_path: str, mods: str, comments: str): | ||
| """Helper function to write spec's shell scripts | ||
|
|
||
| Args: | ||
| shell_script_path: Path to the shell script. | ||
| mods: Modifications to write to the script. | ||
| comments: Comment character(s) to use in the script | ||
| (e.g. "::" for bat and ### for all other shells) | ||
| """ | ||
|
|
||
| try: | ||
| fs.mkdirp(os.path.dirname(shell_script_path)) | ||
|
|
||
| header = ( | ||
| f"{comments} This file is auto-generated by Spack. Do not edit this file directly.\n" | ||
| f"{comments} Generated on: {datetime.now().strftime('%Y-%m-%d')}\n\n" | ||
| ) | ||
| with fs.write_tmp_and_move(shell_script_path, encoding="utf-8") as f: | ||
| f.write(header) | ||
| f.write(mods) | ||
| except OSError as e: | ||
| raise OSError(f"Error generating to {shell_script_path}\n{e}") |
There was a problem hiding this comment.
This method seems to share a lot of code with the analogous method for environments.
I think we can move some core functionality out of this hooks module into the spack.user_environment module, and then we can call it from both the generate_spec_scripts hooks and the spack.environment.generate_scripts module.
Signed-off-by: Kayla Butler <butler59@llnl.gov>
Remove update_env_script 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>
Fixes #47603
Fixes #21413
This will fix the problem of
spack loadandspack env activatetaking 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 Spackspack loadis run