cmds.projects.CmdBuild: Annotate types
Some checks failed
CI / Packaging - Kali Linux (pull_request) Failing after 1m46s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Failing after 2m1s
CI / Packaging test (pull_request) Failing after 0s

CmdBuild lacks consistent type annotation, add that.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-06-18 11:41:53 +02:00
commit 9623870f9a
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61

View file

@ -1,15 +1,16 @@
from __future__ import annotations
import datetime
import os
import re
from functools import lru_cache
from typing import TYPE_CHECKING
from ...App import Scope
from ...lib.log import DEBUG, ERR, NOTICE, log
from ...lib.util import get_profile_env, pretty_cmd
from .Cmd import Cmd, Parent
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from argparse import ArgumentParser, Namespace
@ -150,7 +151,9 @@ class CmdBuild(Cmd): # export
dep_tree[k].remove(d)
return 1
async def run_make(module, target, cur_project, num_projects) -> None:
async def run_make(
module: str, target: str, cur_project: int, num_projects: int
) -> None:
patt = self.app.is_excluded_from_build(module)
if patt is not None:
@ -194,45 +197,44 @@ class CmdBuild(Cmd): # export
except Exception as e:
log(
ERR,
(
f'Failed to make target "{target}" in module "{module}" '
f'below base {self.app.projs_root}: {str(e)}'
),
f'Failed to make target "{target}" in module "{module}" '
f'below base {self.app.projs_root}: {str(e)}'
)
raise
async def run_make_on_modules(modules, order, target):
async def run_make_on_modules(
modules: set[str], order: list[str], target: str
) -> None:
cur_project = 0
num_projects = len(order)
if target in ['clean', 'distclean']:
for m in reversed(order):
cur_project += 1
await run_make(m, target, cur_project, num_projects)
if m in modules:
modules.remove(m)
if not len(modules):
log(NOTICE, 'All modules cleaned')
return
else:
if target not in ['clean', 'distclean']:
for m in order:
cur_project += 1
await run_make(m, target, cur_project, num_projects)
return
for m in reversed(order):
cur_project += 1
await run_make(m, target, cur_project, num_projects)
if m in modules:
modules.remove(m)
if not len(modules):
log(NOTICE, 'All modules cleaned')
async def run(args):
async def run(args) -> None:
log(DEBUG, f'-------------------------------------- running {pretty_cmd()}')
modules = args.modules
exclude = args.exclude.split()
modules = set(args.modules)
exclude = set(args.exclude.split())
target = args.target
env_exclude = os.getenv('BUILD_EXCLUDE', '')
if len(env_exclude):
log(NOTICE, 'Exluding modules from environment: ' + env_exclude)
exclude += ' ' + env_exclude
if env_exclude is not None:
log(NOTICE, f'Exluding modules from environment: {env_exclude}')
exclude |= set(env_exclude.split())
# -- build
order = []
order: list[str] = []
glob_prereq_types = ['build']
if re.match('pkg-.*', target) is not None:
@ -251,7 +253,7 @@ class CmdBuild(Cmd): # export
exit(0)
cur_project = 0
log(NOTICE, 'Building target %s in %d projects:' % (target, len(order)))
log(NOTICE, f'Building target {target} in {len(order)} projects:')
for m in order:
cur_project += 1
log(NOTICE, ' %3d %s' % (cur_project, m))
@ -263,12 +265,9 @@ class CmdBuild(Cmd): # export
log(
NOTICE,
(
'Build done at %s' %
(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
),
'Build done at %s' %
(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
)
dep_cache: dict[str, dict[str, list[str]]] = {}
await run(args)