App: Heave package filter into lib.ExecApp
The --pkg-filter flag and the JW_DEFAULT_PKG_FILTER env read live in the jw.pkg.App, but the filter could have its merits in every application deriving from lib.ExecApp, so heave the package filter machinery into ExecApp: flag, filter resolution and the cached pkg_filter property. Then have jw.pkg.App use self.pkg_filter. Signed-off-by: Jan Lindemann <jan@janware.com> Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
This commit is contained in:
parent
53c45e11de
commit
9778f7f330
2 changed files with 31 additions and 22 deletions
|
|
@ -23,8 +23,6 @@ if TYPE_CHECKING:
|
|||
from argparse import ArgumentParser
|
||||
from typing import Iterable, TypeAlias
|
||||
|
||||
from .lib.PackageFilter import PackageFilter
|
||||
|
||||
# Meaning of pkg.requires.xxx variables
|
||||
# build: needs to be built and installed before this can be built
|
||||
# devel: needs to be installed before this-devel can be installed,
|
||||
|
|
@ -388,18 +386,10 @@ class App(Base):
|
|||
|
||||
async def __init_async(self) -> None:
|
||||
if self.__distro is None:
|
||||
pkg_filter_str = self.args.pkg_filter
|
||||
if pkg_filter_str is None:
|
||||
pkg_filter_str = os.getenv('JW_DEFAULT_PKG_FILTER')
|
||||
pkg_filter: PackageFilter | None = None
|
||||
if pkg_filter_str is not None:
|
||||
from .lib.PackageFilter import PackageFilterString
|
||||
|
||||
pkg_filter = PackageFilterString(pkg_filter_str)
|
||||
self.__distro = await Distro.instantiate(
|
||||
ec = self.exec_context,
|
||||
id = self.args.distro_id,
|
||||
default_pkg_filter = pkg_filter,
|
||||
default_pkg_filter = self.pkg_filter,
|
||||
)
|
||||
|
||||
@override
|
||||
|
|
@ -425,10 +415,6 @@ class App(Base):
|
|||
default = None,
|
||||
help = 'Distribution ID (default is taken from /etc/os-release)',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--pkg-filter',
|
||||
help = 'Default filter for all distribution package-related operations',
|
||||
)
|
||||
|
||||
@override
|
||||
async def _run(self, args: argparse.Namespace) -> None:
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
from typing import TYPE_CHECKING, Any, override
|
||||
from typing import TYPE_CHECKING, Any, Literal, override
|
||||
|
||||
from .App import App as Base
|
||||
|
||||
|
|
@ -11,6 +12,7 @@ if TYPE_CHECKING:
|
|||
from argparse import ArgumentParser
|
||||
|
||||
from .ExecContext import ExecContext
|
||||
from .PackageFilter import PackageFilter
|
||||
|
||||
class ExecApp(Base): # export
|
||||
|
||||
|
|
@ -19,6 +21,7 @@ class ExecApp(Base): # export
|
|||
self.__opt_interactive: bool | None = None
|
||||
self.__opt_verbose: bool | None = None
|
||||
self.__exec_context: ExecContext | None = None
|
||||
self.__pkg_filter: PackageFilter | None | Literal[False] = None
|
||||
|
||||
@override
|
||||
async def __aexit__(self, exc_type: Any, exc: Any, tb: Any) -> None:
|
||||
|
|
@ -47,6 +50,10 @@ class ExecApp(Base): # export
|
|||
parser.add_argument(
|
||||
'--target', default = 'local', help = 'Run commands on this host'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--pkg-filter',
|
||||
help = 'Default filter for all distribution package-related operations',
|
||||
)
|
||||
|
||||
@property
|
||||
def interactive(self) -> bool:
|
||||
|
|
@ -74,6 +81,22 @@ class ExecApp(Base): # export
|
|||
assert self.__opt_verbose is not None
|
||||
return self.__opt_verbose
|
||||
|
||||
@property
|
||||
def pkg_filter(self) -> PackageFilter | None:
|
||||
if self.__pkg_filter is None:
|
||||
spec = self.args.pkg_filter
|
||||
if spec is None:
|
||||
spec = os.getenv('JW_DEFAULT_PKG_FILTER')
|
||||
if spec is None:
|
||||
self.__pkg_filter = False
|
||||
else:
|
||||
from .PackageFilter import PackageFilterString
|
||||
|
||||
self.__pkg_filter = PackageFilterString(spec)
|
||||
if not self.__pkg_filter:
|
||||
return None
|
||||
return self.__pkg_filter
|
||||
|
||||
@property
|
||||
def exec_context(self) -> ExecContext:
|
||||
if self.__exec_context is None:
|
||||
|
|
|
|||
Loading…
Reference in a new issue