Shorten Module.orchestrator and Orchestrator.console
`Orchestrator.console` was shortened to `Orchestrator.c` for convenience so that a function `@module def foo(o: Orchestrator, ...)` can just use `o.c.print` instead of `o.console.print`. Existing `class Foo(Module)` should still use `self.c` like before. Module.orchestrator was shortened to Module.o for convenience and consistency with `Module.c`.
This commit is contained in:
parent
5bb1105f38
commit
442f389b36
3 changed files with 10 additions and 15 deletions
|
|
@ -113,7 +113,7 @@ class Files(Module):
|
|||
) -> None:
|
||||
super().__init__(orchestrator)
|
||||
self._files: dict[str, bytes] = {}
|
||||
self._file_db = FileDb(self.orchestrator.state_dir / file_db_name)
|
||||
self._file_db = FileDb(self.o.state_dir / file_db_name)
|
||||
self._root = root or Path.home()
|
||||
|
||||
def _read_path(self, path: Path | str) -> Path:
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ class Pacman(Module):
|
|||
return self._resolve_packages(groups, packages)
|
||||
|
||||
def _install_packages(self, packages: set[str]) -> None:
|
||||
if self.orchestrator.dry_run:
|
||||
if self.o.dry_run:
|
||||
return
|
||||
|
||||
if packages:
|
||||
|
|
@ -88,7 +88,7 @@ class Pacman(Module):
|
|||
self._pacman_execute("-D", "--asexplicit", *sorted(packages))
|
||||
|
||||
def _uninstall_packages(self, packages: set[str]) -> None:
|
||||
if self.orchestrator.dry_run:
|
||||
if self.o.dry_run:
|
||||
return
|
||||
|
||||
if packages:
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ from xdg_base_dirs import xdg_state_home
|
|||
|
||||
class Module(ABC):
|
||||
def __init__(self, orchestrator: Orchestrator) -> None:
|
||||
self.orchestrator = orchestrator
|
||||
self.orchestrator.register(self)
|
||||
self.c = self.orchestrator.console
|
||||
self.o = orchestrator
|
||||
self.o.register(self)
|
||||
self.c = self.o.c
|
||||
|
||||
@abstractmethod
|
||||
def realize(self) -> None: ...
|
||||
|
|
@ -29,19 +29,14 @@ def _snake_to_camel(s: str) -> str:
|
|||
def module[**P](
|
||||
func: Callable[Concatenate[Orchestrator, P], None],
|
||||
) -> Callable[Concatenate[Orchestrator, P], None]:
|
||||
def __init__(
|
||||
self,
|
||||
orchestrator: Orchestrator,
|
||||
*args: P.args,
|
||||
**kwargs: P.kwargs,
|
||||
) -> None:
|
||||
super(self.__class__, self).__init__(orchestrator)
|
||||
def __init__(self, o: Orchestrator, *args: P.args, **kwargs: P.kwargs) -> None:
|
||||
super(self.__class__, self).__init__(o)
|
||||
self.args = args
|
||||
self.kwargs = kwargs
|
||||
|
||||
def realize(self) -> None:
|
||||
# pyrefly: ignore
|
||||
return func(self.orchestrator, *self.args, **self.kwargs)
|
||||
return func(self.o, *self.args, **self.kwargs)
|
||||
|
||||
# pyrefly: ignore
|
||||
return type(
|
||||
|
|
@ -57,7 +52,7 @@ class Orchestrator:
|
|||
self.dry_run = dry_run
|
||||
|
||||
self.state_dir = xdg_state_home() / self.name
|
||||
self.console = Console(highlight=False)
|
||||
self.c = Console(highlight=False)
|
||||
|
||||
self.user = getpass.getuser()
|
||||
self.host = socket.gethostname()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue