memoize getters

ensures `get_` functions are called only once,
avoiding duplicate log statements
pull/1248/head
Min RK 2023-02-16 13:13:09 +01:00
rodzic 8c0f49ed89
commit 52be2d3d64
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 809C6E46EAA899F4
1 zmienionych plików z 13 dodań i 0 usunięć

Wyświetl plik

@ -7,6 +7,7 @@ import string
import sys
import tarfile
import textwrap
from functools import lru_cache
import escapism
import jinja2
@ -230,6 +231,18 @@ class BuildPack:
"support is experimental in repo2docker."
)
self.platform = ""
self._memoize()
def _memoize(self):
"""Memoize `get_foo` methods with lru_cache()
Avoids duplicate log statements when calling what should be idempotent methods more than once
"""
for method_name in dir(self):
if method_name.startswith("get_"):
method = getattr(self, method_name)
if callable(method):
setattr(self, method_name, lru_cache()(method))
def get_packages(self):
"""