Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Deprecation messages for invalid imports #94

Merged
merged 9 commits into from
Feb 10, 2024
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ install_requires =
eciespy>=0.3.13; python_version>="3.11"
typing_extensions
typer
aleph-message==0.4.1
aleph-message~=0.4.3
eth_account>=0.4.0
# Required to fix a dependency issue with parsimonious and Python3.11
eth_abi==4.0.0b2; python_version>="3.11"
Expand Down
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):
MHHukiewitz marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -42,7 +42,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 @@ -54,7 +54,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 @@ -74,7 +74,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 @@ -109,7 +109,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 @@ -167,7 +167,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 @@ -202,7 +202,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 @@ -214,7 +214,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 @@ -242,7 +242,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 @@ -264,7 +266,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 @@ -296,7 +300,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 @@ -344,7 +350,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 @@ -392,7 +400,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 @@ -417,7 +427,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 @@ -442,7 +454,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
Loading