Skip to content

Commit 9074d98

Browse files
MHHukiewitzhoh
andcommittedFeb 22, 2024
Feature: Add Deprecation Message (#103)
Problem: too strict aleph-message dependency Solution: loosen it to accept compatible versions to 0.4.2 Co-authored-by: Hugo Herter <git@hugoherter.com>
1 parent 2f5642c commit 9074d98

File tree

3 files changed

+71
-14
lines changed

3 files changed

+71
-14
lines changed
 

‎src/aleph/sdk/__init__.py

+19
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,22 @@
1212
del get_distribution, DistributionNotFound
1313

1414
__all__ = ["AlephHttpClient", "AuthenticatedAlephHttpClient"]
15+
16+
17+
def __getattr__(name):
18+
if name == "AlephClient":
19+
raise ImportError(
20+
"AlephClient has been turned into an abstract class. Please use `AlephHttpClient` instead."
21+
)
22+
elif name == "AuthenticatedAlephClient":
23+
raise ImportError(
24+
"AuthenticatedAlephClient has been turned into an abstract class. Please use `AuthenticatedAlephHttpClient` instead."
25+
)
26+
elif name == "synchronous":
27+
raise ImportError(
28+
"The 'aleph.sdk.synchronous' type is deprecated and has been removed from the aleph SDK. Please use `aleph.sdk.client.AlephHttpClient` instead."
29+
)
30+
elif name == "asynchronous":
31+
raise ImportError(
32+
"The 'aleph.sdk.asynchronous' type is deprecated and has been removed from the aleph SDK. Please use `aleph.sdk.client.AlephHttpClient` instead."
33+
)

‎src/aleph/sdk/client/abstract.py

+28-14
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async def fetch_aggregate(self, address: str, key: str) -> Dict[str, Dict]:
4343
:param address: Address of the owner of the aggregate
4444
:param key: Key of the aggregate
4545
"""
46-
pass
46+
raise NotImplementedError("Did you mean to import `AlephHttpClient`?")
4747

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

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

8080
async def get_posts_iterator(
8181
self,
@@ -110,7 +110,7 @@ async def download_file(
110110
111111
:param file_hash: The hash of the file to retrieve.
112112
"""
113-
pass
113+
raise NotImplementedError("Did you mean to import `AlephHttpClient`?")
114114

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

173173
async def get_messages_iterator(
174174
self,
@@ -203,7 +203,7 @@ async def get_message(
203203
:param item_hash: Hash of the message to fetch
204204
:param message_type: Type of message to fetch
205205
"""
206-
pass
206+
raise NotImplementedError("Did you mean to import `AlephHttpClient`?")
207207

208208
@abstractmethod
209209
def watch_messages(
@@ -215,7 +215,7 @@ def watch_messages(
215215
216216
:param message_filter: Filter to apply to the messages
217217
"""
218-
pass
218+
raise NotImplementedError("Did you mean to import `AlephHttpClient`?")
219219

220220

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

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

270274
@abstractmethod
271275
async def create_store(
@@ -297,7 +301,9 @@ async def create_store(
297301
:param channel: Channel to post the message to (Default: "TEST")
298302
:param sync: If true, waits for the message to be processed by the API server (Default: False)
299303
"""
300-
pass
304+
raise NotImplementedError(
305+
"Did you mean to import `AuthenticatedAlephHttpClient`?"
306+
)
301307

302308
@abstractmethod
303309
async def create_program(
@@ -345,7 +351,9 @@ async def create_program(
345351
:param subscriptions: Patterns of aleph.im messages to forward to the program's event receiver
346352
:param metadata: Metadata to attach to the message
347353
"""
348-
pass
354+
raise NotImplementedError(
355+
"Did you mean to import `AuthenticatedAlephHttpClient`?"
356+
)
349357

350358
@abstractmethod
351359
async def create_instance(
@@ -394,7 +402,9 @@ async def create_instance(
394402
:param ssh_keys: SSH keys to authorize access to the VM
395403
:param metadata: Metadata to attach to the message
396404
"""
397-
pass
405+
raise NotImplementedError(
406+
"Did you mean to import `AuthenticatedAlephHttpClient`?"
407+
)
398408

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

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

449463
async def ipfs_push(self, content: Mapping) -> str:
450464
"""

‎tests/unit/test_init.py

+24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
1+
import pytest
2+
13
from aleph.sdk import __version__
24

35

46
def test_version():
57
assert __version__ != ""
8+
9+
10+
def test_deprecation():
11+
with pytest.raises(ImportError):
12+
from aleph.sdk import AlephClient # noqa
13+
14+
with pytest.raises(ImportError):
15+
from aleph.sdk import AuthenticatedAlephClient # noqa
16+
17+
with pytest.raises(ImportError):
18+
from aleph.sdk import synchronous # noqa
19+
20+
with pytest.raises(ImportError):
21+
from aleph.sdk import asynchronous # noqa
22+
23+
with pytest.raises(ImportError):
24+
import aleph.sdk.synchronous # noqa
25+
26+
with pytest.raises(ImportError):
27+
import aleph.sdk.asynchronous # noqa
28+
29+
from aleph.sdk import AlephHttpClient # noqa

0 commit comments

Comments
 (0)
Please sign in to comment.