diff --git a/biothings_client/client/asynchronous.py b/biothings_client/client/asynchronous.py index 13d9227..db46ea2 100644 --- a/biothings_client/client/asynchronous.py +++ b/biothings_client/client/asynchronous.py @@ -5,7 +5,7 @@ from collections.abc import Iterable from copy import copy from pathlib import Path -from typing import Union, Tuple +from typing import Tuple, Union import logging import platform import warnings @@ -30,12 +30,12 @@ MYVARIANT_KWARGS, ) from biothings_client.__version__ import __version__ -from biothings_client._dependencies import _CACHING, _PANDAS -from biothings_client.client.exceptions import OptionalDependencyImportError +from biothings_client._dependencies import _CACHING, _CACHING_NOT_SUPPORTED, _PANDAS +from biothings_client.client.exceptions import CachingNotSupportedError, OptionalDependencyImportError from biothings_client.mixins.gene import MyGeneClientMixin from biothings_client.mixins.variant import MyVariantClientMixin from biothings_client.utils.copy import copy_func -from biothings_client.utils.iteration import iter_n, list_itemcnt, concatenate_list +from biothings_client.utils.iteration import concatenate_list, iter_n, list_itemcnt if _PANDAS: import pandas @@ -310,6 +310,9 @@ async def _set_caching(self, cache_db: Union[str, Path] = None, **kwargs) -> Non Outputs: :return: None """ + if _CACHING_NOT_SUPPORTED: + raise CachingNotSupportedError() + if _CACHING: if not self.caching_enabled: try: @@ -351,6 +354,9 @@ async def _stop_caching(self) -> None: Outputs: :return: None """ + if _CACHING_NOT_SUPPORTED: + raise CachingNotSupportedError() + if _CACHING: if self.caching_enabled: try: @@ -380,6 +386,9 @@ async def _clear_cache(self) -> None: Clear the globally installed cache. Caching will stil be enabled, but the data stored in the cache stored will be dropped """ + if _CACHING_NOT_SUPPORTED: + raise CachingNotSupportedError() + if _CACHING: if self.caching_enabled: try: diff --git a/biothings_client/client/base.py b/biothings_client/client/base.py index ec394ec..d0f6901 100644 --- a/biothings_client/client/base.py +++ b/biothings_client/client/base.py @@ -30,12 +30,12 @@ MYVARIANT_KWARGS, ) from biothings_client.__version__ import __version__ -from biothings_client._dependencies import _CACHING, _PANDAS -from biothings_client.client.exceptions import OptionalDependencyImportError +from biothings_client._dependencies import _CACHING, _CACHING_NOT_SUPPORTED, _PANDAS +from biothings_client.client.exceptions import CachingNotSupportedError, OptionalDependencyImportError from biothings_client.mixins.gene import MyGeneClientMixin from biothings_client.mixins.variant import MyVariantClientMixin from biothings_client.utils.copy import copy_func -from biothings_client.utils.iteration import iter_n, list_itemcnt, concatenate_list +from biothings_client.utils.iteration import concatenate_list, iter_n, list_itemcnt if _PANDAS: import pandas @@ -302,6 +302,9 @@ def _set_caching(self, cache_db: Union[str, Path] = None, **kwargs) -> None: Outputs: :return: None """ + if _CACHING_NOT_SUPPORTED: + raise CachingNotSupportedError() + if _CACHING: if not self.caching_enabled: try: @@ -343,6 +346,9 @@ def _stop_caching(self) -> None: Outputs: :return: None """ + if _CACHING_NOT_SUPPORTED: + raise CachingNotSupportedError() + if _CACHING: if self.caching_enabled: try: @@ -378,6 +384,9 @@ def _clear_cache(self) -> None: Outputs: :return: None """ + if _CACHING_NOT_SUPPORTED: + raise CachingNotSupportedError() + if _CACHING: if self.caching_enabled: try: diff --git a/biothings_client/client/exceptions.py b/biothings_client/client/exceptions.py index c20fa66..ee413e2 100644 --- a/biothings_client/client/exceptions.py +++ b/biothings_client/client/exceptions.py @@ -5,7 +5,7 @@ from typing import List -class OptionalDependencyImportError(Exception): +class OptionalDependencyImportError(ImportError): def __init__(self, optional_function_access: str, optional_group: str, libraries: List[str]): pip_command = f"`pip install biothings_client[{optional_group}]`" message = ( @@ -13,3 +13,9 @@ def __init__(self, optional_function_access: str, optional_group: str, libraries f"To install run the following command: {pip_command}" ) super().__init__(message) + + +class CachingNotSupportedError(Exception): + def __init__(self, message: str): + message = f"Caching is only supported for Python 3.8+\n{message}" + super().__init__(message)