From a4b58f0eddd28705ba921b6c53c145f426802e3c Mon Sep 17 00:00:00 2001 From: mhh Date: Tue, 30 Jan 2024 15:22:56 +0100 Subject: [PATCH 1/9] Problem: too strict aleph-message dependency Solution: loosen it to accept compatible versions to 0.4.2 --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index a132f9bc..42f0e15a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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.2 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" From 5c01b921612f0b09709fcf9fe5e6be4b9271357a Mon Sep 17 00:00:00 2001 From: Mike Hukiewitz <70762838+MHHukiewitz@users.noreply.github.com> Date: Tue, 30 Jan 2024 15:34:59 +0100 Subject: [PATCH 2/9] Update setup.cfg Co-authored-by: nesitor --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 42f0e15a..37143bbf 100644 --- a/setup.cfg +++ b/setup.cfg @@ -38,7 +38,7 @@ install_requires = eciespy>=0.3.13; python_version>="3.11" typing_extensions typer - aleph-message~=0.4.2 + aleph-message~=0.4.1 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" From 6e969bceda30c14bf66936c52d99b3612e37d66b Mon Sep 17 00:00:00 2001 From: Mike Hukiewitz <70762838+MHHukiewitz@users.noreply.github.com> Date: Thu, 1 Feb 2024 13:44:39 +0100 Subject: [PATCH 3/9] Update setup.cfg Co-authored-by: Hugo Herter --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 37143bbf..42f0e15a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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.2 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" From 0e64dca112c64b330836650317ec740e3ea3fef8 Mon Sep 17 00:00:00 2001 From: mhh Date: Fri, 9 Feb 2024 17:47:31 +0100 Subject: [PATCH 4/9] Upgrade to aleph-message~=0.4.3 with backward compatible typing --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 42f0e15a..de505203 100644 --- a/setup.cfg +++ b/setup.cfg @@ -38,7 +38,7 @@ install_requires = eciespy>=0.3.13; python_version>="3.11" typing_extensions typer - aleph-message~=0.4.2 + 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" From d603ab20393e9ad202cac4e25fd0aad8aa68b787 Mon Sep 17 00:00:00 2001 From: mhh Date: Tue, 30 Jan 2024 18:52:37 +0100 Subject: [PATCH 5/9] Update Aleph SDK client to raise ImportError with appropriate error message for deprecated classes and types. --- src/aleph/sdk/__init__.py | 11 +++++++++++ src/aleph/sdk/client/abstract.py | 28 ++++++++++++++-------------- tests/unit/test_init.py | 18 ++++++++++++++++++ 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/aleph/sdk/__init__.py b/src/aleph/sdk/__init__.py index c14b64f6..c45da029 100644 --- a/src/aleph/sdk/__init__.py +++ b/src/aleph/sdk/__init__.py @@ -12,3 +12,14 @@ del get_distribution, DistributionNotFound __all__ = ["AlephHttpClient", "AuthenticatedAlephHttpClient"] + + +def __getattr__(name): + if name == "AlephClient": + raise ImportError(f"AlephClient has been turned into an abstract class. Please use `AlephHttpClient` instead.") + elif name == "AuthenticatedAlephClient": + raise ImportError(f"AuthenticatedAlephClient has been turned into an abstract class. Please use `AuthenticatedAlephHttpClient` instead.") + elif name == "synchronous": + raise ImportError(f"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(f"The 'aleph.sdk.asynchronous' type is deprecated and has been removed from the aleph SDK. Please use `aleph.sdk.client.AlephHttpClient` instead.") diff --git a/src/aleph/sdk/client/abstract.py b/src/aleph/sdk/client/abstract.py index 20a04e43..a24506e4 100644 --- a/src/aleph/sdk/client/abstract.py +++ b/src/aleph/sdk/client/abstract.py @@ -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 ImportError("Did you mean to import `AlephHttpClient`?") @abstractmethod async def fetch_aggregates( @@ -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 ImportError("Did you mean to import `AlephHttpClient`?") @abstractmethod async def get_posts( @@ -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 ImportError("Did you mean to import `AlephHttpClient`?") async def get_posts_iterator( self, @@ -109,7 +109,7 @@ async def download_file( :param file_hash: The hash of the file to retrieve. """ - pass + raise ImportError("Did you mean to import `AlephHttpClient`?") async def download_file_ipfs( self, @@ -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 ImportError("Did you mean to import `AlephHttpClient`?") async def get_messages_iterator( self, @@ -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 ImportError("Did you mean to import `AlephHttpClient`?") @abstractmethod def watch_messages( @@ -214,7 +214,7 @@ def watch_messages( :param message_filter: Filter to apply to the messages """ - pass + raise ImportError("Did you mean to import `AlephHttpClient`?") class AuthenticatedAlephClient(AlephClient): @@ -242,7 +242,7 @@ 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 ImportError("Did you mean to import `AuthenticatedAlephHttpClient`?") @abstractmethod async def create_aggregate( @@ -264,7 +264,7 @@ 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 ImportError("Did you mean to import `AuthenticatedAlephHttpClient`?") @abstractmethod async def create_store( @@ -296,7 +296,7 @@ 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 ImportError("Did you mean to import `AuthenticatedAlephHttpClient`?") @abstractmethod async def create_program( @@ -344,7 +344,7 @@ 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 ImportError("Did you mean to import `AuthenticatedAlephHttpClient`?") @abstractmethod async def create_instance( @@ -392,7 +392,7 @@ 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 ImportError("Did you mean to import `AuthenticatedAlephHttpClient`?") @abstractmethod async def forget( @@ -417,7 +417,7 @@ 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 ImportError("Did you mean to import `AuthenticatedAlephHttpClient`?") @abstractmethod async def submit( @@ -442,7 +442,7 @@ 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 ImportError("Did you mean to import `AuthenticatedAlephHttpClient`?") async def ipfs_push(self, content: Mapping) -> str: """ diff --git a/tests/unit/test_init.py b/tests/unit/test_init.py index 85a1ba69..f65f2d5d 100644 --- a/tests/unit/test_init.py +++ b/tests/unit/test_init.py @@ -1,5 +1,23 @@ +import pytest + from aleph.sdk import __version__ def test_version(): assert __version__ != "" + + +def test_deprecation(): + with pytest.raises(ImportError): + from aleph.sdk import AlephClient + + with pytest.raises(ImportError): + from aleph.sdk import AuthenticatedAlephClient + + with pytest.raises(ImportError): + from aleph.sdk import synchronous + + with pytest.raises(ImportError): + from aleph.sdk import asynchronous + + from aleph.sdk import AlephHttpClient \ No newline at end of file From 47d307296b17809c67c2a448a8c15a992a1aa82e Mon Sep 17 00:00:00 2001 From: mhh Date: Thu, 1 Feb 2024 14:00:07 +0100 Subject: [PATCH 6/9] Add super call to __getattr__ in __init__.py; fix unnecessar f-strings --- src/aleph/sdk/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/aleph/sdk/__init__.py b/src/aleph/sdk/__init__.py index c45da029..5fc84686 100644 --- a/src/aleph/sdk/__init__.py +++ b/src/aleph/sdk/__init__.py @@ -16,10 +16,12 @@ def __getattr__(name): if name == "AlephClient": - raise ImportError(f"AlephClient has been turned into an abstract class. Please use `AlephHttpClient` instead.") + raise ImportError("AlephClient has been turned into an abstract class. Please use `AlephHttpClient` instead.") elif name == "AuthenticatedAlephClient": - raise ImportError(f"AuthenticatedAlephClient has been turned into an abstract class. Please use `AuthenticatedAlephHttpClient` instead.") + raise ImportError("AuthenticatedAlephClient has been turned into an abstract class. Please use `AuthenticatedAlephHttpClient` instead.") elif name == "synchronous": - raise ImportError(f"The 'aleph.sdk.synchronous' type is deprecated and has been removed from the aleph SDK. Please use `aleph.sdk.client.AlephHttpClient` instead.") + 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(f"The 'aleph.sdk.asynchronous' type is deprecated and has been removed from the aleph SDK. Please use `aleph.sdk.client.AlephHttpClient` instead.") + raise ImportError("The 'aleph.sdk.asynchronous' type is deprecated and has been removed from the aleph SDK. Please use `aleph.sdk.client.AlephHttpClient` instead.") + else: + super().__getattribute__(name) From 7c84630cac6768360c1e2c264eaad793d0e356e8 Mon Sep 17 00:00:00 2001 From: mhh Date: Thu, 1 Feb 2024 14:10:05 +0100 Subject: [PATCH 7/9] Reformat and add more tests --- src/aleph/sdk/__init__.py | 18 ++++++++++++------ tests/unit/test_init.py | 16 +++++++++++----- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/aleph/sdk/__init__.py b/src/aleph/sdk/__init__.py index 5fc84686..a3ecc693 100644 --- a/src/aleph/sdk/__init__.py +++ b/src/aleph/sdk/__init__.py @@ -16,12 +16,18 @@ def __getattr__(name): if name == "AlephClient": - raise ImportError("AlephClient has been turned into an abstract class. Please use `AlephHttpClient` instead.") + 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.") + 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.") + 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.") - else: - super().__getattribute__(name) + raise ImportError( + "The 'aleph.sdk.asynchronous' type is deprecated and has been removed from the aleph SDK. Please use `aleph.sdk.client.AlephHttpClient` instead." + ) diff --git a/tests/unit/test_init.py b/tests/unit/test_init.py index f65f2d5d..664783a3 100644 --- a/tests/unit/test_init.py +++ b/tests/unit/test_init.py @@ -9,15 +9,21 @@ def test_version(): def test_deprecation(): with pytest.raises(ImportError): - from aleph.sdk import AlephClient + from aleph.sdk import AlephClient # noqa with pytest.raises(ImportError): - from aleph.sdk import AuthenticatedAlephClient + from aleph.sdk import AuthenticatedAlephClient # noqa with pytest.raises(ImportError): - from aleph.sdk import synchronous + from aleph.sdk import synchronous # noqa with pytest.raises(ImportError): - from aleph.sdk import asynchronous + from aleph.sdk import asynchronous # noqa - from aleph.sdk import AlephHttpClient \ No newline at end of file + with pytest.raises(ImportError): + import aleph.sdk.synchronous # noqa + + with pytest.raises(ImportError): + import aleph.sdk.asynchronous # noqa + + from aleph.sdk import AlephHttpClient # noqa From 733bcdd5357a8b4e0686bb4259a4d73ec5b4d8ac Mon Sep 17 00:00:00 2001 From: mhh Date: Fri, 9 Feb 2024 17:45:32 +0100 Subject: [PATCH 8/9] Replace ImportError by NotImplementedError where applicable --- src/aleph/sdk/client/abstract.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/aleph/sdk/client/abstract.py b/src/aleph/sdk/client/abstract.py index a24506e4..8d55be9b 100644 --- a/src/aleph/sdk/client/abstract.py +++ b/src/aleph/sdk/client/abstract.py @@ -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 """ - raise ImportError("Did you mean to import `AlephHttpClient`?") + raise NotImplementedError("Did you mean to import `AlephHttpClient`?") @abstractmethod async def fetch_aggregates( @@ -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) """ - raise ImportError("Did you mean to import `AlephHttpClient`?") + raise NotImplementedError("Did you mean to import `AlephHttpClient`?") @abstractmethod async def get_posts( @@ -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) """ - raise ImportError("Did you mean to import `AlephHttpClient`?") + raise NotImplementedError("Did you mean to import `AlephHttpClient`?") async def get_posts_iterator( self, @@ -109,7 +109,7 @@ async def download_file( :param file_hash: The hash of the file to retrieve. """ - raise ImportError("Did you mean to import `AlephHttpClient`?") + raise NotImplementedError("Did you mean to import `AlephHttpClient`?") async def download_file_ipfs( self, @@ -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) """ - raise ImportError("Did you mean to import `AlephHttpClient`?") + raise NotImplementedError("Did you mean to import `AlephHttpClient`?") async def get_messages_iterator( self, @@ -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 """ - raise ImportError("Did you mean to import `AlephHttpClient`?") + raise NotImplementedError("Did you mean to import `AlephHttpClient`?") @abstractmethod def watch_messages( @@ -214,7 +214,7 @@ def watch_messages( :param message_filter: Filter to apply to the messages """ - raise ImportError("Did you mean to import `AlephHttpClient`?") + raise NotImplementedError("Did you mean to import `AlephHttpClient`?") class AuthenticatedAlephClient(AlephClient): @@ -242,7 +242,7 @@ 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) """ - raise ImportError("Did you mean to import `AuthenticatedAlephHttpClient`?") + raise NotImplementedError("Did you mean to import `AuthenticatedAlephHttpClient`?") @abstractmethod async def create_aggregate( @@ -264,7 +264,7 @@ 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) """ - raise ImportError("Did you mean to import `AuthenticatedAlephHttpClient`?") + raise NotImplementedError("Did you mean to import `AuthenticatedAlephHttpClient`?") @abstractmethod async def create_store( @@ -296,7 +296,7 @@ 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) """ - raise ImportError("Did you mean to import `AuthenticatedAlephHttpClient`?") + raise NotImplementedError("Did you mean to import `AuthenticatedAlephHttpClient`?") @abstractmethod async def create_program( @@ -344,7 +344,7 @@ 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 """ - raise ImportError("Did you mean to import `AuthenticatedAlephHttpClient`?") + raise NotImplementedError("Did you mean to import `AuthenticatedAlephHttpClient`?") @abstractmethod async def create_instance( @@ -392,7 +392,7 @@ async def create_instance( :param ssh_keys: SSH keys to authorize access to the VM :param metadata: Metadata to attach to the message """ - raise ImportError("Did you mean to import `AuthenticatedAlephHttpClient`?") + raise NotImplementedError("Did you mean to import `AuthenticatedAlephHttpClient`?") @abstractmethod async def forget( @@ -417,7 +417,7 @@ 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) """ - raise ImportError("Did you mean to import `AuthenticatedAlephHttpClient`?") + raise NotImplementedError("Did you mean to import `AuthenticatedAlephHttpClient`?") @abstractmethod async def submit( @@ -442,7 +442,7 @@ 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) """ - raise ImportError("Did you mean to import `AuthenticatedAlephHttpClient`?") + raise NotImplementedError("Did you mean to import `AuthenticatedAlephHttpClient`?") async def ipfs_push(self, content: Mapping) -> str: """ From 198aa30ed2adc6e640da75ebbcda358722f3b15c Mon Sep 17 00:00:00 2001 From: mhh Date: Fri, 9 Feb 2024 17:48:07 +0100 Subject: [PATCH 9/9] Fix formatting --- src/aleph/sdk/client/abstract.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/aleph/sdk/client/abstract.py b/src/aleph/sdk/client/abstract.py index 8d55be9b..496108c7 100644 --- a/src/aleph/sdk/client/abstract.py +++ b/src/aleph/sdk/client/abstract.py @@ -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) """ - raise NotImplementedError("Did you mean to import `AuthenticatedAlephHttpClient`?") + raise NotImplementedError( + "Did you mean to import `AuthenticatedAlephHttpClient`?" + ) @abstractmethod async def create_aggregate( @@ -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) """ - raise NotImplementedError("Did you mean to import `AuthenticatedAlephHttpClient`?") + raise NotImplementedError( + "Did you mean to import `AuthenticatedAlephHttpClient`?" + ) @abstractmethod async def create_store( @@ -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) """ - raise NotImplementedError("Did you mean to import `AuthenticatedAlephHttpClient`?") + raise NotImplementedError( + "Did you mean to import `AuthenticatedAlephHttpClient`?" + ) @abstractmethod async def create_program( @@ -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 """ - raise NotImplementedError("Did you mean to import `AuthenticatedAlephHttpClient`?") + raise NotImplementedError( + "Did you mean to import `AuthenticatedAlephHttpClient`?" + ) @abstractmethod async def create_instance( @@ -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 """ - raise NotImplementedError("Did you mean to import `AuthenticatedAlephHttpClient`?") + raise NotImplementedError( + "Did you mean to import `AuthenticatedAlephHttpClient`?" + ) @abstractmethod async def forget( @@ -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) """ - raise NotImplementedError("Did you mean to import `AuthenticatedAlephHttpClient`?") + raise NotImplementedError( + "Did you mean to import `AuthenticatedAlephHttpClient`?" + ) @abstractmethod async def submit( @@ -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) """ - raise NotImplementedError("Did you mean to import `AuthenticatedAlephHttpClient`?") + raise NotImplementedError( + "Did you mean to import `AuthenticatedAlephHttpClient`?" + ) async def ipfs_push(self, content: Mapping) -> str: """