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 <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-01-26 13:13:12 +01:00
commit f6ed191d73
11 changed files with 36 additions and 24 deletions

View file

@ -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: