Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# .coveragerc to control coverage.py
[run]
branch = True
source = aleph_client
source = aleph.sdk
# omit = bad_file.py

[paths]
Expand Down
4 changes: 2 additions & 2 deletions examples/httpgateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from aleph.sdk.chains.common import get_fallback_private_key
from aleph.sdk.chains.ethereum import ETHAccount
from aleph.sdk.user_session import AuthenticatedUserSession
from aleph.sdk.client import AuthenticatedAlephClient

app = web.Application()
routes = web.RouteTableDef()
Expand All @@ -32,7 +32,7 @@ async def source_post(request):
return web.json_response(
{"status": "error", "message": "unauthorized secret"}
)
async with AuthenticatedUserSession(
async with AuthenticatedAlephClient(
account=app["account"], api_server="https://api2.aleph.im"
) as session:
message, _status = await session.create_post(
Expand Down
7 changes: 2 additions & 5 deletions examples/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@
from aleph_message.models import AlephMessage

from aleph.sdk.chains.ethereum import get_fallback_account
from aleph.sdk.client import AuthenticatedAlephClient, AuthenticatedUserSessionSync
from aleph.sdk.conf import settings
from aleph.sdk.types import MessageStatus
from aleph.sdk.user_session import (
AuthenticatedUserSession,
AuthenticatedUserSessionSync,
)


def get_sysinfo():
Expand Down Expand Up @@ -73,7 +70,7 @@ def collect_metrics():

def main():
account = get_fallback_account()
with AuthenticatedUserSession(
with AuthenticatedAlephClient(
account=account, api_server=settings.API_HOST
) as session:
while True:
Expand Down
6 changes: 3 additions & 3 deletions examples/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

from aleph.sdk.chains.common import get_fallback_private_key
from aleph.sdk.chains.ethereum import ETHAccount
from aleph.sdk.client import AuthenticatedAlephClient
from aleph.sdk.conf import settings
from aleph.sdk.user_session import AuthenticatedUserSession


def get_input_data(value):
Expand All @@ -27,7 +27,7 @@ def get_input_data(value):


def send_metrics(account, metrics):
with AuthenticatedUserSession(
with AuthenticatedAlephClient(
account=account, api_server=settings.API_HOST
) as session:
return session.create_aggregate(
Expand Down Expand Up @@ -100,7 +100,7 @@ async def gateway(
if not userdata["received"]:
await client.reconnect()

async with AuthenticatedUserSession(
async with AuthenticatedAlephClient(
account=account, api_server=settings.API_HOST
) as session:
for key, value in state.items():
Expand Down
4 changes: 2 additions & 2 deletions examples/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

from aleph.sdk.chains.common import get_fallback_private_key
from aleph.sdk.chains.ethereum import ETHAccount
from aleph.sdk.client import AuthenticatedAlephClient
from aleph.sdk.conf import settings
from aleph.sdk.types import MessageStatus
from aleph.sdk.user_session import AuthenticatedUserSession

DEFAULT_SERVER = "https://api2.aleph.im"

Expand All @@ -23,7 +23,7 @@ async def print_output_hash(message: StoreMessage, status: MessageStatus):


async def do_upload(account, engine, channel, filename=None, file_hash=None):
async with AuthenticatedUserSession(
async with AuthenticatedAlephClient(
account=account, api_server=settings.API_HOST
) as session:
print(filename, account.get_address())
Expand Down
8 changes: 3 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,9 @@ docs =

[options.entry_points]
# Add here console scripts like:
console_scripts =
aleph = aleph_client.__main__:app
# For example:
# console_scripts =
# fibonacci = aleph_client.skeleton:run
# fibonacci = aleph.sdk.skeleton:run
# And any other entry points, for example:
# pyscaffold.cli =
# awesome = pyscaffoldext.awesome.extension:AwesomeExtension
Expand All @@ -118,7 +116,7 @@ extras = True
# e.g. --cov-report html (or xml) for html/xml output or --junitxml junit.xml
# in order to write a coverage file that can be read by Jenkins.
addopts =
--cov aleph_client --cov-report term-missing
--cov aleph.sdk --cov-report term-missing
--verbose
norecursedirs =
dist
Expand Down Expand Up @@ -160,4 +158,4 @@ profile = black
# PyScaffold's parameters when the project was created.
# This will be used when updating. Do not change!
version = 3.2.1
package = aleph_client
package = aleph.sdk
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
"""
Setup file for aleph_client.
Setup file for aleph.sdk
Use setup.cfg to configure your project.

This file was generated with PyScaffold 3.2.1.
Expand Down
4 changes: 2 additions & 2 deletions src/aleph/sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pkg_resources import DistributionNotFound, get_distribution

from aleph.sdk.user_session import AuthenticatedUserSession, UserSession
from aleph.sdk.client import AlephClient, AuthenticatedAlephClient

try:
# Change here if project is renamed and does not equal the package name
Expand All @@ -11,4 +11,4 @@
finally:
del get_distribution, DistributionNotFound

__all__ = ["AuthenticatedUserSession", "UserSession"]
__all__ = ["AlephClient", "AuthenticatedAlephClient"]
18 changes: 9 additions & 9 deletions src/aleph/sdk/user_session.py → src/aleph/sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def async_wrapper(f):
Copies the docstring of wrapped functions.
"""

wrapped = getattr(AuthenticatedUserSession, f.__name__)
wrapped = getattr(AuthenticatedAlephClient, f.__name__)
f.__doc__ = wrapped.__doc__


Expand All @@ -95,7 +95,7 @@ def func_caller(*args, **kwargs):
async def run_async_watcher(
*args, output_queue: queue.Queue, api_server: str, **kwargs
):
async with UserSession(api_server=api_server) as session:
async with AlephClient(api_server=api_server) as session:
async for message in session.watch_messages(*args, **kwargs):
output_queue.put(message)

Expand All @@ -122,7 +122,7 @@ class UserSessionSync:
>>> return self._wrap(self.async_session.func)(*args, **kwargs)
"""

def __init__(self, async_session: "UserSession"):
def __init__(self, async_session: "AlephClient"):
self.async_session = async_session

def _wrap(self, method: Callable[..., Awaitable[T]], *args, **kwargs):
Expand Down Expand Up @@ -272,9 +272,9 @@ def watch_messages(


class AuthenticatedUserSessionSync(UserSessionSync):
async_session: "AuthenticatedUserSession"
async_session: "AuthenticatedAlephClient"

def __init__(self, async_session: "AuthenticatedUserSession"):
def __init__(self, async_session: "AuthenticatedAlephClient"):
super().__init__(async_session=async_session)

def ipfs_push(self, content: Mapping) -> str:
Expand Down Expand Up @@ -436,7 +436,7 @@ def submit(
)


class UserSession:
class AlephClient:
api_server: str
http_session: aiohttp.ClientSession

Expand All @@ -455,7 +455,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
except RuntimeError:
asyncio.run(close_fut)

async def __aenter__(self) -> "UserSession":
async def __aenter__(self) -> "AlephClient":
return self

async def __aexit__(self, exc_type, exc_val, exc_tb):
Expand Down Expand Up @@ -807,7 +807,7 @@ async def watch_messages(
break


class AuthenticatedUserSession(UserSession):
class AuthenticatedAlephClient(AlephClient):
account: Account

BROADCAST_MESSAGE_FIELDS = {
Expand All @@ -829,7 +829,7 @@ def __init__(self, account: Account, api_server: str):
def __enter__(self) -> "AuthenticatedUserSessionSync":
return AuthenticatedUserSessionSync(async_session=self)

async def __aenter__(self) -> "AuthenticatedUserSession":
async def __aenter__(self) -> "AuthenticatedAlephClient":
return self

async def ipfs_push(self, content: Mapping) -> str:
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/itest_aggregates.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import pytest

from aleph.sdk.client import AuthenticatedAlephClient
from aleph.sdk.types import Account
from aleph.sdk.user_session import AuthenticatedUserSession
from tests.integration.toolkit import try_until

from .config import REFERENCE_NODE, TARGET_NODE
Expand All @@ -18,7 +18,7 @@ async def create_aggregate_on_target(
receiver_node: str,
channel="INTEGRATION_TESTS",
):
async with AuthenticatedUserSession(
async with AuthenticatedAlephClient(
account=account, api_server=emitter_node
) as tx_session:
aggregate_message, message_status = await tx_session.create_aggregate(
Expand All @@ -38,7 +38,7 @@ async def create_aggregate_on_target(
assert aggregate_message.content.address == account.get_address()
assert aggregate_message.content.content == content

async with AuthenticatedUserSession(
async with AuthenticatedAlephClient(
account=account, api_server=receiver_node
) as rx_session:
aggregate_from_receiver = await try_until(
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/itest_forget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import pytest

from aleph.sdk.client import AuthenticatedAlephClient
from aleph.sdk.types import Account
from aleph.sdk.user_session import AuthenticatedUserSession

from .config import REFERENCE_NODE, TARGET_NODE, TEST_CHANNEL
from .toolkit import try_until
Expand All @@ -17,7 +17,7 @@ async def wait_matching_posts(
condition: Callable[[Dict], bool],
timeout: int = 5,
):
async with AuthenticatedUserSession(
async with AuthenticatedAlephClient(
account=account, api_server=receiver_node
) as rx_session:
return await try_until(
Expand All @@ -27,7 +27,7 @@ async def wait_matching_posts(
hashes=[item_hash],
)

async with AuthenticatedUserSession(
async with AuthenticatedAlephClient(
account=account, api_server=emitter_node
) as tx_session:
post_message, message_status = await tx_session.create_post(
Expand All @@ -46,7 +46,7 @@ async def wait_matching_posts(

post_hash = post_message.item_hash
reason = "This well thought-out content offends me!"
async with AuthenticatedUserSession(
async with AuthenticatedAlephClient(
account=account, api_server=emitter_node
) as tx_session:
forget_message, forget_status = await tx_session.forget(
Expand Down Expand Up @@ -103,7 +103,7 @@ async def test_forget_a_forget_message(fixture_account):

# TODO: this test should be moved to the PyAleph API tests, once a framework is in place.
post_hash = await create_and_forget_post(fixture_account, TARGET_NODE, TARGET_NODE)
async with AuthenticatedUserSession(
async with AuthenticatedAlephClient(
account=fixture_account, api_server=TARGET_NODE
) as session:
get_post_response = await session.get_posts(hashes=[post_hash])
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/itest_posts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from aleph_message.models import MessagesResponse

from aleph.sdk.user_session import AuthenticatedUserSession
from aleph.sdk.client import AuthenticatedAlephClient
from tests.integration.toolkit import try_until

from .config import REFERENCE_NODE, TARGET_NODE
Expand All @@ -13,7 +13,7 @@ async def create_message_on_target(
"""
Create a POST message on the target node, then fetch it from the reference node.
"""
async with AuthenticatedUserSession(
async with AuthenticatedAlephClient(
account=fixture_account, api_server=emitter_node
) as tx_session:
post_message, message_status = await tx_session.create_post(
Expand All @@ -25,7 +25,7 @@ async def create_message_on_target(
def response_contains_messages(response: MessagesResponse) -> bool:
return len(response.messages) > 0

async with AuthenticatedUserSession(
async with AuthenticatedAlephClient(
account=fixture_account, api_server=receiver_node
) as rx_session:
responses = await try_until(
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/test_asynchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
StoreMessage,
)

from aleph.sdk.client import AuthenticatedAlephClient
from aleph.sdk.types import Account, MessageStatus, StorageEnum
from aleph.sdk.user_session import AuthenticatedUserSession


@pytest.fixture
def mock_session_with_post_success(
ethereum_account: Account,
) -> AuthenticatedUserSession:
) -> AuthenticatedAlephClient:
class MockResponse:
def __init__(self, sync: bool):
self.sync = sync
Expand Down Expand Up @@ -48,12 +48,12 @@ async def text(self):
sync=kwargs.get("sync", False)
)

user_session = AuthenticatedUserSession(
client = AuthenticatedAlephClient(
account=ethereum_account, api_server="http://localhost"
)
user_session.http_session = http_session
client.http_session = http_session

return user_session
return client


@pytest.mark.asyncio
Expand Down
Loading