diff --git a/osbuild/meta.py b/osbuild/meta.py index 7b89446a..c5833a19 100644 --- a/osbuild/meta.py +++ b/osbuild/meta.py @@ -537,6 +537,7 @@ class Index: self._module_info: Dict[Tuple[str, Any], Any] = {} self._format_info: Dict[Tuple[str, Any], Any] = {} self._schemata: Dict[Tuple[str, Any, str], Schema] = {} + self._runners: List[RunnerInfo] = [] @staticmethod def list_formats() -> List[str]: @@ -634,13 +635,15 @@ class Index: If `distro` is specified, only runners matching that distro will be returned. """ - path = os.path.join(self.path, "runners") - names = filter(lambda f: os.path.isfile(f"{path}/{f}"), - os.listdir(path)) - paths = map(lambda n: os.path.join(path, n), names) - mapped = map(RunnerInfo.from_path, paths) - runners = sorted(mapped, key=lambda r: (r.distro, r.version)) + if not self._runners: + path = os.path.join(self.path, "runners") + names = filter(lambda f: os.path.isfile(f"{path}/{f}"), + os.listdir(path)) + paths = map(lambda n: os.path.join(path, n), names) + mapped = map(RunnerInfo.from_path, paths) + self._runners = sorted(mapped, key=lambda r: (r.distro, r.version)) + runners = self._runners[:] if distro: runners = [r for r in runners if r.distro == distro] diff --git a/test/mod/test_meta.py b/test/mod/test_meta.py index a185f841..93c809bb 100644 --- a/test/mod/test_meta.py +++ b/test/mod/test_meta.py @@ -64,8 +64,6 @@ def test_runner_detection(tempdir): runners = os.path.join(tempdir, "runners") os.makedirs(runners) - meta = osbuild.meta.Index(tempdir) - table = { "arch": { "base": "", @@ -102,6 +100,7 @@ def test_runner_detection(tempdir): base = info["base"] or 0 versions = info["versions"] want = create_runners(runners, distro, str(base), versions) + meta = osbuild.meta.Index(tempdir) have = meta.list_runners(distro) assert len(want) == len(have) want_all += want