Skip to content

Commit

Permalink
chore: make tqdm optional as intended (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Oct 10, 2023
1 parent e07e3af commit 3c6d47c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
12 changes: 8 additions & 4 deletions a_sync/utils/as_completed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion a_sync/utils/gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3c6d47c

Please sign in to comment.