pmb.helpers.other.cache: simplify (MR 2252)

The init_cache() function just assigned some default constants, simplify
this by just declaring it that way to begin with, as well as adding type
hints.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
Caleb Connolly 2024-04-04 02:38:37 +02:00 committed by Oliver Smith
parent 3bfc6474bb
commit 7ed08e74d3
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
4 changed files with 20 additions and 30 deletions

View file

@ -216,9 +216,6 @@ def switch_to_channel_branch(args: PmbArgs, channel_new):
" fix what git complained about, then try again: " " fix what git complained about, then try again: "
f"{args.aports}") f"{args.aports}")
# Invalidate all caches
pmb.helpers.other.init_cache()
# Verify pmaports.cfg on new branch # Verify pmaports.cfg on new branch
read_config(args) read_config(args)
return True return True

View file

@ -113,7 +113,6 @@ def init(args: PmbArgs):
fix_mirrors_postmarketos(args) fix_mirrors_postmarketos(args)
pmb.config.merge_with_args(args) pmb.config.merge_with_args(args)
replace_placeholders(args) replace_placeholders(args)
pmb.helpers.other.init_cache()
# Initialize logs (we could raise errors below) # Initialize logs (we could raise errors below)
pmb.helpers.logging.init(args) pmb.helpers.logging.init(args)

View file

@ -10,6 +10,7 @@ import pmb.config.init
from pmb.core.types import PmbArgs from pmb.core.types import PmbArgs
import pmb.helpers.pmaports import pmb.helpers.pmaports
import pmb.helpers.run import pmb.helpers.run
from typing import Dict, Any
def folder_size(args: PmbArgs, path: Path): def folder_size(args: PmbArgs, path: Path):
@ -97,7 +98,7 @@ def migrate_work_folder(args: PmbArgs):
logging.info("* Building chroots have a different username (#709)") logging.info("* Building chroots have a different username (#709)")
logging.info("Migration will do the following:") logging.info("Migration will do the following:")
logging.info("* Zap your chroots") logging.info("* Zap your chroots")
logging.info("* Adjust '" + pmb.config.work / "config_abuild/abuild.conf'") logging.info(f"* Adjust '{pmb.config.work / 'config_abuild/abuild.conf'}'")
if not pmb.helpers.cli.confirm(args): if not pmb.helpers.cli.confirm(args):
raise RuntimeError("Aborted.") raise RuntimeError("Aborted.")
@ -117,8 +118,7 @@ def migrate_work_folder(args: PmbArgs):
logging.info("Changelog:") logging.info("Changelog:")
logging.info("* Fix: cache_distfiles was writable for everyone") logging.info("* Fix: cache_distfiles was writable for everyone")
logging.info("Migration will do the following:") logging.info("Migration will do the following:")
logging.info("* Fix permissions of '" + pmb.config.work + logging.info(f"* Fix permissions of '{pmb.config.work / 'cache_distfiles'}'")
"/cache_distfiles'")
if not pmb.helpers.cli.confirm(args): if not pmb.helpers.cli.confirm(args):
raise RuntimeError("Aborted.") raise RuntimeError("Aborted.")
@ -155,7 +155,7 @@ def migrate_work_folder(args: PmbArgs):
logging.info(" 'git' instead of using it from an Alpine chroot") logging.info(" 'git' instead of using it from an Alpine chroot")
logging.info("Migration will do the following:") logging.info("Migration will do the following:")
logging.info("* Check if 'git' is installed") logging.info("* Check if 'git' is installed")
logging.info("* Change ownership to your user: " + path) logging.info(f"* Change ownership to your user: {path}")
if not pmb.helpers.cli.confirm(args): if not pmb.helpers.cli.confirm(args):
raise RuntimeError("Aborted.") raise RuntimeError("Aborted.")
@ -236,8 +236,8 @@ def migrate_work_folder(args: PmbArgs):
if current != required: if current != required:
raise RuntimeError("Sorry, we can't migrate that automatically. Please" raise RuntimeError("Sorry, we can't migrate that automatically. Please"
" run 'pmbootstrap shutdown', then delete your" " run 'pmbootstrap shutdown', then delete your"
" current work folder manually ('sudo rm -rf " + " current work folder manually ('sudo rm -rf "
pmb.config.work + "') and start over with 'pmbootstrap" f"{pmb.config.work}') and start over with 'pmbootstrap"
" init'. All your binary packages and caches will" " init'. All your binary packages and caches will"
" be lost.") " be lost.")
@ -281,22 +281,17 @@ def lookup(key):
pmb.helpers.other.cache["mycache"][key] = ret pmb.helpers.other.cache["mycache"][key] = ret
return ret return ret
""" """
cache = None cache: Dict[str, Any] = {
"apkindex": {},
"apkbuild": {},
def init_cache(): "apk_min_version_checked": [],
global cache "apk_repository_list_updated": [],
"""Add a caching dict (caches parsing of files etc. for the current session).""" "built": {},
repo_update = {"404": [], "offline_msg_shown": False} "find_aport": {},
cache = {"apkindex": {}, "pmb.helpers.package.depends_recurse": {},
"apkbuild": {}, "pmb.helpers.package.get": {},
"apk_min_version_checked": [], "pmb.helpers.repo.update": {"404": [], "offline_msg_shown": False},
"apk_repository_list_updated": [], "pmb.helpers.git.parse_channels_cfg": {},
"built": {}, "pmb.config.pmaports.read_config": None,
"find_aport": {}, "pmb.config.pmaports.read_config_repos": None,
"pmb.helpers.package.depends_recurse": {}, }
"pmb.helpers.package.get": {},
"pmb.helpers.repo.update": repo_update,
"pmb.helpers.git.parse_channels_cfg": {},
"pmb.config.pmaports.read_config": None,
"pmb.config.pmaports.read_config_repos": None}

View file

@ -593,7 +593,6 @@ def package_completer(prefix, action, parser=None, parsed_args=None):
args = parsed_args args = parsed_args
pmb.config.merge_with_args(args) pmb.config.merge_with_args(args)
pmb.helpers.args.replace_placeholders(args) pmb.helpers.args.replace_placeholders(args)
pmb.helpers.other.init_cache()
packages = set( packages = set(
package for package in pmb.helpers.pmaports.get_list(args) package for package in pmb.helpers.pmaports.get_list(args)
if package.startswith(prefix)) if package.startswith(prefix))