meta: cache list of runners
Instead of enumerating all existing runners -- doing i/o -- we cache the list at the `Index` level.
This commit is contained in:
parent
c755068bd2
commit
683a8cbfa7
2 changed files with 10 additions and 8 deletions
|
|
@ -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]
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue