Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • hive/clive
1 result
Show changes
Commits on Source (46)
Showing
with 50 additions and 51 deletions
......@@ -112,6 +112,8 @@ build_wheel:
- "**/generated*/"
when: always
expire_in: 7 days
after_script:
- (bash "${CI_PROJECT_DIR}/scripts/check_for_dangling_beekeeper.bash" && echo $?) || (echo $? && false)
testing_beekeeper:
extends: .testing
......
......@@ -32,13 +32,13 @@ repos:
- '@azabraao/prettier-plugin-css-order@1.3.0'
args: [ "--print-width", "120", "--plugin=@azabraao/prettier-plugin-css-order" ]
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.277'
rev: 'v0.2.2'
hooks:
- id: ruff
name: linting code with Ruff
args: [ "--fix" ]
- repo: https://github.com/psf/black
rev: 23.3.0
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.2.0
hooks:
- id: black
name: format code using black
......
......@@ -15,8 +15,7 @@ class BeekeeperCommon(ABC):
@property
@abstractmethod
def beekeeper(self) -> Beekeeper:
...
def beekeeper(self) -> Beekeeper: ...
@property
def beekeeper_remote_url(self) -> Url | None:
......
......@@ -8,6 +8,7 @@ from clive.exceptions import CliveError
class CommonOptionInstanceNotAvailableError(CliveError):
def __init__(self, cls: type["CommonOptionsBase"]) -> None:
self.cls = cls
super().__init__(f"Common option instance of {cls.__name__} not available.")
......
......@@ -61,6 +61,7 @@ class CLIProfileDoesNotExistsError(CLIPrettyError):
class CLIProfileAlreadyExistsError(CLIPrettyError):
def __init__(self, profile_name: str | None = None, existing_profiles: list[str] | None = None) -> None:
self.profile_name = profile_name
self.existing_profiles = existing_profiles
profile_name_detail = f" `{profile_name}` " if profile_name else " "
existing_profiles_detail = f", different than {existing_profiles}." if existing_profiles else "."
......
......@@ -22,7 +22,7 @@ def asyncio_run(awaitable: Awaitable[T]) -> T:
async def await_for_given_awaitable() -> T:
return await awaitable
return thread_pool.submit(asyncio.run, await_for_given_awaitable()).result()
return thread_pool.submit(asyncio.run, await_for_given_awaitable()).result() # type: ignore[arg-type]
async def event_wait(event: asyncio.Event, timeout: float | None = None) -> bool:
......
......@@ -41,7 +41,7 @@ class BeekeeperApi:
raise NotImplementedError
@api
async def open(self, *, wallet_name: str) -> model.EmptyResponse: # noqa: A003
async def open(self, *, wallet_name: str) -> model.EmptyResponse:
"""Open wallet file / mount hardware key."""
raise NotImplementedError
......
......@@ -64,5 +64,7 @@ class BeekeeperResponseError(BeekeeperError, CommunicationError):
class BeekeeperNotMatchingIdJsonRPCError(BeekeeperError):
def __init__(self, given: Any, got: Any) -> None:
self.message = f"Given id `{given}` does not match the id of the response `{got}`"
super().__init__(self.message)
self.given = given
self.got = got
message = f"Given id `{given}` does not match the id of the response `{got}`"
super().__init__(message)
......@@ -154,7 +154,7 @@ class BeekeeperExecutable:
command,
stdout=self.__files["stdout"],
stderr=self.__files["stderr"],
preexec_fn=os.setpgrp, # create new process group, so signals won't be passed to child process
preexec_fn=os.setpgrp, # noqa: PLW1509 create new process group, so signals won't be passed to child process
)
except Exception as e:
logger.debug(f"Caught exception during start, closing: {e}")
......
......@@ -100,7 +100,9 @@ class Beekeeper:
return self
return await self.launch()
async def __aexit__(self, _: type[Exception] | None, ex: Exception | None, ___: TracebackType | None) -> None:
async def __aexit__(
self, _: type[BaseException] | None, ex: BaseException | None, ___: TracebackType | None
) -> None:
if not self.__run_in_background:
await self.close()
......@@ -174,6 +176,10 @@ class Beekeeper:
raise BeekeeperNotificationServerNotSetError
return self.config.notifications_endpoint
@property
def is_opening_beekeeper_failed(self) -> bool:
return self.__notification_server.opening_beekeeper_failed.is_set()
@contextmanager
def modified_connection_details(
self,
......@@ -347,7 +353,7 @@ class Beekeeper:
return Url(connection.type_, connection.address, connection.port)
def help(self) -> str: # noqa: A003
def help(self) -> str:
arguments = BeekeeperCLIArguments(help=True)
return self.__executable.run_and_get_output(allow_empty_notification_server=True, arguments=arguments)
......
......@@ -26,8 +26,7 @@ class ServerAlreadyRunningError(AsyncHttpServerError):
class Notifiable(Protocol):
def notify(self, message: JsonT) -> None:
...
def notify(self, message: JsonT) -> None: ...
class AsyncHttpServer:
......
......@@ -15,8 +15,7 @@ if TYPE_CHECKING:
class WalletClosingListener(Protocol):
def notify_wallet_closing(self) -> None:
...
def notify_wallet_closing(self) -> None: ...
class BeekeeperNotificationsServer:
......
......@@ -3,7 +3,7 @@ from __future__ import annotations
from math import ceil
from typing import TYPE_CHECKING
from clive.__private.core.vests_to_hive import vests_to_hive
from clive.__private.core.hive_vests_conversions import vests_to_hive
if TYPE_CHECKING:
from clive.models import Asset
......
......@@ -9,7 +9,7 @@ if TYPE_CHECKING:
@lru_cache(maxsize=2048)
def __count_parameters(callback: Callable[..., Any]) -> int:
def count_parameters(callback: Callable[..., Any]) -> int:
"""Count the number of parameters in a callable."""
return len(signature(callback).parameters)
......@@ -27,7 +27,7 @@ async def invoke(callback: Callable[..., Any], *params: Any) -> Any:
-------
The return value of the invoked callable.
"""
parameter_count = __count_parameters(callback)
parameter_count = count_parameters(callback)
result = callback(*params[:parameter_count])
if isawaitable(result):
result = await result
......
......@@ -9,10 +9,11 @@ from clive.exceptions import CliveError
class CommandError(CliveError):
def __init__(self, command: Command, message: str = "") -> None:
def __init__(self, command: Command, reason: str = "") -> None:
self.command = command
self.message = f"Command {command.__class__.__name__} failed. Reason: {message}"
super().__init__(self.message)
self.reason = reason
message = f"Command {command.__class__.__name__} failed. Reason: {reason}"
super().__init__(message)
@dataclass(kw_only=True)
......
......@@ -9,13 +9,12 @@ from clive.__private.core.commands.abc.command_restricted import CommandExecutio
class AppStateProtocol(Protocol):
@property
def is_active(self) -> bool:
...
def is_active(self) -> bool: ...
class CommandRequiresActiveModeError(CommandExecutionNotPossibleError):
def __init__(self, command: CommandInActive) -> None:
super().__init__(command, message="requires the application to be in active mode.")
super().__init__(command, reason="requires the application to be in active mode.")
@dataclass(kw_only=True)
......
......@@ -7,10 +7,10 @@ from clive.__private.core.commands.abc.command import Command, CommandError
class CommandExecutionNotPossibleError(CommandError):
_DEFAULT_MESSAGE: Final[str] = "does not met the requirements to be executed."
_DEFAULT_REASON: Final[str] = "does not met the requirements to be executed."
def __init__(self, command: CommandRestricted, *, message: str = _DEFAULT_MESSAGE) -> None:
super().__init__(command, message)
def __init__(self, command: CommandRestricted, *, reason: str = _DEFAULT_REASON) -> None:
super().__init__(command, reason)
class CommandRestricted(Command, ABC):
......
......@@ -329,14 +329,12 @@ class Commands(Generic[WorldT]):
return await self.__surround_with_exception_handlers(FindAccounts(node=self._world.node, accounts=accounts))
@overload
async def __surround_with_exception_handlers( # type: ignore[misc]
async def __surround_with_exception_handlers( # type: ignore[overload-overlap]
self, command: CommandWithResult[CommandResultT]
) -> CommandWithResultWrapper[CommandResultT]:
...
) -> CommandWithResultWrapper[CommandResultT]: ...
@overload
async def __surround_with_exception_handlers(self, command: Command) -> CommandWrapper:
...
async def __surround_with_exception_handlers(self, command: Command) -> CommandWrapper: ...
async def __surround_with_exception_handlers(
self, command: CommandWithResult[CommandResultT] | Command
......@@ -352,13 +350,12 @@ class Commands(Generic[WorldT]):
return await self.__surround_with_exception_handler(command, self.__exception_handlers) # type: ignore[arg-type]
@overload
async def __surround_with_exception_handler( # type: ignore[misc]
async def __surround_with_exception_handler( # type: ignore[overload-overlap]
self,
command: CommandWithResult[CommandResultT],
exception_handlers: list[type[ErrorHandlerContextManager]],
error: Exception | None = None,
) -> CommandWithResultWrapper[CommandResultT]:
...
) -> CommandWithResultWrapper[CommandResultT]: ...
@overload
async def __surround_with_exception_handler(
......@@ -366,8 +363,7 @@ class Commands(Generic[WorldT]):
command: Command,
exception_handlers: list[type[ErrorHandlerContextManager]],
error: Exception | None = None,
) -> CommandWrapper:
...
) -> CommandWrapper: ...
async def __surround_with_exception_handler(
self,
......@@ -380,7 +376,7 @@ class Commands(Generic[WorldT]):
except IndexError:
# No more exception handlers
assert error is not None
raise error
raise error from None
handler = next_exception_handler()
......@@ -398,14 +394,12 @@ class Commands(Generic[WorldT]):
return self.__create_command_wrapper(command, handler.error)
@overload
def __create_command_wrapper( # type: ignore[misc]
def __create_command_wrapper( # type: ignore[overload-overlap]
self, command: CommandWithResult[CommandResultT], error: Exception | None = None
) -> CommandWithResultWrapper[CommandResultT]:
...
) -> CommandWithResultWrapper[CommandResultT]: ...
@overload
def __create_command_wrapper(self, command: Command, error: Exception | None = None) -> CommandWrapper:
...
def __create_command_wrapper(self, command: Command, error: Exception | None = None) -> CommandWrapper: ...
def __create_command_wrapper(
self, command: Command | CommandWithResult[CommandResultT], error: Exception | None = None
......
......@@ -4,7 +4,7 @@ from dataclasses import dataclass
from typing import TYPE_CHECKING, Final
from clive.__private.core.commands.abc.command_data_retrieval import CommandDataRetrieval
from clive.__private.core.vests_to_hive import vests_to_hive
from clive.__private.core.hive_vests_conversions import vests_to_hive
from clive.models import Asset
if TYPE_CHECKING:
......
......@@ -97,7 +97,7 @@ class ProposalsDataRetrieval(CommandDataRetrieval[HarvestedDataRaw, SanitizedDat
raise ValueError(f"Unknown order: {self.order}")
searched_proposals = await node.api.database_api.list_proposals(
start=[], # type: ignore[arg-type] # TODO: API interface should allow an empty list
start=[],
limit=self.MAX_SEARCHED_PROPOSALS_HARD_LIMIT,
order=order,
order_direction=self.order_direction,
......@@ -154,11 +154,7 @@ class ProposalsDataRetrieval(CommandDataRetrieval[HarvestedDataRaw, SanitizedDat
return [self.__create_proposal_data(proposal, data) for proposal in proposals]
def __get_proposals_ids(self, proposals: list[ProposalSchema]) -> list[int]:
proposal_ids: list[int] = []
for proposal in proposals:
proposal_ids.append(proposal.proposal_id)
return proposal_ids
return [proposal.proposal_id for proposal in proposals]
def __assert_gdpo(self, data: DynamicGlobalProperties | None) -> DynamicGlobalProperties:
assert data is not None, "DynamicGlobalProperties data is missing"
......