jw-pkg/src/python/jw/pkg/cmds/projects/BaseCmdPkgRelations.py
Jan Lindemann 5fa008be5a
App, lib, cmds: Fix mypy.explicit-override fallout
This commit adds @override decorators to approximately 300 methods
across 76 files that inherit from base classes such as AbstractCmd,
FileContext, ExecContext, Distro, SSHClient, and others.

The decorator ensures the type checker can verify that overridden
methods have compatible signatures and prevents accidental shadowing
of inherited methods without intent.

Files modified include command classes, library modules, distro
implementations, and SSH client implementations.

Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-07 18:02:26 +02:00

149 lines
5 KiB
Python

from __future__ import annotations
import re
from typing import TYPE_CHECKING, override
from .Cmd import Cmd, Parent
from .lib.pkg_relations import VersionSyntax
from .lib.pkg_relations import pkg_relations as pkg_relations_list
if TYPE_CHECKING:
from argparse import ArgumentParser, Namespace
class BaseCmdPkgRelations(Cmd):
arg_sep = r'[,\s|]'
def pkg_relations(self, rel_type: str, args: Namespace) -> str:
return args.delimiter.join(
pkg_relations_list(
self.app,
rel_type = rel_type,
flavours = re.split(self.arg_sep, args.flavours),
seed_pkgs = args.modules,
subsections = (
None if args.subsections is None else
re.split(self.arg_sep, args.subsections)
),
no_subpackages = args.no_subpackages,
dont_strip_revision = args.dont_strip_revision,
expand_semver_revision_range = args.expand_semver_revision_range,
syntax = VersionSyntax[args.syntax.replace('-', '_')],
recursive = args.recursive,
dont_expand_version_macros = args.dont_expand_version_macros,
ignore = set(re.split(self.arg_sep, args.ignore)),
quote = args.quote,
skip_excluded = args.skip_excluded,
hide_self = args.hide_self,
hide_jw_pkg = args.hide_jw_pkg,
)
)
def print_pkg_relations(self, rel_type: str, args: Namespace) -> None:
print(self.pkg_relations(rel_type, args))
def __init__(self, parent: Parent, relation: str, help: str) -> None:
super().__init__(parent, 'pkg-' + relation, help = help)
self.relation = relation
@override
def add_arguments(self, parser: ArgumentParser) -> None:
super().add_arguments(parser)
parser.add_argument(
'-S',
'--subsections',
nargs = '?',
default = None,
help = 'Subsections to consider, separated by comma or whitespace',
)
parser.add_argument(
'-d',
'--delimiter',
nargs = '?',
default = ', ',
help = 'Output words delimiter'
)
parser.add_argument(
'flavours',
help = 'Dependency flavours (run, build, devel, release), '
'separated by comma or whitespace'
)
parser.add_argument('modules', nargs = '*', help = 'Modules')
parser.add_argument(
'-p',
'--no-subpackages',
action = 'store_true',
default = False,
help = 'Cut -run and -devel from package names',
)
parser.add_argument(
'--dont-strip-revision',
action = 'store_true',
default = False,
help = 'Always treat VERSION macro as VERSION-REVISION',
)
parser.add_argument(
'--expand-semver-revision-range',
action = 'store_true',
default = False,
help = 'Always treat =VERSION macro as >= VERSION-0 and < (VERSION+1)-0',
)
parser.add_argument(
'--syntax',
choices = ['semver', 'debian', 'names-only'],
default = 'semver',
help = 'Output syntax',
)
parser.add_argument(
'--recursive',
action = 'store_true',
default = False,
help = 'Find dependencies recursively',
)
parser.add_argument(
'--dont-expand-version-macros',
action = 'store_true',
default = False,
help = "Don't expand VERSION and REVISION macros",
)
parser.add_argument(
'--ignore',
nargs = '?',
default = '',
help = 'Packages that should be ignored together with their dependencies',
)
parser.add_argument(
'--skip-excluded',
action = 'store_true',
default = False,
help = (
"Don't consider or output modules matching the os cascade in their "
'[build].exclude config'
),
)
parser.add_argument(
'--hide-self',
action = 'store_true',
default = False,
help = "Don't include projects listed in <modules> in the output",
)
parser.add_argument(
'--hide-jw-pkg',
action = 'store_true',
default = False,
help = "Don't include packages from requires.jw in the output",
)
parser.add_argument(
'--quote',
action = 'store_true',
default = False,
help = 'Put double quotes around each listed dependency',
)
@override
async def _run(self, args: Namespace) -> None:
return self.print_pkg_relations(self.relation, args)
__all__ = ['Parent', 'BaseCmdPkgRelations']