Skip to content
Snippets Groups Projects
Commit 555a7025 authored by Mateusz Żebrak's avatar Mateusz Żebrak
Browse files

Rename Typer/Textual world and commands to CLI/TUI world and commands

parent b1726d22
No related branches found
No related tags found
2 merge requests!481Release v1.27.5.16,!460Do not hide exceptions catched by ErrorNotificator, reraise CannotNotifyError, use in CLI
...@@ -4,7 +4,7 @@ from dataclasses import dataclass ...@@ -4,7 +4,7 @@ from dataclasses import dataclass
from clive.__private.cli.commands.abc.beekeeper_based_command import BeekeeperCommon from clive.__private.cli.commands.abc.beekeeper_based_command import BeekeeperCommon
from clive.__private.cli.commands.abc.contextual_cli_command import ContextualCLICommand from clive.__private.cli.commands.abc.contextual_cli_command import ContextualCLICommand
from clive.__private.core.beekeeper import Beekeeper from clive.__private.core.beekeeper import Beekeeper
from clive.__private.core.world import TyperWorld, World from clive.__private.core.world import CLIWorld, World
@dataclass(kw_only=True) @dataclass(kw_only=True)
...@@ -23,7 +23,7 @@ class WorldBasedCommand(ContextualCLICommand[World], BeekeeperCommon, ABC): ...@@ -23,7 +23,7 @@ class WorldBasedCommand(ContextualCLICommand[World], BeekeeperCommon, ABC):
return self.world.beekeeper return self.world.beekeeper
async def _create_context_manager_instance(self) -> World: async def _create_context_manager_instance(self) -> World:
return TyperWorld( return CLIWorld(
profile_name=self.profile_name, profile_name=self.profile_name,
use_beekeeper=self.use_beekeeper, use_beekeeper=self.use_beekeeper,
beekeeper_remote_endpoint=self.beekeeper_remote_url, beekeeper_remote_endpoint=self.beekeeper_remote_url,
......
...@@ -66,7 +66,7 @@ if TYPE_CHECKING: ...@@ -66,7 +66,7 @@ if TYPE_CHECKING:
AnyErrorHandlerContextManager, AnyErrorHandlerContextManager,
) )
from clive.__private.core.keys import PrivateKeyAliased, PublicKey, PublicKeyAliased from clive.__private.core.keys import PrivateKeyAliased, PublicKey, PublicKeyAliased
from clive.__private.core.world import TextualWorld, TyperWorld, World from clive.__private.core.world import CLIWorld, TUIWorld, World
from clive.__private.models import Transaction from clive.__private.models import Transaction
from clive.__private.models.schemas import ( from clive.__private.models.schemas import (
Account, Account,
...@@ -469,13 +469,13 @@ class Commands(Generic[WorldT_co]): ...@@ -469,13 +469,13 @@ class Commands(Generic[WorldT_co]):
return CommandWrapper(command=command, error=error) return CommandWrapper(command=command, error=error)
class TyperCommands(Commands["TyperWorld"]): class CLICommands(Commands["CLIWorld"]):
def __init__(self, world: TyperWorld) -> None: def __init__(self, world: CLIWorld) -> None:
super().__init__(world, exception_handlers=[CommunicationFailureNotificator, GeneralErrorNotificator]) super().__init__(world, exception_handlers=[CommunicationFailureNotificator, GeneralErrorNotificator])
class TextualCommands(Commands["TextualWorld"], CliveDOMNode): class TUICommands(Commands["TUIWorld"], CliveDOMNode):
def __init__(self, world: TextualWorld) -> None: def __init__(self, world: TUIWorld) -> None:
super().__init__(world, exception_handlers=[CommunicationFailureNotificator, GeneralErrorNotificator]) super().__init__(world, exception_handlers=[CommunicationFailureNotificator, GeneralErrorNotificator])
async def unlock(self, *, password: str, time: timedelta | None = None, permanent: bool = False) -> CommandWrapper: async def unlock(self, *, password: str, time: timedelta | None = None, permanent: bool = False) -> CommandWrapper:
......
...@@ -8,7 +8,7 @@ from textual.reactive import var ...@@ -8,7 +8,7 @@ from textual.reactive import var
from clive.__private.core.app_state import AppState from clive.__private.core.app_state import AppState
from clive.__private.core.beekeeper import Beekeeper from clive.__private.core.beekeeper import Beekeeper
from clive.__private.core.commands.commands import Commands, TextualCommands, TyperCommands from clive.__private.core.commands.commands import CLICommands, Commands, TUICommands
from clive.__private.core.communication import Communication from clive.__private.core.communication import Communication
from clive.__private.core.node.node import Node from clive.__private.core.node.node import Node
from clive.__private.core.profile import Profile from clive.__private.core.profile import Profile
...@@ -140,7 +140,7 @@ class World: ...@@ -140,7 +140,7 @@ class World:
self.app_state.lock() self.app_state.lock()
class TextualWorld(World, ManualReactive): class TUIWorld(World, ManualReactive):
profile: Profile = var(None) # type: ignore[assignment] profile: Profile = var(None) # type: ignore[assignment]
app_state: AppState = var(None) # type: ignore[assignment] app_state: AppState = var(None) # type: ignore[assignment]
node: Node = var(None) # type: ignore[assignment] node: Node = var(None) # type: ignore[assignment]
...@@ -163,8 +163,8 @@ class TextualWorld(World, ManualReactive): ...@@ -163,8 +163,8 @@ class TextualWorld(World, ManualReactive):
return profile return profile
@property @property
def commands(self) -> TextualCommands: def commands(self) -> TUICommands:
return cast(TextualCommands, super().commands) return cast(TUICommands, super().commands)
@property @property
def is_in_onboarding_mode(self) -> bool: def is_in_onboarding_mode(self) -> bool:
...@@ -173,8 +173,8 @@ class TextualWorld(World, ManualReactive): ...@@ -173,8 +173,8 @@ class TextualWorld(World, ManualReactive):
def _is_in_onboarding_mode(self, profile: Profile) -> bool: def _is_in_onboarding_mode(self, profile: Profile) -> bool:
return profile.name == Onboarding.ONBOARDING_PROFILE_NAME return profile.name == Onboarding.ONBOARDING_PROFILE_NAME
def _setup_commands(self) -> TextualCommands: def _setup_commands(self) -> TUICommands:
return TextualCommands(self) return TUICommands(self)
def notify_wallet_closing(self) -> None: def notify_wallet_closing(self) -> None:
super().notify_wallet_closing() super().notify_wallet_closing()
...@@ -186,13 +186,13 @@ class TextualWorld(World, ManualReactive): ...@@ -186,13 +186,13 @@ class TextualWorld(World, ManualReactive):
self.app.trigger_app_state_watchers() self.app.trigger_app_state_watchers()
class TyperWorld(World): class CLIWorld(World):
@property @property
def commands(self) -> TyperCommands: def commands(self) -> CLICommands:
return cast(TyperCommands, super().commands) return cast(CLICommands, super().commands)
def _setup_commands(self) -> TyperCommands: def _setup_commands(self) -> CLICommands:
return TyperCommands(self) return CLICommands(self)
def _load_profile(self, profile_name: str | None) -> Profile: def _load_profile(self, profile_name: str | None) -> Profile:
return Profile.load(profile_name, auto_create=False) return Profile.load(profile_name, auto_create=False)
...@@ -16,7 +16,7 @@ from textual.notifications import Notification, Notify, SeverityLevel ...@@ -16,7 +16,7 @@ from textual.notifications import Notification, Notify, SeverityLevel
from textual.reactive import var from textual.reactive import var
from clive.__private.core.constants.terminal import TERMINAL_HEIGHT, TERMINAL_WIDTH from clive.__private.core.constants.terminal import TERMINAL_HEIGHT, TERMINAL_WIDTH
from clive.__private.core.world import TextualWorld from clive.__private.core.world import TUIWorld
from clive.__private.logger import logger from clive.__private.logger import logger
from clive.__private.settings import safe_settings from clive.__private.settings import safe_settings
from clive.__private.ui.get_css import get_relative_css_path from clive.__private.ui.get_css import get_relative_css_path
...@@ -75,7 +75,7 @@ class Clive(App[int], ManualReactive): ...@@ -75,7 +75,7 @@ class Clive(App[int], ManualReactive):
is_launched: ClassVar[bool] = False is_launched: ClassVar[bool] = False
"""Whether the Clive app is currently launched.""" """Whether the Clive app is currently launched."""
world: ClassVar[TextualWorld] = None # type: ignore[assignment] world: ClassVar[TUIWorld] = None # type: ignore[assignment]
notification_history: list[Notification] = var([], init=False) # type: ignore[assignment] notification_history: list[Notification] = var([], init=False) # type: ignore[assignment]
"""A list of all notifications that were displayed.""" """A list of all notifications that were displayed."""
...@@ -130,7 +130,7 @@ class Clive(App[int], ManualReactive): ...@@ -130,7 +130,7 @@ class Clive(App[int], ManualReactive):
auto_pilot: AutopilotCallbackType | None = None, auto_pilot: AutopilotCallbackType | None = None,
) -> int | None: ) -> int | None:
try: try:
async with TextualWorld() as world: async with TUIWorld() as world:
self.__class__.world = world self.__class__.world = world
return await super().run_async( return await super().run_async(
headless=headless, headless=headless,
...@@ -157,7 +157,7 @@ class Clive(App[int], ManualReactive): ...@@ -157,7 +157,7 @@ class Clive(App[int], ManualReactive):
message_hook: Callable[[Message], None] | None = None, message_hook: Callable[[Message], None] | None = None,
) -> AsyncGenerator[ClivePilot, None]: ) -> AsyncGenerator[ClivePilot, None]:
try: try:
async with TextualWorld() as world: async with TUIWorld() as world:
self.__class__.world = world self.__class__.world = world
async with super().run_test( async with super().run_test(
headless=headless, headless=headless,
......
...@@ -12,10 +12,10 @@ if TYPE_CHECKING: ...@@ -12,10 +12,10 @@ if TYPE_CHECKING:
from textual.binding import Binding from textual.binding import Binding
from clive.__private.core.app_state import AppState from clive.__private.core.app_state import AppState
from clive.__private.core.commands.commands import TextualCommands from clive.__private.core.commands.commands import TUICommands
from clive.__private.core.node import Node from clive.__private.core.node import Node
from clive.__private.core.profile import Profile from clive.__private.core.profile import Profile
from clive.__private.core.world import TextualWorld from clive.__private.core.world import TUIWorld
class CliveWidget(CliveDOMNode, Widget): class CliveWidget(CliveDOMNode, Widget):
...@@ -26,7 +26,7 @@ class CliveWidget(CliveDOMNode, Widget): ...@@ -26,7 +26,7 @@ class CliveWidget(CliveDOMNode, Widget):
""" """
@property @property
def world(self) -> TextualWorld: def world(self) -> TUIWorld:
return self.app.world return self.app.world
@property @property
...@@ -38,7 +38,7 @@ class CliveWidget(CliveDOMNode, Widget): ...@@ -38,7 +38,7 @@ class CliveWidget(CliveDOMNode, Widget):
return self.world.app_state return self.world.app_state
@property @property
def commands(self) -> TextualCommands: def commands(self) -> TUICommands:
return self.world.commands return self.world.commands
@property @property
......
...@@ -27,7 +27,7 @@ if TYPE_CHECKING: ...@@ -27,7 +27,7 @@ if TYPE_CHECKING:
from clive.__private.core.accounts.accounts import TrackedAccount from clive.__private.core.accounts.accounts import TrackedAccount
from clive.__private.core.alarms.alarm import AnyAlarm from clive.__private.core.alarms.alarm import AnyAlarm
from clive.__private.core.profile import Profile from clive.__private.core.profile import Profile
from clive.__private.core.world import TextualWorld from clive.__private.core.world import TUIWorld
from clive.__private.ui.screens.account_details.alarms.alarm_fix_details import AlarmFixDetails from clive.__private.ui.screens.account_details.alarms.alarm_fix_details import AlarmFixDetails
...@@ -64,7 +64,7 @@ class AlarmsTable(CliveCheckerboardTable): ...@@ -64,7 +64,7 @@ class AlarmsTable(CliveCheckerboardTable):
return NoContentAvailable("Account has no alarms") return NoContentAvailable("Account has no alarms")
@property @property
def object_to_watch(self) -> TextualWorld: def object_to_watch(self) -> TUIWorld:
return self.world return self.world
def check_if_should_be_updated(self, content: Profile) -> bool: def check_if_should_be_updated(self, content: Profile) -> bool:
......
...@@ -18,7 +18,7 @@ from clive.__private.ui.widgets.no_content_available import NoContentAvailable ...@@ -18,7 +18,7 @@ from clive.__private.ui.widgets.no_content_available import NoContentAvailable
if TYPE_CHECKING: if TYPE_CHECKING:
from clive.__private.core.accounts.accounts import Account, KnownAccount, TrackedAccount from clive.__private.core.accounts.accounts import Account, KnownAccount, TrackedAccount
from clive.__private.core.profile import Profile from clive.__private.core.profile import Profile
from clive.__private.core.world import TextualWorld from clive.__private.core.world import TUIWorld
from clive.__private.core.accounts.accounts import WorkingAccount from clive.__private.core.accounts.accounts import WorkingAccount
AccountsType = Literal["known_accounts", "tracked_accounts"] AccountsType = Literal["known_accounts", "tracked_accounts"]
...@@ -108,7 +108,7 @@ class ManageAccountsTable(CliveCheckerboardTable): ...@@ -108,7 +108,7 @@ class ManageAccountsTable(CliveCheckerboardTable):
) )
@property @property
def object_to_watch(self) -> TextualWorld: def object_to_watch(self) -> TUIWorld:
return self.world return self.world
def update_previous_state(self, content: Profile) -> None: def update_previous_state(self, content: Profile) -> None:
......
...@@ -3,7 +3,7 @@ from __future__ import annotations ...@@ -3,7 +3,7 @@ from __future__ import annotations
import pytest import pytest
from clive.__private.core.profile import Profile from clive.__private.core.profile import Profile
from clive.__private.core.world import TyperWorld, World from clive.__private.core.world import CLIWorld, World
from clive.__private.storage.service import NoDefaultProfileToLoadError, ProfileDoesNotExistsError from clive.__private.storage.service import NoDefaultProfileToLoadError, ProfileDoesNotExistsError
...@@ -76,7 +76,7 @@ async def test_if_default_profile_is_loaded_other_was_saved() -> None: ...@@ -76,7 +76,7 @@ async def test_if_default_profile_is_loaded_other_was_saved() -> None:
assert Profile.list_profiles() == [default_profile_name, additional_profile_name] assert Profile.list_profiles() == [default_profile_name, additional_profile_name]
@pytest.mark.parametrize("world_cls", [World, TyperWorld]) @pytest.mark.parametrize("world_cls", [World, CLIWorld])
def test_loading_profile_without_given_name_when_no_default_set(world_cls: type[World]) -> None: def test_loading_profile_without_given_name_when_no_default_set(world_cls: type[World]) -> None:
# ACT & ASSERT # ACT & ASSERT
with pytest.raises(NoDefaultProfileToLoadError): with pytest.raises(NoDefaultProfileToLoadError):
...@@ -90,8 +90,8 @@ def test_loading_non_existing_profile_with_auto_create_disabled() -> None: ...@@ -90,8 +90,8 @@ def test_loading_non_existing_profile_with_auto_create_disabled() -> None:
# ACT & ASSERT # ACT & ASSERT
with pytest.raises(ProfileDoesNotExistsError) as error: with pytest.raises(ProfileDoesNotExistsError) as error:
# TyperWorld should have auto_create disabled by default # CLIWorld should have auto_create disabled by default
TyperWorld(profile_name) CLIWorld(profile_name)
assert exception_message in str(error.value) assert exception_message in str(error.value)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment