Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: make tqdm optional as intended #84

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading