Add new ruff rules and fix their fallout:
future-annotations = true
select = [
"TC", # type-checking import placement rules
"FA", # future annotations rules
]
This comprises:
- Streamline imports and exports in cmds.xxx.Cmd
- Import base class as "Base"
- Export types Cmd and Parent via __all__
- Move all types imported only for annotation below TYPE_CHECKING
- Use "from __future__ import annotations" all over the place
Signed-off-by: Jan Lindemann <jan@janware.com>
70 lines
2.5 KiB
Python
70 lines
2.5 KiB
Python
from __future__ import annotations
|
|
|
|
from ...App import Scope
|
|
from ...lib.log import DEBUG, log
|
|
from .Cmd import Cmd, Parent
|
|
from typing import TYPE_CHECKING
|
|
|
|
if TYPE_CHECKING:
|
|
from argparse import ArgumentParser, Namespace
|
|
|
|
# TODO: seems at least partly redundant to CmdPkgRequires / print_pkg_relations
|
|
class CmdRequiredOsPkg(Cmd): # export
|
|
|
|
def __init__(self, parent: Parent) -> None:
|
|
super().__init__(
|
|
parent,
|
|
'required-os-pkg',
|
|
help = 'List distribution packages required for a package',
|
|
)
|
|
|
|
def add_arguments(self, parser: ArgumentParser) -> None:
|
|
super().add_arguments(parser)
|
|
parser.add_argument('flavours', help = 'Dependency flavours', default = 'build')
|
|
parser.add_argument('modules', nargs = '*', help = 'Modules')
|
|
parser.add_argument(
|
|
'--skip-excluded',
|
|
action = 'store_true',
|
|
default = False,
|
|
help = 'Output empty prerequisite list for excluded modules',
|
|
)
|
|
parser.add_argument(
|
|
'--quote',
|
|
action = 'store_true',
|
|
default = False,
|
|
help = 'Put double quotes around each listed dependency',
|
|
)
|
|
|
|
async def _run(self, args: Namespace) -> None:
|
|
modules = args.modules
|
|
flavours = set(args.flavours.split(','))
|
|
if 'build' in flavours:
|
|
# TODO: This adds too much. Only the run dependencies of the build
|
|
# dependencies would be needed.
|
|
flavours.add('run')
|
|
if 'release' in flavours:
|
|
flavours |= set(['run', 'devel', 'build'])
|
|
log(DEBUG, 'flavours = ' + args.flavours)
|
|
deps = self.app.get_project_refs(
|
|
modules,
|
|
['pkg.requires.jw'],
|
|
list(flavours),
|
|
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:
|
|
deps.remove(d)
|
|
subsecs = self.app.distro.os_cascade
|
|
log(DEBUG, 'subsecs = ', subsecs)
|
|
requires: set[str] = set()
|
|
for sec in subsecs:
|
|
for flavour in flavours:
|
|
vals = self.app.get_values(deps, ['pkg.requires.' + sec], [flavour])
|
|
if vals:
|
|
requires |= set(vals)
|
|
out = [f'"{dep}"' for dep in requires] if args.quote else requires
|
|
# TODO: add all not in build tree as -devel
|
|
print(' '.join(out))
|