From e41cce98e83066309def56d9147bda89a960d8ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Correa=20G=C3=B3mez?= Date: Fri, 26 Dec 2025 17:39:02 +0100 Subject: [PATCH] ci: use functools.cache instead of implementing custom cache global MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pablo Correa Gómez Part-of: --- .ci/lib/common.py | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/.ci/lib/common.py b/.ci/lib/common.py index 8bffe0eb7..d1df8096b 100755 --- a/.ci/lib/common.py +++ b/.ci/lib/common.py @@ -7,18 +7,12 @@ import configparser import os import subprocess +from functools import cache -cache = {} - - +@cache def get_pmaports_dir(): - global cache - if "pmaports_dir" in cache: - return cache["pmaports_dir"] - ret = os.path.realpath(os.path.join(os.path.dirname(__file__) + "/../..")) - cache["pmaports_dir"] = ret - return ret + return os.path.realpath(os.path.join(os.path.dirname(__file__) + "/../..")) def run_git(parameters, check=True, stderr=None): @@ -51,6 +45,7 @@ def run_pmbootstrap(parameters): subprocess.run(cmd, universal_newlines=True, check=True) +@cache def get_upstream_branch(): """ Use pmaports.cfg from current branch (e.g. "v20.05_fix-ci") and channels.cfg from master to retrieve the upstream branch. @@ -61,10 +56,6 @@ def get_upstream_branch(): if target_branch := os.environ.get("CI_MERGE_REQUEST_TARGET_BRANCH_NAME"): return target_branch - global cache - if "upstream_branch" in cache: - return cache["upstream_branch"] - # Get channel (e.g. "stable") from pmaports.cfg # https://postmarketos.org/pmaports.cfg pmaports_dir = get_pmaports_dir() @@ -82,9 +73,7 @@ def get_upstream_branch(): " This appears to be an old branch, consider recreating your change" \ " on top of master." - ret = channels_cfg[channel]["branch_pmaports"] - cache["upstream_branch"] = ret - return ret + return channels_cfg[channel]["branch_pmaports"] def get_base_commit() -> str: