meta: cache host runner

The host runner does not change and we can thus avoid looking it up
over and over again.
This commit is contained in:
Christian Kellner 2022-09-26 14:09:05 +02:00
parent ebf967ad1f
commit e923f559ab

View file

@ -539,6 +539,7 @@ class Index:
self._format_info: Dict[Tuple[str, Any], Any] = {}
self._schemata: Dict[Tuple[str, Any, str], Schema] = {}
self._runners: List[RunnerInfo] = []
self._host_runner: Optional[RunnerInfo] = None
@staticmethod
def list_formats() -> List[str]:
@ -678,5 +679,8 @@ class Index:
def detect_host_runner(self) -> RunnerInfo:
"""Use os-release(5) to detect the runner for the host"""
osname = osrelease.describe_os(*osrelease.DEFAULT_PATHS)
return self.detect_runner("org.osbuild." + osname)
if not self._host_runner:
osname = osrelease.describe_os(*osrelease.DEFAULT_PATHS)
self._host_runner = self.detect_runner("org.osbuild." + osname)
return self._host_runner