Skip to content
Snippets Groups Projects
Commit 9167b762 authored by Krzysztof Mochocki's avatar Krzysztof Mochocki
Browse files

Move all apis to one directory in _interfaces

parent 6ae1979e
No related branches found
No related tags found
No related merge requests found
Pipeline #118583 passed
Showing
with 284 additions and 80 deletions
......@@ -33,7 +33,7 @@ variables:
include:
- project: 'hive/hive'
# This has to be the same as the commit checked out in the submodule
ref: ed702f86d3a1ae567b2d2e1d0d7240a187223964
ref: 40e6bc384b63fe116f370153a20c15a46888011f
file: '/scripts/ci-helpers/prepare_data_image_job.yml'
- project: 'hive/common-ci-configuration'
# This should be the same version of Common CI defined in /hive/scripts/ci-helpers/prepare_data_image_job.yml
......@@ -96,19 +96,6 @@ prepare_hived_image:
- public-runner-docker
- hived-for-tests
prepare_hived_data:
extends: .prepare_hived_data_5m
needs:
- job: prepare_hived_image
artifacts: true
stage: build
variables:
SUBMODULE_DIR: "$CI_PROJECT_DIR/hive"
BLOCK_LOG_SOURCE_DIR: $BLOCK_LOG_SOURCE_DIR_5M
CONFIG_INI_SOURCE: "$CI_PROJECT_DIR/hive/docker/config_5M.ini"
tags:
- data-cache-storage
build_beekeepy_wheel:
stage: beekeepy
extends: .build_wheel_template
......
from __future__ import annotations
from beekeepy._interface.abc.asynchronous.beekeeper import Beekeeper as AsyncBeekeeper
from beekeepy._interface.abc.asynchronous.session import Session as AsyncSession
from beekeepy._interface.abc.asynchronous.wallet import UnlockedWallet as AsyncUnlockedWallet
from beekeepy._interface.abc.asynchronous.wallet import Wallet as AsyncWallet
from beekeepy._interface.abc.packed_object import PackedAsyncBeekeeper, PackedSyncBeekeeper
from beekeepy._interface.abc.synchronous.beekeeper import Beekeeper
from beekeepy._interface.abc.synchronous.session import Session
from beekeepy._interface.abc.synchronous.wallet import UnlockedWallet, Wallet
from beekeepy._remote_handle.settings import Settings as RemoteHandleSettings
from beekeepy._runnable_handle.close_already_running_beekeeper import close_already_running_beekeeper
from beekeepy._runnable_handle.settings import Settings
from beekeepy._interface import InterfaceSettings as Settings
from beekeepy._interface.abc import (
AsyncBeekeeper,
AsyncSession,
AsyncUnlockedWallet,
AsyncWallet,
Beekeeper,
PackedAsyncBeekeeper,
PackedSyncBeekeeper,
Session,
UnlockedWallet,
Wallet,
)
from beekeepy._runnable_handle import close_already_running_beekeeper
__all__ = [
"AsyncBeekeeper",
......
from __future__ import annotations
from beekeepy._apis import abc
from beekeepy._apis.app_status_api import (
AppStatusProbeAsyncApiCollection,
AppStatusProbeSyncApiCollection,
AsyncAppStatusApi,
SyncAppStatusApi,
)
from beekeepy._apis.apply_session_token import async_apply_session_token, sync_apply_session_token
from beekeepy._apis.beekeeper_api import (
AsyncBeekeeperApi,
BeekeeperAsyncApiCollection,
BeekeeperSyncApiCollection,
SyncBeekeeperApi,
)
__all__ = [
"abc",
"AppStatusProbeAsyncApiCollection",
"AppStatusProbeSyncApiCollection",
"AsyncAppStatusApi",
"SyncAppStatusApi",
"SyncBeekeeperApi",
"AsyncBeekeeperApi",
"BeekeeperSyncApiCollection",
"BeekeeperAsyncApiCollection",
"sync_apply_session_token",
"async_apply_session_token",
]
from __future__ import annotations
from beekeepy._apis.abc.api import (
AbstractApi,
AbstractAsyncApi,
AbstractSyncApi,
ApiArgumentSerialization,
ApiArgumentsToSerialize,
HandleT,
RegisteredApisT,
)
from beekeepy._apis.abc.api_collection import AbstractAsyncApiCollection, AbstractSyncApiCollection
from beekeepy._apis.abc.sendable import (
AsyncSendable,
SyncSendable,
)
from beekeepy._apis.abc.session_holder import AsyncSessionHolder, SyncSessionHolder
__all__ = [
"AbstractApi",
"AbstractAsyncApi",
"AbstractAsyncApiCollection",
"AbstractSyncApi",
"AbstractSyncApiCollection",
"ApiArgumentSerialization",
"ApiArgumentsToSerialize",
"AsyncSendable",
"AsyncSessionHolder",
"HandleT",
"RegisteredApisT",
"SyncSendable",
"SyncSessionHolder",
]
......@@ -13,16 +13,11 @@ from typing import (
ClassVar,
Generic,
ParamSpec,
TypeAlias,
TypeVar,
get_type_hints,
)
from beekeepy._remote_handle.abc.handle import (
AbstractAsyncHandle,
AbstractSyncHandle,
)
from beekeepy._remote_handle.batch_handle import AsyncBatchHandle, SyncBatchHandle
from beekeepy._apis.abc.sendable import AsyncSendable, SyncSendable
from schemas._preconfigured_base_model import PreconfiguredBaseModel
from schemas.fields.serializable import Serializable
from schemas.operations.representations.legacy_representation import LegacyRepresentation
......@@ -34,9 +29,7 @@ if TYPE_CHECKING:
P = ParamSpec("P")
SyncHandleT: TypeAlias = AbstractSyncHandle[Any] | SyncBatchHandle[Any]
AsyncHandleT: TypeAlias = AbstractAsyncHandle[Any] | AsyncBatchHandle[Any]
HandleT = TypeVar("HandleT", bound=SyncHandleT | AsyncHandleT)
HandleT = TypeVar("HandleT", bound=SyncSendable | AsyncSendable)
RegisteredApisT = defaultdict[bool, defaultdict[str, set[str]]]
ApiArgumentsToSerialize = tuple[tuple[Any, ...], dict[str, Any]]
......@@ -121,7 +114,7 @@ class AbstractApi(ABC, Generic[HandleT]):
self._owner = owner
class AbstractSyncApi(AbstractApi[SyncHandleT]):
class AbstractSyncApi(AbstractApi[SyncSendable]):
"""Base class for all apis, that provides synchronous endpoints."""
def _additional_arguments_actions(
......@@ -153,7 +146,7 @@ class AbstractSyncApi(AbstractApi[SyncHandleT]):
return impl # type: ignore[return-value]
class AbstractAsyncApi(AbstractApi[AsyncHandleT]):
class AbstractAsyncApi(AbstractApi[AsyncSendable]):
"""Base class for all apis, that provides asynchronous endpoints."""
async def _additional_arguments_actions(
......
......@@ -2,7 +2,8 @@ from __future__ import annotations
from typing import Generic
from beekeepy._remote_handle.abc.api import AsyncHandleT, HandleT, SyncHandleT
from beekeepy._apis.abc.api import HandleT
from beekeepy._apis.abc.sendable import AsyncSendable, SyncSendable
class AbstractApiCollection(Generic[HandleT]):
......@@ -12,15 +13,15 @@ class AbstractApiCollection(Generic[HandleT]):
self._owner = owner
class AbstractAsyncApiCollection(AbstractApiCollection[AsyncHandleT]):
class AbstractAsyncApiCollection(AbstractApiCollection[AsyncSendable]):
"""Base class for Async Api Collections."""
def __init__(self, owner: AsyncHandleT) -> None:
def __init__(self, owner: AsyncSendable) -> None:
super().__init__(owner)
class AbstractSyncApiCollection(AbstractApiCollection[SyncHandleT]):
class AbstractSyncApiCollection(AbstractApiCollection[SyncSendable]):
"""Base class for Sync Api Collections."""
def __init__(self, owner: SyncHandleT) -> None:
def __init__(self, owner: SyncSendable) -> None:
super().__init__(owner)
from __future__ import annotations
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from schemas.jsonrpc import ExpectResultT, JSONRPCResult
class SyncSendable(ABC):
@abstractmethod
def _send(
self, *, endpoint: str, params: str, expected_type: type[ExpectResultT]
) -> JSONRPCResult[ExpectResultT]: ...
class AsyncSendable(ABC):
@abstractmethod
async def _async_send(
self, *, endpoint: str, params: str, expected_type: type[ExpectResultT]
) -> JSONRPCResult[ExpectResultT]: ...
from __future__ import annotations
from abc import abstractmethod
from abc import ABC, abstractmethod
from typing import Any
from beekeepy._apis.abc.sendable import AsyncSendable, SyncSendable
from schemas.apis.beekeeper_api import CreateSession
__all__ = ["SyncSessionHolder", "AsyncSessionHolder"]
......@@ -37,7 +38,7 @@ class SessionHolder:
return self.__session
class SyncSessionHolder(SessionHolder):
class SyncSessionHolder(SyncSendable, SessionHolder, ABC):
@abstractmethod
def _acquire_session_token(self) -> str: ...
......@@ -48,7 +49,7 @@ class SyncSessionHolder(SessionHolder):
return self._check_and_return_session()
class AsyncSessionHolder(SessionHolder):
class AsyncSessionHolder(AsyncSendable, SessionHolder, ABC):
@abstractmethod
async def _acquire_session_token(self) -> str: ...
......
from __future__ import annotations
from beekeepy._apis.app_status_api.api_collection import (
AppStatusProbeAsyncApiCollection,
AppStatusProbeSyncApiCollection,
)
from beekeepy._apis.app_status_api.async_api import (
AppStatusApi as AsyncAppStatusApi,
)
from beekeepy._apis.app_status_api.sync_api import (
AppStatusApi as SyncAppStatusApi,
)
__all__ = [
"AsyncAppStatusApi",
"SyncAppStatusApi",
"AppStatusProbeAsyncApiCollection",
"AppStatusProbeSyncApiCollection",
]
from __future__ import annotations
from typing import TYPE_CHECKING
from beekeepy._apis.abc.api_collection import AbstractAsyncApiCollection, AbstractSyncApiCollection
from beekeepy._apis.app_status_api.async_api import AppStatusApi as AsyncAppStatusApi
from beekeepy._apis.app_status_api.sync_api import AppStatusApi as SyncAppStatusApi
if TYPE_CHECKING:
from beekeepy._apis.abc.sendable import AsyncSendable, SyncSendable
class AppStatusProbeSyncApiCollection(AbstractSyncApiCollection):
"""Beekeepers collection of available apis in async version."""
_owner: SyncSendable
def __init__(self, owner: SyncSendable) -> None:
super().__init__(owner)
self.app_status = SyncAppStatusApi(owner=self._owner)
self.app_status_api = self.app_status
class AppStatusProbeAsyncApiCollection(AbstractAsyncApiCollection):
"""Beekeepers collection of available apis in async version."""
_owner: AsyncSendable
def __init__(self, owner: AsyncSendable) -> None:
super().__init__(owner)
self.app_status = AsyncAppStatusApi(owner=self._owner)
self.app_status_api = self.app_status
from __future__ import annotations
from beekeepy._apis.abc.api import AbstractAsyncApi
from schemas.apis import app_status_api # noqa: TCH001
class AppStatusApi(AbstractAsyncApi):
api = AbstractAsyncApi._endpoint
@api
async def get_app_status(self) -> app_status_api.GetAppStatus:
raise NotImplementedError
from __future__ import annotations
from beekeepy._apis.abc.api import AbstractSyncApi
from schemas.apis import app_status_api # noqa: TCH001
class AppStatusApi(AbstractSyncApi):
api = AbstractSyncApi._endpoint
@api
def get_app_status(self) -> app_status_api.GetAppStatus:
raise NotImplementedError
......@@ -3,8 +3,7 @@ from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from beekeepy._remote_handle.abc.api import ApiArgumentsToSerialize
from beekeepy._remote_handle.api.session_holder import AsyncSessionHolder, SyncSessionHolder
from beekeepy._apis.abc import ApiArgumentsToSerialize, AsyncSessionHolder, SyncSessionHolder
def sync_apply_session_token(owner: SyncSessionHolder, arguments: ApiArgumentsToSerialize) -> ApiArgumentsToSerialize:
......
from __future__ import annotations
from beekeepy._apis.beekeeper_api.api_collection import (
BeekeeperAsyncApiCollection,
BeekeeperSyncApiCollection,
)
from beekeepy._apis.beekeeper_api.async_api import (
BeekeeperApi as AsyncBeekeeperApi,
)
from beekeepy._apis.beekeeper_api.sync_api import (
BeekeeperApi as SyncBeekeeperApi,
)
__all__ = ["AsyncBeekeeperApi", "SyncBeekeeperApi", "BeekeeperAsyncApiCollection", "BeekeeperSyncApiCollection"]
......@@ -2,38 +2,31 @@ from __future__ import annotations
from typing import TYPE_CHECKING
from beekeepy._remote_handle.abc.api_collection import (
AbstractAsyncApiCollection,
AbstractSyncApiCollection,
)
from beekeepy._remote_handle.api import AsyncBeekeeperApi, SyncBeekeeperApi
from beekeepy._apis.app_status_api import AppStatusProbeAsyncApiCollection, AppStatusProbeSyncApiCollection
from beekeepy._apis.beekeeper_api.async_api import BeekeeperApi as AsyncBeekeeperApi
from beekeepy._apis.beekeeper_api.sync_api import BeekeeperApi as SyncBeekeeperApi
if TYPE_CHECKING:
from beekeepy._remote_handle.beekeeper import (
AsyncBeekeeper,
Beekeeper,
_AsyncSessionBatchHandle,
_SyncSessionBatchHandle,
)
from beekeepy._apis.abc import AsyncSessionHolder, SyncSessionHolder
class BeekeeperAsyncApiCollection(AbstractAsyncApiCollection):
class BeekeeperAsyncApiCollection(AppStatusProbeAsyncApiCollection):
"""Beekeepers collection of available apis in async version."""
_owner: AsyncBeekeeper | _AsyncSessionBatchHandle
_owner: AsyncSessionHolder
def __init__(self, owner: AsyncBeekeeper | _AsyncSessionBatchHandle) -> None:
def __init__(self, owner: AsyncSessionHolder) -> None:
super().__init__(owner)
self.beekeeper = AsyncBeekeeperApi(owner=self._owner)
self.beekeeper_api = self.beekeeper
class BeekeeperSyncApiCollection(AbstractSyncApiCollection):
class BeekeeperSyncApiCollection(AppStatusProbeSyncApiCollection):
"""Beekeepers collection of available apis in async version."""
_owner: Beekeeper | _SyncSessionBatchHandle
_owner: SyncSessionHolder
def __init__(self, owner: Beekeeper | _SyncSessionBatchHandle) -> None:
def __init__(self, owner: SyncSessionHolder) -> None:
super().__init__(owner)
self.beekeeper = SyncBeekeeperApi(owner=self._owner)
self.beekeeper_api = self.beekeeper
from __future__ import annotations
from typing import TYPE_CHECKING
from beekeepy._remote_handle.abc.api import AbstractAsyncApi, ApiArgumentsToSerialize, AsyncHandleT
from beekeepy._remote_handle.api.apply_session_token import async_apply_session_token
from beekeepy._remote_handle.api.beekeeper_api_commons import BeekeeperApiCommons
from beekeepy._remote_handle.api.session_holder import AsyncSessionHolder
from beekeepy._apis.abc import AbstractAsyncApi, ApiArgumentsToSerialize, AsyncSendable, AsyncSessionHolder
from beekeepy._apis.apply_session_token import async_apply_session_token
from beekeepy._apis.beekeeper_api.beekeeper_api_commons import BeekeeperApiCommons
from schemas.apis import beekeeper_api # noqa: TCH001
if TYPE_CHECKING:
from beekeepy._remote_handle.beekeeper import AsyncBeekeeper, _AsyncSessionBatchHandle
class BeekeeperApi(AbstractAsyncApi, BeekeeperApiCommons[AsyncHandleT]):
class BeekeeperApi(AbstractAsyncApi, BeekeeperApiCommons[AsyncSendable]):
"""Set of endpoints, that allows asynchronous communication with beekeeper service."""
api = AbstractAsyncApi._endpoint
_owner: AsyncBeekeeper | _AsyncSessionBatchHandle
_owner: AsyncSessionHolder
def __init__(self, owner: AsyncBeekeeper | _AsyncSessionBatchHandle) -> None:
def __init__(self, owner: AsyncSessionHolder) -> None:
self._verify_is_owner_can_hold_session_token(owner=owner)
super().__init__(owner=owner)
......@@ -216,14 +210,13 @@ class BeekeeperApi(AbstractAsyncApi, BeekeeperApiCommons[AsyncHandleT]):
raise NotImplementedError
@api
async def create_session(self, *, notifications_endpoint: str = "", salt: str = "") -> beekeeper_api.CreateSession:
async def create_session(self, *, salt: str = "") -> beekeeper_api.CreateSession:
"""Creates session.
Note:
This is called automatically when connection with beekeeper is establish, no need to call it explicitly.
Args:
notifications_endpoint: endpoint on which notifications of status will be broadcasted. (defaults: "")
salt: used for generation of session token
Returns:
......
......@@ -3,10 +3,10 @@ from __future__ import annotations
from abc import abstractmethod
from typing import TYPE_CHECKING, Any, Generic, Protocol
from beekeepy._remote_handle.abc.api import HandleT
from beekeepy._apis.abc.api import HandleT
if TYPE_CHECKING:
from beekeepy._remote_handle.api.session_holder import AsyncSessionHolder, SyncSessionHolder
from beekeepy._apis.abc import AsyncSessionHolder, SyncSessionHolder
class CreateSessionActionProtocol(Protocol):
......
from __future__ import annotations
from typing import TYPE_CHECKING, cast
from beekeepy._remote_handle.abc.api import AbstractSyncApi, ApiArgumentsToSerialize, SyncHandleT
from beekeepy._remote_handle.api.apply_session_token import sync_apply_session_token
from beekeepy._remote_handle.api.beekeeper_api_commons import BeekeeperApiCommons
from beekeepy._remote_handle.api.session_holder import SyncSessionHolder
from beekeepy._apis.abc import AbstractSyncApi, ApiArgumentsToSerialize, SyncSendable, SyncSessionHolder
from beekeepy._apis.apply_session_token import sync_apply_session_token
from beekeepy._apis.beekeeper_api.beekeeper_api_commons import BeekeeperApiCommons
from schemas.apis import beekeeper_api # noqa: TCH001
if TYPE_CHECKING:
from beekeepy._remote_handle.beekeeper import Beekeeper, _SyncSessionBatchHandle
class BeekeeperApi(AbstractSyncApi, BeekeeperApiCommons[SyncHandleT]):
class BeekeeperApi(AbstractSyncApi, BeekeeperApiCommons[SyncSendable]):
api = AbstractSyncApi._endpoint
_owner: Beekeeper | _SyncSessionBatchHandle
_owner: SyncSessionHolder
def __init__(self, owner: Beekeeper | _SyncSessionBatchHandle) -> None:
def __init__(self, owner: SyncSessionHolder) -> None:
self._verify_is_owner_can_hold_session_token(owner=owner)
super().__init__(owner=owner)
......@@ -26,7 +20,7 @@ class BeekeeperApi(AbstractSyncApi, BeekeeperApiCommons[SyncHandleT]):
) -> ApiArgumentsToSerialize:
if not self._token_required(endpoint_name):
return super()._additional_arguments_actions(endpoint_name, arguments)
return sync_apply_session_token(cast(SyncSessionHolder, self._owner), arguments)
return sync_apply_session_token(self._owner, arguments)
def _get_requires_session_holder_type(self) -> type[SyncSessionHolder]:
return SyncSessionHolder
......@@ -94,7 +88,7 @@ class BeekeeperApi(AbstractSyncApi, BeekeeperApiCommons[SyncHandleT]):
raise NotImplementedError
@api
def create_session(self, *, notifications_endpoint: str = "", salt: str = "") -> beekeeper_api.CreateSession:
def create_session(self, *, salt: str = "") -> beekeeper_api.CreateSession:
raise NotImplementedError
@api
......
from __future__ import annotations
from beekeepy._communication import rules
from beekeepy._communication.abc.communicator import AbstractCommunicator
from beekeepy._communication.abc.overseer import AbstractOverseer
from beekeepy._communication.aiohttp_communicator import AioHttpCommunicator
from beekeepy._communication.httpx_communicator import HttpxCommunicator
from beekeepy._communication.overseers import CommonOverseer, StrictOverseer
from beekeepy._communication.request_communicator import RequestCommunicator
from beekeepy._communication.settings import CommunicationSettings
from beekeepy._communication.url import AnyUrl, HttpUrl, P2PUrl, Url, WsUrl
__all__ = [
"CommunicationSettings",
"CommonOverseer",
"StrictOverseer",
"AioHttpCommunicator",
"HttpxCommunicator",
"RequestCommunicator",
"AnyUrl",
"HttpUrl",
"P2PUrl",
"Url",
"WsUrl",
"AbstractCommunicator",
"AbstractOverseer",
"rules",
]
......@@ -7,13 +7,13 @@ from threading import Thread
from typing import TYPE_CHECKING, Any, Awaitable
from beekeepy._communication.settings import CommunicationSettings
from beekeepy._interface.settings_holder import SharedSettingsHolder
from beekeepy._interface.stopwatch import Stopwatch
from beekeepy._utilities.settings_holder import SharedSettingsHolder
from beekeepy._utilities.stopwatch import Stopwatch
from beekeepy.exceptions import CommunicationError, TimeoutExceededError, UnknownDecisionPathError
if TYPE_CHECKING:
from beekeepy._interface.stopwatch import StopwatchResult
from beekeepy._interface.url import HttpUrl
from beekeepy._communication.url import HttpUrl
from beekeepy._utilities.stopwatch import StopwatchResult
class AbstractCommunicator(SharedSettingsHolder[CommunicationSettings], ABC):
......
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