performance: avoid jinja2 import at startup unless needed (#43237)

`jinja2` can be a costly import, and right now it happens at startup every time we run
Spack. This slows down `spack --print-shell-vars` a bit, which is needed by `setup-env.*sh`.
This commit is contained in:
Todd Gamblin 2024-03-18 02:00:37 -07:00 committed by GitHub
parent 8cd160db85
commit 3d8136493a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -9,8 +9,6 @@
import tempfile
from typing import Any, Deque, Dict, Generator, List, NamedTuple, Tuple
import jinja2
from llnl.util import filesystem
import spack.repo
@ -85,6 +83,8 @@ def _mock_layout(self) -> Generator[List[str], None, None]:
self.tmpdir.cleanup()
def _create_executable_scripts(self, mock_executables: MockExecutables) -> List[pathlib.Path]:
import jinja2
relative_paths = mock_executables.executables
script = mock_executables.script
script_template = jinja2.Template("#!/bin/bash\n{{ script }}\n")