mirror of
https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git
synced 2025-07-13 03:19:47 +03:00
meta: introduce a Cache decorator (MR 2252)
Generalise pmb.helpers.other.cache with a more python decorator. The Cache decorator takes a list of function arguments to use as cache keys, keyword args can be used to restrict caching so that it is skipped entirely unless the attribute has a specific value. For example, pmb.helpers.pmaports.get() has the decorator: @Cache("pkgname", subpackages=True) This means the return value will be cached only when subpackages is True, otherwise it will always miss. Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
parent
79cf2e8910
commit
185d8bcef5
20 changed files with 244 additions and 165 deletions
|
@ -15,6 +15,7 @@ import pmb.chroot.apk
|
|||
import pmb.config
|
||||
import pmb.helpers.pmaports
|
||||
import pmb.helpers.run
|
||||
from pmb.meta import Cache
|
||||
|
||||
|
||||
def get_path(name_repo: str):
|
||||
|
@ -107,6 +108,7 @@ def get_upstream_remote(aports: Path):
|
|||
" repository: {}".format(name_repo, urls, aports))
|
||||
|
||||
|
||||
@Cache("aports")
|
||||
def parse_channels_cfg(aports: Path):
|
||||
"""Parse channels.cfg from pmaports.git, origin/master branch.
|
||||
|
||||
|
@ -119,11 +121,6 @@ def parse_channels_cfg(aports: Path):
|
|||
"mirrordir_alpine": ...},
|
||||
...}}
|
||||
"""
|
||||
# Cache during one pmbootstrap run
|
||||
cache_key = "pmb.helpers.git.parse_channels_cfg"
|
||||
if pmb.helpers.other.cache[cache_key]:
|
||||
return pmb.helpers.other.cache[cache_key]
|
||||
|
||||
# Read with configparser
|
||||
cfg = configparser.ConfigParser()
|
||||
remote = get_upstream_remote(aports)
|
||||
|
@ -157,7 +154,6 @@ def parse_channels_cfg(aports: Path):
|
|||
# FIXME: how to type this properly??
|
||||
ret["channels"][channel_new][key] = value # type: ignore[index]
|
||||
|
||||
pmb.helpers.other.cache[cache_key] = ret
|
||||
return ret
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue