From 3d8136493a62c382bc8269d014a4503d7fe05f4d Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 18 Mar 2024 02:00:37 -0700 Subject: [PATCH] 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`. --- lib/spack/spack/detection/test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/spack/spack/detection/test.py b/lib/spack/spack/detection/test.py index a9a03115201..657188a38cd 100644 --- a/lib/spack/spack/detection/test.py +++ b/lib/spack/spack/detection/test.py @@ -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")