Skip to content

Commit

Permalink
feat: 🥅 added a more specific caching error for py<3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
newgene committed Dec 17, 2024
1 parent 8cc39a9 commit e1b7caa
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
17 changes: 13 additions & 4 deletions biothings_client/client/asynchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
15 changes: 12 additions & 3 deletions biothings_client/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 7 additions & 1 deletion biothings_client/client/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
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 = (
f"To {optional_function_access} requires the {libraries} library(ies). "
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)

0 comments on commit e1b7caa

Please sign in to comment.