autonotebook.py 956 B

1234567891011121314151617181920212223242526272829
  1. """
  2. Automatically choose between `tqdm.notebook` and `tqdm.std`.
  3. Usage:
  4. >>> from tqdm.autonotebook import trange, tqdm
  5. >>> for i in trange(10):
  6. ... ...
  7. """
  8. import sys
  9. from warnings import warn
  10. try:
  11. get_ipython = sys.modules['IPython'].get_ipython
  12. if 'IPKernelApp' not in get_ipython().config: # pragma: no cover
  13. raise ImportError("console")
  14. from .notebook import WARN_NOIPYW, IProgress
  15. if IProgress is None:
  16. from .std import TqdmWarning
  17. warn(WARN_NOIPYW, TqdmWarning, stacklevel=2)
  18. raise ImportError('ipywidgets')
  19. except Exception:
  20. from .std import tqdm, trange
  21. else: # pragma: no cover
  22. from .notebook import tqdm, trange
  23. from .std import TqdmExperimentalWarning
  24. warn("Using `tqdm.autonotebook.tqdm` in notebook mode."
  25. " Use `tqdm.tqdm` instead to force console mode"
  26. " (e.g. in jupyter console)", TqdmExperimentalWarning, stacklevel=2)
  27. __all__ = ["tqdm", "trange"]