jw.pkg.App: Add lru_cache where possible

ResultCache is a home-grown result cache. The @lru_cache decorator,
now available in Python 3, accomplishes the same thing, so try to
ditch ResultCache for it.

Sadly, this doesn't entirely work as of now, because it uses hash()
to hash the arguments, which won't work for the two list-type
arguments to add_modules_from_project_txt() (buf and visited).

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-01-26 12:32:15 +01:00
commit 5cdc32abd7

View file

@ -4,6 +4,7 @@
#
import os, sys, argparse, pwd, re
from functools import lru_cache
from .lib.App import App as Base
from .lib.log import *
@ -139,7 +140,7 @@ class App(Base):
self.__pretty_topdir = self.__format_topdir(self.__topdir, args.topdir_format)
self.__topdir_fmt = args.topdir_format
if self.__topdir is not None:
self.__top_name = self.__res_cache.run(self.read_value, [self.__topdir + '/make/project.conf', 'build', 'name'])
self.__top_name = self.read_value(self.__topdir + '/make/project.conf', 'build', 'name')
if not self.__top_name:
self.__top_name = re.sub('-[0-9.-]*$', '', os.path.basename(os.path.realpath(self.__topdir)))
@ -167,6 +168,7 @@ class App(Base):
seen_add = seen.add
return [x for x in seq if not (x in seen or seen_add(x))]
@lru_cache(maxsize=None)
def get_os(self, args = ""):
import subprocess
for d in [ self.__projs_root + '/jw-pkg/scripts', '/opt/jw-pkg/bin' ]:
@ -198,7 +200,7 @@ class App(Base):
if self.__os_cascade is not None:
return self.__os_cascade.copy()
r = [ 'os', platform.system().lower() ]
os = self.__opt_os if self.__opt_os is not None else self.__res_cache.run(self.get_os, [])
os = self.__opt_os if self.__opt_os is not None else self.get_os()
name = re.sub('-.*', '', os)
series = os
while True:
@ -235,6 +237,7 @@ class App(Base):
file.close()
return r.rstrip()
@lru_cache(maxsize=None)
def read_value(self, path, section, key):
def scan_section(f, key):
@ -311,7 +314,7 @@ class App(Base):
path = proj_root + '/make/project.conf'
#print('path = ', path, 'self.__top_name = ', self.__top_name, 'name = ', name)
return self.__res_cache.run(self.read_value, [path, section, key])
return self.read_value(path, section, key)
def collect_values(self, names, section, key):
r = ""