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:
parent
7a65a7b5e1
commit
5d1ba6e15a
77 changed files with 382 additions and 196 deletions
|
|
@ -1,19 +1,19 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from argparse import ArgumentParser
|
||||
from functools import cached_property
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from ...CmdBase import CmdBase
|
||||
from ...CmdBase import CmdBase as Base
|
||||
from ..CmdSecrets import CmdSecrets as Parent
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Iterable
|
||||
from .lib.base import Attrs
|
||||
|
||||
from .lib.DistroContext import DistroContext
|
||||
|
||||
class Cmd(CmdBase): # export
|
||||
if TYPE_CHECKING:
|
||||
from argparse import ArgumentParser
|
||||
from typing import Iterable
|
||||
|
||||
from .lib.base import Attrs
|
||||
|
||||
class Cmd(Base): # export
|
||||
|
||||
@cached_property
|
||||
def ctx(self) -> DistroContext:
|
||||
|
|
@ -49,3 +49,5 @@ class Cmd(CmdBase): # export
|
|||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
super().add_arguments(parser)
|
||||
parser.add_argument('packages', nargs = '*', help = 'Package names')
|
||||
|
||||
__all__ = ['Parent', 'Cmd']
|
||||
|
|
|
|||
|
|
@ -2,17 +2,15 @@ from __future__ import annotations
|
|||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from .Cmd import Cmd
|
||||
from .Cmd import Cmd, Parent
|
||||
from .lib.base import Attrs
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
from ..CmdSecrets import CmdSecrets
|
||||
|
||||
class CmdCompileTemplates(Cmd): # export
|
||||
|
||||
def __init__(self, parent: CmdSecrets) -> None:
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(
|
||||
parent, 'compile-templates', help = 'Compile package template files'
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,16 +2,14 @@ from __future__ import annotations
|
|||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from .Cmd import Cmd
|
||||
from .Cmd import Cmd, Parent
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
from ..CmdSecrets import CmdSecrets
|
||||
|
||||
class CmdInstall(Cmd): # export
|
||||
|
||||
def __init__(self, parent: CmdSecrets) -> None:
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(
|
||||
parent,
|
||||
'install',
|
||||
|
|
|
|||
|
|
@ -2,16 +2,14 @@ from __future__ import annotations
|
|||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from .Cmd import Cmd
|
||||
from .Cmd import Cmd, Parent
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
from ..CmdSecrets import CmdSecrets
|
||||
|
||||
class CmdListCompilationOutput(Cmd): # export
|
||||
|
||||
def __init__(self, parent: CmdSecrets) -> None:
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(
|
||||
parent,
|
||||
'list-compilation-output',
|
||||
|
|
|
|||
|
|
@ -2,16 +2,14 @@ from __future__ import annotations
|
|||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from .Cmd import Cmd
|
||||
from .Cmd import Cmd, Parent
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
from ..CmdSecrets import CmdSecrets
|
||||
|
||||
class CmdListSecrets(Cmd): # export
|
||||
|
||||
def __init__(self, parent: CmdSecrets) -> None:
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(parent, 'list-secrets', help = 'List package secret files')
|
||||
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
|
|
|
|||
|
|
@ -2,16 +2,14 @@ from __future__ import annotations
|
|||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from .Cmd import Cmd
|
||||
from .Cmd import Cmd, Parent
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from argparse import Namespace
|
||||
|
||||
from ..CmdSecrets import CmdSecrets
|
||||
|
||||
class CmdListTemplates(Cmd): # export
|
||||
|
||||
def __init__(self, parent: CmdSecrets) -> None:
|
||||
def __init__(self, parent: Parent) -> None:
|
||||
super().__init__(parent, 'list-templates', help = 'List package template files')
|
||||
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@ from typing import TYPE_CHECKING
|
|||
|
||||
from ....lib.log import DEBUG, NOTICE, WARNING, log
|
||||
from ....lib.ProcFilterGpg import ProcFilterGpg
|
||||
from .base import Attrs
|
||||
from .FilesContext import FilesContext
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .base import Attrs
|
||||
from typing import Iterable
|
||||
|
||||
from ....lib.Distro import Distro
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@ from tarfile import TarFile
|
|||
from typing import TYPE_CHECKING, Callable
|
||||
|
||||
from ....lib.log import DEBUG, log
|
||||
from ....lib.ExecContext import ExecContext
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Iterable
|
||||
|
||||
from ....lib.ExecContext import ExecContext
|
||||
from ....lib.FileContext import FileContext
|
||||
|
||||
def filter(
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@ from __future__ import annotations
|
|||
from typing import TYPE_CHECKING
|
||||
|
||||
from ....lib.ec.Local import Local
|
||||
from ....lib.FileContext import FileContext
|
||||
from .FilesContext import FilesContext
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ....lib.FileContext import FileContext
|
||||
from .base import Attrs
|
||||
|
||||
async def compile_template_file(
|
||||
|
|
|
|||
Loading…
Reference in a new issue