Skip to content

Commit

Permalink
Feature: Add Deprecation Message (#103)
Browse files Browse the repository at this point in the history
Problem: too strict aleph-message dependency

Solution: loosen it to accept compatible versions to 0.4.2

Co-authored-by: Hugo Herter <[email protected]>
  • Loading branch information
MHHukiewitz and hoh committed Feb 22, 2024
1 parent 2f5642c commit 9074d98
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 14 deletions.
19 changes: 19 additions & 0 deletions src/aleph/sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,22 @@
del get_distribution, DistributionNotFound

__all__ = ["AlephHttpClient", "AuthenticatedAlephHttpClient"]


def __getattr__(name):
if name == "AlephClient":
raise ImportError(
"AlephClient has been turned into an abstract class. Please use `AlephHttpClient` instead."
)
elif name == "AuthenticatedAlephClient":
raise ImportError(
"AuthenticatedAlephClient has been turned into an abstract class. Please use `AuthenticatedAlephHttpClient` instead."
)
elif name == "synchronous":
raise ImportError(
"The 'aleph.sdk.synchronous' type is deprecated and has been removed from the aleph SDK. Please use `aleph.sdk.client.AlephHttpClient` instead."
)
elif name == "asynchronous":
raise ImportError(
"The 'aleph.sdk.asynchronous' type is deprecated and has been removed from the aleph SDK. Please use `aleph.sdk.client.AlephHttpClient` instead."
)
42 changes: 28 additions & 14 deletions src/aleph/sdk/client/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async def fetch_aggregate(self, address: str, key: str) -> Dict[str, Dict]:
:param address: Address of the owner of the aggregate
:param key: Key of the aggregate
"""
pass
raise NotImplementedError("Did you mean to import `AlephHttpClient`?")

@abstractmethod
async def fetch_aggregates(
Expand All @@ -55,7 +55,7 @@ async def fetch_aggregates(
:param address: Address of the owner of the aggregate
:param keys: Keys of the aggregates to fetch (Default: all items)
"""
pass
raise NotImplementedError("Did you mean to import `AlephHttpClient`?")

@abstractmethod
async def get_posts(
Expand All @@ -75,7 +75,7 @@ async def get_posts(
:param ignore_invalid_messages: Ignore invalid messages (Default: True)
:param invalid_messages_log_level: Log level to use for invalid messages (Default: logging.NOTSET)
"""
pass
raise NotImplementedError("Did you mean to import `AlephHttpClient`?")

async def get_posts_iterator(
self,
Expand Down Expand Up @@ -110,7 +110,7 @@ async def download_file(
:param file_hash: The hash of the file to retrieve.
"""
pass
raise NotImplementedError("Did you mean to import `AlephHttpClient`?")

async def download_file_ipfs(
self,
Expand Down Expand Up @@ -168,7 +168,7 @@ async def get_messages(
:param ignore_invalid_messages: Ignore invalid messages (Default: True)
:param invalid_messages_log_level: Log level to use for invalid messages (Default: logging.NOTSET)
"""
pass
raise NotImplementedError("Did you mean to import `AlephHttpClient`?")

async def get_messages_iterator(
self,
Expand Down Expand Up @@ -203,7 +203,7 @@ async def get_message(
:param item_hash: Hash of the message to fetch
:param message_type: Type of message to fetch
"""
pass
raise NotImplementedError("Did you mean to import `AlephHttpClient`?")

@abstractmethod
def watch_messages(
Expand All @@ -215,7 +215,7 @@ def watch_messages(
:param message_filter: Filter to apply to the messages
"""
pass
raise NotImplementedError("Did you mean to import `AlephHttpClient`?")


class AuthenticatedAlephClient(AlephClient):
Expand Down Expand Up @@ -243,7 +243,9 @@ async def create_post(
:param storage_engine: An optional storage engine to use for the message, if not inlined (Default: "storage")
:param sync: If true, waits for the message to be processed by the API server (Default: False)
"""
pass
raise NotImplementedError(
"Did you mean to import `AuthenticatedAlephHttpClient`?"
)

@abstractmethod
async def create_aggregate(
Expand All @@ -265,7 +267,9 @@ async def create_aggregate(
:param inline: Whether to write content inside the message (Default: True)
:param sync: If true, waits for the message to be processed by the API server (Default: False)
"""
pass
raise NotImplementedError(
"Did you mean to import `AuthenticatedAlephHttpClient`?"
)

@abstractmethod
async def create_store(
Expand Down Expand Up @@ -297,7 +301,9 @@ async def create_store(
:param channel: Channel to post the message to (Default: "TEST")
:param sync: If true, waits for the message to be processed by the API server (Default: False)
"""
pass
raise NotImplementedError(
"Did you mean to import `AuthenticatedAlephHttpClient`?"
)

@abstractmethod
async def create_program(
Expand Down Expand Up @@ -345,7 +351,9 @@ async def create_program(
:param subscriptions: Patterns of aleph.im messages to forward to the program's event receiver
:param metadata: Metadata to attach to the message
"""
pass
raise NotImplementedError(
"Did you mean to import `AuthenticatedAlephHttpClient`?"
)

@abstractmethod
async def create_instance(
Expand Down Expand Up @@ -394,7 +402,9 @@ async def create_instance(
:param ssh_keys: SSH keys to authorize access to the VM
:param metadata: Metadata to attach to the message
"""
pass
raise NotImplementedError(
"Did you mean to import `AuthenticatedAlephHttpClient`?"
)

@abstractmethod
async def forget(
Expand All @@ -419,7 +429,9 @@ async def forget(
:param address: Address to use (Default: account.get_address())
:param sync: If true, waits for the message to be processed by the API server (Default: False)
"""
pass
raise NotImplementedError(
"Did you mean to import `AuthenticatedAlephHttpClient`?"
)

@abstractmethod
async def submit(
Expand All @@ -444,7 +456,9 @@ async def submit(
:param sync: If true, waits for the message to be processed by the API server (Default: False)
:param raise_on_rejected: Whether to raise an exception if the message is rejected (Default: True)
"""
pass
raise NotImplementedError(
"Did you mean to import `AuthenticatedAlephHttpClient`?"
)

async def ipfs_push(self, content: Mapping) -> str:
"""
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/test_init.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
import pytest

from aleph.sdk import __version__


def test_version():
assert __version__ != ""


def test_deprecation():
with pytest.raises(ImportError):
from aleph.sdk import AlephClient # noqa

with pytest.raises(ImportError):
from aleph.sdk import AuthenticatedAlephClient # noqa

with pytest.raises(ImportError):
from aleph.sdk import synchronous # noqa

with pytest.raises(ImportError):
from aleph.sdk import asynchronous # noqa

with pytest.raises(ImportError):
import aleph.sdk.synchronous # noqa

with pytest.raises(ImportError):
import aleph.sdk.asynchronous # noqa

from aleph.sdk import AlephHttpClient # noqa

0 comments on commit 9074d98

Please sign in to comment.