auto.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. """
  2. Enables multiple commonly used features.
  3. Method resolution order:
  4. - `tqdm.autonotebook` without import warnings
  5. - `tqdm.asyncio` on Python3.5+
  6. - `tqdm.std` base class
  7. Usage:
  8. >>> from tqdm.auto import trange, tqdm
  9. >>> for i in trange(10):
  10. ... ...
  11. """
  12. import sys
  13. import warnings
  14. from .std import TqdmExperimentalWarning
  15. with warnings.catch_warnings():
  16. warnings.simplefilter("ignore", category=TqdmExperimentalWarning)
  17. from .autonotebook import tqdm as notebook_tqdm
  18. from .autonotebook import trange as notebook_trange
  19. if sys.version_info[:1] < (3, 4):
  20. tqdm = notebook_tqdm
  21. trange = notebook_trange
  22. else: # Python3.5+
  23. from .asyncio import tqdm as asyncio_tqdm
  24. from .std import tqdm as std_tqdm
  25. if notebook_tqdm != std_tqdm:
  26. class tqdm(notebook_tqdm, asyncio_tqdm):
  27. pass
  28. else:
  29. tqdm = asyncio_tqdm
  30. def trange(*args, **kwargs):
  31. """
  32. A shortcut for `tqdm.auto.tqdm(range(*args), **kwargs)`.
  33. """
  34. return tqdm(range(*args), **kwargs)
  35. __all__ = ["tqdm", "trange"]