diff --git a/a_sync/utils/as_completed.py b/a_sync/utils/as_completed.py index 83ae8905..5a2d5672 100644 --- a/a_sync/utils/as_completed.py +++ b/a_sync/utils/as_completed.py @@ -3,8 +3,13 @@ from typing import (Any, AsyncIterator, Awaitable, Iterable, Iterator, Mapping, Optional, Tuple, TypeVar, Union, overload) -from tqdm.asyncio import tqdm_asyncio - +try: + from tqdm.asyncio import tqdm_asyncio +except ImportError as e: + class tqdm_asyncio: + def as_completed(*args, **kwargs): + raise ImportError("You must have tqdm installed to use this feature") + from a_sync.iter import ASyncIterator T = TypeVar('T') @@ -43,8 +48,7 @@ def as_completed_mapping(mapping: Mapping[KT, Awaitable[VT]], *, timeout: Option return as_completed([__mapping_wrap(k, v) for k, v in mapping.items()], timeout=timeout, return_exceptions=return_exceptions, aiter=aiter, tqdm=tqdm, **tqdm_kwargs) async def __yield_as_completed(futs: Iterable[Awaitable[T]], *, timeout: Optional[float] = None, return_exceptions: bool = False, tqdm: bool = False, **tqdm_kwargs: Any) -> AsyncIterator[T]: - futs = tqdm_asyncio.as_completed(futs, timeout=timeout, **tqdm_kwargs) if tqdm else asyncio.as_completed(futs, timeout=timeout) - for fut in futs: + for fut in as_completed(futs, timeout=timeout, return_exceptions=return_exceptions, tqdm=tqdm, **tqdm_kwargs): yield await fut async def __mapping_wrap(k: KT, v: Awaitable[VT]) -> VT: diff --git a/a_sync/utils/gather.py b/a_sync/utils/gather.py index 6593e55a..d6ffa101 100644 --- a/a_sync/utils/gather.py +++ b/a_sync/utils/gather.py @@ -3,7 +3,12 @@ from typing import (Any, Awaitable, Dict, List, Mapping, TypeVar, Union, overload) -from tqdm.asyncio import tqdm_asyncio +try: + from tqdm.asyncio import tqdm_asyncio +except ImportError as e: + class tqdm_asyncio: + async def gather(*args, **kwargs): + raise ImportError("You must have tqdm installed in order to use this feature") from a_sync.utils.as_completed import as_completed_mapping diff --git a/requirements.txt b/requirements.txt index e02fbf90..b976e80c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,5 @@ aiolimiter==1.0.0 async_lru_threadsafe==2.0.4 async_property==0.2.1 -tqdm typed_envs>=0.0.2 typing_extensions>=4.1.0 # typing_extensions.Unpack was introduced in 4.1.0