From f6ed191d7303beb44398d91527e86e9068831f9b Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Mon, 26 Jan 2026 13:13:12 +0100 Subject: [PATCH] jw.pkg.App.get_modules_from_project_txt(): Add Scope Add the Enum "Scope" to denote the scope argument of jw.pkg.App.get_modules_from_project_txt(), because it explains itself better than an integer. Signed-off-by: Jan Lindemann --- src/python/jw/pkg/App.py | 28 ++++++++++--------- src/python/jw/pkg/cmds/projects/CmdBuild.py | 3 +- src/python/jw/pkg/cmds/projects/CmdCflags.py | 3 +- src/python/jw/pkg/cmds/projects/CmdExepath.py | 3 +- src/python/jw/pkg/cmds/projects/CmdLdflags.py | 5 ++-- .../jw/pkg/cmds/projects/CmdLdlibpath.py | 3 +- src/python/jw/pkg/cmds/projects/CmdPath.py | 3 +- src/python/jw/pkg/cmds/projects/CmdPrereq.py | 3 +- .../jw/pkg/cmds/projects/CmdPythonpath.py | 3 +- .../jw/pkg/cmds/projects/CmdPythonpathOrig.py | 3 +- .../jw/pkg/cmds/projects/CmdRequiredOsPkg.py | 3 +- 11 files changed, 36 insertions(+), 24 deletions(-) diff --git a/src/python/jw/pkg/App.py b/src/python/jw/pkg/App.py index b5964c75..ae5682fe 100644 --- a/src/python/jw/pkg/App.py +++ b/src/python/jw/pkg/App.py @@ -5,6 +5,7 @@ import os, sys, argparse, pwd, re from functools import lru_cache +from enum import Enum, auto from .lib.App import App as Base from .lib.log import * @@ -46,6 +47,11 @@ class ResultCache(object): #d = d[k] raise Exception("cache algorithm failed for function", func.__name__, "in depth", depth) +class Scope(Enum): + Self = auto() + One = auto() + Subtree = auto() + # ----------------------------------------------------------------- class App class App(Base): @@ -323,15 +329,11 @@ class App(Base): r = r + " " + val return self.remove_duplicates([x.strip() for x in r.split(",")]) - # scope 0: no children - # scope 1: children - # scope 2: recursive - def add_modules_from_project_txt_cached(self, buf, visited, spec, section, key, add_self, scope, names_only): return self.__res_cache.run(self.add_modules_from_project_txt, [buf, visited, spec, section, key, add_self, scope, names_only]) def add_modules_from_project_txt(self, buf: list[str], visited: set[str], spec: str, - section: str, key: str, add_self: bool, scope: int, names_only: bool): + section: str, key: str, add_self: bool, scope: Scope, names_only: bool): name = self.strip_module_from_spec(spec) if names_only: spec = name @@ -343,12 +345,12 @@ class App(Base): return visited.add(spec) deps = self.get_value(name, section, key) - log(DEBUG, "name = ", name, "section = ", section, "key = ", key, "deps = ", deps, "scope = ", scope, "visited = ", visited) - if deps and scope > 0: - if scope == 1: - subscope = 0 + log(DEBUG, "name = ", name, "section = ", section, "key = ", key, "deps = ", deps, "scope = ", scope.name, "visited = ", visited) + if deps and scope != Scope.Self: + if scope == Scope.One: + subscope = Scope.Self else: - subscope = 2 + subscope = Scope.Subtree deps = deps.split(',') for dep in deps: dep = dep.strip() @@ -381,7 +383,7 @@ class App(Base): def get_libname(self, names): vals = self.get_modules_from_project_txt(names, ['build'], 'libname', - scope = 1, add_self=False, names_only=True) + scope = Scope.One, add_self=False, names_only=True) if not vals: return ' '.join(names) if 'none' in vals: @@ -391,7 +393,7 @@ class App(Base): def is_excluded_from_build(self, module): log(DEBUG, "checking if module " + module + " is excluded from build") exclude = self.get_modules_from_project_txt([ module ], ['build'], 'exclude', - scope = 1, add_self=False, names_only=True) + scope = Scope.One, add_self=False, names_only=True) cascade = self.os_cascade() + [ 'all' ] for p1 in exclude: for p2 in cascade: @@ -413,7 +415,7 @@ class App(Base): if m in graph: continue deps = self.get_modules_from_project_txt([ m ], ['pkg.requires.jw'], section, - scope = 1, add_self=False, names_only=True) + scope = Scope.One, add_self=False, names_only=True) if not deps is None: graph[m] = deps for d in deps: diff --git a/src/python/jw/pkg/cmds/projects/CmdBuild.py b/src/python/jw/pkg/cmds/projects/CmdBuild.py index 1055cc56..dcd74033 100644 --- a/src/python/jw/pkg/cmds/projects/CmdBuild.py +++ b/src/python/jw/pkg/cmds/projects/CmdBuild.py @@ -6,6 +6,7 @@ from functools import lru_cache from ...lib.log import * from ..Cmd import Cmd +from ...App import Scope class CmdBuild(Cmd): # export @@ -36,7 +37,7 @@ class CmdBuild(Cmd): # export dep_cache[prereq_type]: dict[str, str] = {} ret = self.app.get_modules_from_project_txt([ cur ], ['pkg.requires.jw'], - prereq_type, scope = 2, add_self=False, names_only=True) + prereq_type, scope = Scope.Subtree, add_self=False, names_only=True) log(DEBUG, 'prerequisites = ' + ' '.join(ret)) if cur in ret: ret.remove(cur) diff --git a/src/python/jw/pkg/cmds/projects/CmdCflags.py b/src/python/jw/pkg/cmds/projects/CmdCflags.py index 4fd87190..67e9ec7d 100644 --- a/src/python/jw/pkg/cmds/projects/CmdCflags.py +++ b/src/python/jw/pkg/cmds/projects/CmdCflags.py @@ -3,6 +3,7 @@ from argparse import Namespace, ArgumentParser from ..Cmd import Cmd +from ...App import Scope class CmdCflags(Cmd): # export @@ -15,7 +16,7 @@ class CmdCflags(Cmd): # export def _run(self, args: Namespace) -> None: deps = self.app.get_modules_from_project_txt(args.module, ['pkg.requires.jw'], 'build', - scope = 2, add_self=True, names_only=True) + scope = Scope.Subtree, add_self=True, names_only=True) out = [] for m in reversed(deps): path = self.app.find_dir(m, ['/include']) diff --git a/src/python/jw/pkg/cmds/projects/CmdExepath.py b/src/python/jw/pkg/cmds/projects/CmdExepath.py index 04a72085..e074975d 100644 --- a/src/python/jw/pkg/cmds/projects/CmdExepath.py +++ b/src/python/jw/pkg/cmds/projects/CmdExepath.py @@ -3,6 +3,7 @@ from argparse import Namespace, ArgumentParser from ..Cmd import Cmd +from ...App import Scope class CmdExepath(Cmd): # export @@ -15,7 +16,7 @@ class CmdExepath(Cmd): # export def _run(self, args: Namespace) -> None: deps = self.app.get_modules_from_project_txt(args.module, ['pkg.requires.jw'], [ 'run', 'build', 'devel' ], - scope = 2, add_self=True, names_only=True) + scope = Scope.Subtree, add_self=True, names_only=True) out = [] for m in deps: path = self.app.find_dir(m, ['/bin']) diff --git a/src/python/jw/pkg/cmds/projects/CmdLdflags.py b/src/python/jw/pkg/cmds/projects/CmdLdflags.py index 762df6fa..3a59c21e 100644 --- a/src/python/jw/pkg/cmds/projects/CmdLdflags.py +++ b/src/python/jw/pkg/cmds/projects/CmdLdflags.py @@ -3,6 +3,7 @@ from argparse import Namespace, ArgumentParser from ..Cmd import Cmd +from ...App import Scope class CmdLdflags(Cmd): # export @@ -19,7 +20,7 @@ class CmdLdflags(Cmd): # export # -L needs to contain more paths than libs linked with -l would require def __get_ldpathflags(self, names: list[str], exclude: list[str] = []) -> str: deps = self.app.get_modules_from_project_txt(names, ['pkg.requires.jw'], 'build', - scope = 2, add_self=True, names_only=True) + scope = Scope.Subtree, add_self=True, names_only=True) ret = [] for m in deps: if m in exclude: @@ -37,7 +38,7 @@ class CmdLdflags(Cmd): # export def _run(self, args: Namespace) -> None: deps = self.app.get_modules_from_project_txt(args.module, ['pkg.requires.jw'], 'build', - scope = 1, add_self=args.add_self, names_only=True) + scope = Scope.One, add_self=args.add_self, names_only=True) out = [] for m in reversed(deps): if m in args.exclude: diff --git a/src/python/jw/pkg/cmds/projects/CmdLdlibpath.py b/src/python/jw/pkg/cmds/projects/CmdLdlibpath.py index e3aa59b2..1f3031cf 100644 --- a/src/python/jw/pkg/cmds/projects/CmdLdlibpath.py +++ b/src/python/jw/pkg/cmds/projects/CmdLdlibpath.py @@ -3,6 +3,7 @@ from argparse import Namespace, ArgumentParser from ..Cmd import Cmd +from ...App import Scope class CmdLdlibpath(Cmd): # export @@ -15,7 +16,7 @@ class CmdLdlibpath(Cmd): # export def _run(self, args: Namespace) -> None: deps = self.app.get_modules_from_project_txt(args.module, ['pkg.requires.jw'], [ 'run', 'build', 'devel' ], - scope = 2, add_self=True, names_only=True) + scope = Scope.Subtree, add_self=True, names_only=True) out = [] for m in deps: path = self.app.find_dir(m, ['/lib']) diff --git a/src/python/jw/pkg/cmds/projects/CmdPath.py b/src/python/jw/pkg/cmds/projects/CmdPath.py index d50b1cbc..a09da9d5 100644 --- a/src/python/jw/pkg/cmds/projects/CmdPath.py +++ b/src/python/jw/pkg/cmds/projects/CmdPath.py @@ -3,6 +3,7 @@ from argparse import Namespace, ArgumentParser from ..Cmd import Cmd +from ...App import Scope class CmdPath(Cmd): # export @@ -15,7 +16,7 @@ class CmdPath(Cmd): # export def _run(self, args: Namespace) -> None: deps = self.app.get_modules_from_project_txt(args.module, ['pkg.requires.jw'], 'run', - scope = 2, add_self=True, names_only=True) + scope = Scope.Subtree, add_self=True, names_only=True) out = [] for m in deps: path = self.app.find_dir(m, '/bin') diff --git a/src/python/jw/pkg/cmds/projects/CmdPrereq.py b/src/python/jw/pkg/cmds/projects/CmdPrereq.py index ef0eed30..dcc1e349 100644 --- a/src/python/jw/pkg/cmds/projects/CmdPrereq.py +++ b/src/python/jw/pkg/cmds/projects/CmdPrereq.py @@ -3,6 +3,7 @@ from argparse import Namespace, ArgumentParser from ..Cmd import Cmd +from ...App import Scope # TODO: seems at least partly redundant to CmdPkgRequires / print_pkg_relations class CmdPrereq(Cmd): # export @@ -17,5 +18,5 @@ class CmdPrereq(Cmd): # export def _run(self, args: Namespace) -> None: deps = self.app.get_modules_from_project_txt(args.module, ['pkg.requires.jw'], - args.flavour, scope = 2, add_self=False, names_only=True) + args.flavour, scope = Scope.Subtree, add_self=False, names_only=True) print(' '.join(deps)) diff --git a/src/python/jw/pkg/cmds/projects/CmdPythonpath.py b/src/python/jw/pkg/cmds/projects/CmdPythonpath.py index b1e127cc..bed466d6 100644 --- a/src/python/jw/pkg/cmds/projects/CmdPythonpath.py +++ b/src/python/jw/pkg/cmds/projects/CmdPythonpath.py @@ -3,6 +3,7 @@ from argparse import Namespace, ArgumentParser from ..Cmd import Cmd +from ...App import Scope class CmdPythonpath(Cmd): # export @@ -15,7 +16,7 @@ class CmdPythonpath(Cmd): # export def _run(self, args: Namespace) -> None: deps = self.app.get_modules_from_project_txt(args.module, ['pkg.requires.jw'], [ 'run', 'build' ], - scope = 2, add_self=True, names_only=True) + scope = Scope.Subtree, add_self=True, names_only=True) out = [] for m in deps: path = self.app.find_dir(m, ['src/python', 'tools/python']) diff --git a/src/python/jw/pkg/cmds/projects/CmdPythonpathOrig.py b/src/python/jw/pkg/cmds/projects/CmdPythonpathOrig.py index 59a25396..fdeb470d 100644 --- a/src/python/jw/pkg/cmds/projects/CmdPythonpathOrig.py +++ b/src/python/jw/pkg/cmds/projects/CmdPythonpathOrig.py @@ -3,6 +3,7 @@ from argparse import Namespace, ArgumentParser from ..Cmd import Cmd +from ...App import Scope class CmdPythonpathOrig(Cmd): # export @@ -15,7 +16,7 @@ class CmdPythonpathOrig(Cmd): # export def _run(self, args: Namespace) -> None: deps = self.app.get_modules_from_project_txt(args.module, ['pkg.requires.jw'], [ 'run', 'build' ], - scope = 2, add_self=True, names_only=True) + scope = Scope.Subtree, add_self=True, names_only=True) r = '' for m in deps: pd = self.app.find_dir(m, pretty=False) diff --git a/src/python/jw/pkg/cmds/projects/CmdRequiredOsPkg.py b/src/python/jw/pkg/cmds/projects/CmdRequiredOsPkg.py index 37cfc36c..297b8b45 100644 --- a/src/python/jw/pkg/cmds/projects/CmdRequiredOsPkg.py +++ b/src/python/jw/pkg/cmds/projects/CmdRequiredOsPkg.py @@ -4,6 +4,7 @@ from argparse import Namespace, ArgumentParser from ...lib.log import * from ..Cmd import Cmd +from ...App import Scope # TODO: seems at least partly redundant to CmdPkgRequires / print_pkg_relations class CmdRequiredOsPkg(Cmd): # export @@ -26,7 +27,7 @@ class CmdRequiredOsPkg(Cmd): # export flavours.append('run') log(DEBUG, "flavours = " + args.flavours) deps = self.app.get_modules_from_project_txt(modules, ['pkg.requires.jw'], flavours, - scope = 2, add_self=True, names_only=True) + scope = Scope.Subtree, add_self=True, names_only=True) if args.skip_excluded: for d in deps: if self.app.is_excluded_from_build(d) is not None: