pyproject.toml: Enforce import annotations style

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>
This commit is contained in:
Jan Lindemann 2026-06-01 10:04:38 +02:00
commit 5d1ba6e15a
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61
77 changed files with 382 additions and 196 deletions

View file

@ -38,10 +38,14 @@
[tool.ruff.lint] [tool.ruff.lint]
future-annotations = true
select = [ select = [
"F", # Pyflakes, includes F401 "F", # Pyflakes, includes F401
"E", # pycodestyle errors "E", # pycodestyle errors
"W", # pycodestyle warnings "W", # pycodestyle warnings
"TC", # type-checking import placement rules
"FA", # future annotations rules
] ]
ignore = [ ignore = [

View file

@ -4,7 +4,6 @@
from __future__ import annotations from __future__ import annotations
import argparse
import os import os
import pwd import pwd
import re import re
@ -19,10 +18,7 @@ from .lib.Distro import Distro
from .lib.log import DEBUG, ERR, log from .lib.log import DEBUG, ERR, log
if TYPE_CHECKING: if TYPE_CHECKING:
import os import argparse
import pwd
import re
import sys
from typing import TypeAlias from typing import TypeAlias

View file

@ -2,15 +2,15 @@ from __future__ import annotations
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from ..CmdBase import CmdBase from ..App import App as Parent
from ..CmdBase import CmdBase as Base
if TYPE_CHECKING: if TYPE_CHECKING:
from ..App import App
from ..lib.Distro import Distro from ..lib.Distro import Distro
class Cmd(CmdBase): # export class Cmd(Base): # export
def __init__(self, parent: App | CmdBase, name: str, help: str) -> None: def __init__(self, parent: Parent, name: str, help: str) -> None:
super().__init__(parent, name, help) super().__init__(parent, name, help)
async def _run(self, args): async def _run(self, args):
@ -20,3 +20,5 @@ class Cmd(CmdBase): # export
@property @property
def distro(self) -> Distro: def distro(self) -> Distro:
return self.app.distro return self.app.distro
__all__ = ['Parent', 'Cmd']

View file

@ -1,11 +1,15 @@
from argparse import ArgumentParser from __future__ import annotations
from ..App import App from typing import TYPE_CHECKING
from .Cmd import Cmd as CmdBase
class CmdPkg(CmdBase): # export from .Cmd import Cmd, Parent
def __init__(self, parent: App) -> None: if TYPE_CHECKING:
from argparse import ArgumentParser
class CmdPkg(Cmd): # export
def __init__(self, parent: Parent) -> None:
super().__init__(parent, 'pkg', help = 'System package manager wrapper') super().__init__(parent, 'pkg', help = 'System package manager wrapper')
self.load_subcommands() self.load_subcommands()

View file

@ -1,11 +1,15 @@
from argparse import ArgumentParser from __future__ import annotations
from ..App import App from typing import TYPE_CHECKING
from .Cmd import Cmd as CmdBase
class CmdPlatform(CmdBase): # export from .Cmd import Cmd, Parent
def __init__(self, parent: App) -> None: if TYPE_CHECKING:
from argparse import ArgumentParser
class CmdPlatform(Cmd): # export
def __init__(self, parent: Parent) -> None:
super().__init__( super().__init__(
parent, 'platform', help = 'Miscellaneous platform-related comamnds' parent, 'platform', help = 'Miscellaneous platform-related comamnds'
) )

View file

@ -1,11 +1,15 @@
from argparse import ArgumentParser from __future__ import annotations
from ..App import App from typing import TYPE_CHECKING
from .Cmd import Cmd as CmdBase
class CmdPosix(CmdBase): # export from .Cmd import Cmd, Parent
def __init__(self, parent: App) -> None: if TYPE_CHECKING:
from argparse import ArgumentParser
class CmdPosix(Cmd): # export
def __init__(self, parent: Parent) -> None:
super().__init__( super().__init__(
parent, parent,
'posix', 'posix',

View file

@ -1,13 +1,17 @@
from __future__ import annotations
import sys import sys
from argparse import ArgumentParser from typing import TYPE_CHECKING
from ..App import App from .Cmd import Cmd, Parent
from .Cmd import Cmd as CmdBase
class CmdProjects(CmdBase): # export if TYPE_CHECKING:
from argparse import ArgumentParser
def __init__(self, parent: App) -> None: class CmdProjects(Cmd): # export
def __init__(self, parent: Parent) -> None:
super().__init__( super().__init__(
parent, parent,
'projects', 'projects',

View file

@ -1,11 +1,15 @@
from argparse import ArgumentParser from __future__ import annotations
from ..App import App from typing import TYPE_CHECKING
from .Cmd import Cmd as CmdBase
class CmdSecrets(CmdBase): # export from .Cmd import Cmd, Parent
def __init__(self, parent: App) -> None: if TYPE_CHECKING:
from argparse import ArgumentParser
class CmdSecrets(Cmd): # export
def __init__(self, parent: Parent) -> None:
super().__init__(parent, 'secrets', help = 'Manage package secrets') super().__init__(parent, 'secrets', help = 'Manage package secrets')
self.load_subcommands() self.load_subcommands()

View file

@ -2,12 +2,19 @@ from __future__ import annotations
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
if TYPE_CHECKING: from ...CmdBase import CmdBase as Base
from ..CmdPkg import CmdPkg from ..CmdPkg import CmdPkg as Parent
from ..Cmd import Cmd as Base if TYPE_CHECKING:
from ...lib.Distro import Distro
class Cmd(Base): # export class Cmd(Base): # export
def __init__(self, parent: CmdPkg, name: str, help: str) -> None: def __init__(self, parent: Parent, name: str, help: str) -> None:
super().__init__(parent, name, help) super().__init__(parent, name, help)
@property
def distro(self) -> Distro:
return self.app.distro
__all__ = ['Parent', 'Cmd']

View file

@ -1,11 +1,15 @@
from argparse import ArgumentParser, Namespace from __future__ import annotations
from ..CmdPkg import CmdPkg from typing import TYPE_CHECKING
from .Cmd import Cmd
from .Cmd import Cmd, Parent
if TYPE_CHECKING:
from argparse import ArgumentParser, Namespace
class CmdDelete(Cmd): # export class CmdDelete(Cmd): # export
def __init__(self, parent: CmdPkg) -> None: def __init__(self, parent: Parent) -> None:
super().__init__(parent, 'delete', help = 'Delete packages by name') super().__init__(parent, 'delete', help = 'Delete packages by name')
def add_arguments(self, parser: ArgumentParser) -> None: def add_arguments(self, parser: ArgumentParser) -> None:

View file

@ -1,11 +1,15 @@
from argparse import ArgumentParser, Namespace from __future__ import annotations
from ..CmdPkg import CmdPkg from typing import TYPE_CHECKING
from .Cmd import Cmd
from .Cmd import Cmd, Parent
if TYPE_CHECKING:
from argparse import ArgumentParser, Namespace
class CmdDup(Cmd): # export class CmdDup(Cmd): # export
def __init__(self, parent: CmdPkg) -> None: def __init__(self, parent: Parent) -> None:
super().__init__(parent, 'dup', help = 'Upgrade distribution') super().__init__(parent, 'dup', help = 'Upgrade distribution')
def add_arguments(self, parser: ArgumentParser) -> None: def add_arguments(self, parser: ArgumentParser) -> None:

View file

@ -1,11 +1,15 @@
from argparse import ArgumentParser, Namespace from __future__ import annotations
from ..CmdPkg import CmdPkg from typing import TYPE_CHECKING
from .Cmd import Cmd
from .Cmd import Cmd, Parent
if TYPE_CHECKING:
from argparse import ArgumentParser, Namespace
class CmdInstall(Cmd): # export class CmdInstall(Cmd): # export
def __init__(self, parent: CmdPkg) -> None: def __init__(self, parent: Parent) -> None:
super().__init__( super().__init__(
parent, parent,
'install', 'install',

View file

@ -1,11 +1,15 @@
from argparse import ArgumentParser, Namespace from __future__ import annotations
from ..CmdPkg import CmdPkg from typing import TYPE_CHECKING
from .NamedPkgsCmd import NamedPkgsCmd as Base
class CmdLs(Base): # export from .Cmd import Cmd, Parent
def __init__(self, parent: CmdPkg) -> None: if TYPE_CHECKING:
from argparse import ArgumentParser, Namespace
class CmdLs(Cmd): # export
def __init__(self, parent: Parent) -> None:
super().__init__(parent, 'ls', help = 'List package contents') super().__init__(parent, 'ls', help = 'List package contents')
def add_arguments(self, parser: ArgumentParser) -> None: def add_arguments(self, parser: ArgumentParser) -> None:

View file

@ -1,11 +1,15 @@
from argparse import ArgumentParser, Namespace from __future__ import annotations
from ..CmdPkg import CmdPkg from typing import TYPE_CHECKING
from .NamedPkgsCmd import NamedPkgsCmd as Base
class CmdMeta(Base): # export from .NamedPkgsCmd import NamedPkgsCmd, Parent
def __init__(self, parent: CmdPkg) -> None: if TYPE_CHECKING:
from argparse import ArgumentParser, Namespace
class CmdMeta(NamedPkgsCmd): # export
def __init__(self, parent: Parent) -> None:
super().__init__(parent, 'meta', help = 'List package metadata') super().__init__(parent, 'meta', help = 'List package metadata')
def add_arguments(self, parser: ArgumentParser) -> None: def add_arguments(self, parser: ArgumentParser) -> None:

View file

@ -1,11 +1,15 @@
from argparse import ArgumentParser, Namespace from __future__ import annotations
from ..CmdPkg import CmdPkg from typing import TYPE_CHECKING
from .Cmd import Cmd
from .Cmd import Cmd, Parent
if TYPE_CHECKING:
from argparse import ArgumentParser, Namespace
class CmdRebootRequired(Cmd): # export class CmdRebootRequired(Cmd): # export
def __init__(self, parent: CmdPkg) -> None: def __init__(self, parent: Parent) -> None:
super().__init__( super().__init__(
parent, parent,
'reboot-required', 'reboot-required',

View file

@ -1,11 +1,15 @@
from argparse import ArgumentParser, Namespace from __future__ import annotations
from ..CmdPkg import CmdPkg from typing import TYPE_CHECKING
from .Cmd import Cmd
from .Cmd import Cmd, Parent
if TYPE_CHECKING:
from argparse import ArgumentParser, Namespace
class CmdRefresh(Cmd): # export class CmdRefresh(Cmd): # export
def __init__(self, parent: CmdPkg) -> None: def __init__(self, parent: Parent) -> None:
super().__init__( super().__init__(
parent, parent,
'refresh', 'refresh',

View file

@ -1,12 +1,16 @@
from argparse import ArgumentParser, Namespace from __future__ import annotations
from typing import TYPE_CHECKING
from ...lib.PackageFilter import PackageFilterString from ...lib.PackageFilter import PackageFilterString
from ..CmdPkg import CmdPkg from .Cmd import Cmd, Parent
from .Cmd import Cmd
if TYPE_CHECKING:
from argparse import ArgumentParser, Namespace
class CmdSelect(Cmd): # export class CmdSelect(Cmd): # export
def __init__(self, parent: CmdPkg) -> None: def __init__(self, parent: Parent) -> None:
super().__init__(parent, 'select', help = 'Select packages by filter') super().__init__(parent, 'select', help = 'Select packages by filter')
def add_arguments(self, parser: ArgumentParser) -> None: def add_arguments(self, parser: ArgumentParser) -> None:

View file

@ -1,9 +1,13 @@
from argparse import ArgumentParser from __future__ import annotations
from ..CmdPkg import CmdPkg as Parent from typing import TYPE_CHECKING
from .Cmd import Cmd as Base
class NamedPkgsCmd(Base): # export from .Cmd import Cmd, Parent
if TYPE_CHECKING:
from argparse import ArgumentParser
class NamedPkgsCmd(Cmd): # export
def __init__(self, parent: Parent, name: str, help: str) -> None: def __init__(self, parent: Parent, name: str, help: str) -> None:
super().__init__(parent, name, help) super().__init__(parent, name, help)
@ -11,3 +15,5 @@ class NamedPkgsCmd(Base): # export
def add_arguments(self, parser: ArgumentParser) -> None: def add_arguments(self, parser: ArgumentParser) -> None:
super().add_arguments(parser) super().add_arguments(parser)
parser.add_argument('names', nargs = '*', help = 'Package names') parser.add_argument('names', nargs = '*', help = 'Package names')
__all__ = ['NamedPkgsCmd', 'Parent']

View file

@ -1,13 +1,11 @@
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING from ...CmdBase import CmdBase as Base
from ..CmdPlatform import CmdPlatform as Parent
if TYPE_CHECKING:
from ..CmdPlatform import CmdPlatform
from ..Cmd import Cmd as Base
class Cmd(Base): # export class Cmd(Base): # export
def __init__(self, parent: CmdPlatform, name: str, help: str) -> None: def __init__(self, parent: Parent, name: str, help: str) -> None:
super().__init__(parent, name, help) super().__init__(parent, name, help)
__all__ = ['Parent', 'Cmd']

View file

@ -1,12 +1,16 @@
from argparse import ArgumentParser, Namespace from __future__ import annotations
from typing import TYPE_CHECKING
from ...lib.Distro import Distro from ...lib.Distro import Distro
from ..Cmd import Cmd from .Cmd import Cmd, Parent
from ..CmdPlatform import CmdPlatform
if TYPE_CHECKING:
from argparse import ArgumentParser, Namespace
class CmdInfo(Cmd): # export class CmdInfo(Cmd): # export
def __init__(self, parent: CmdPlatform) -> None: def __init__(self, parent: Parent) -> None:
super().__init__( super().__init__(
parent, 'info', help = 'Retrieve information about target platform' parent, 'info', help = 'Retrieve information about target platform'
) )

Some files were not shown because too many files have changed in this diff Show more