diff options
Diffstat (limited to 'third_party/python/tqdm/tqdm/autonotebook.py')
-rw-r--r-- | third_party/python/tqdm/tqdm/autonotebook.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/third_party/python/tqdm/tqdm/autonotebook.py b/third_party/python/tqdm/tqdm/autonotebook.py new file mode 100644 index 0000000000..b032061bfb --- /dev/null +++ b/third_party/python/tqdm/tqdm/autonotebook.py @@ -0,0 +1,28 @@ +""" +Automatically choose between `tqdm.notebook` and `tqdm.std`. + +Usage: +>>> from tqdm.autonotebook import trange, tqdm +>>> for i in trange(10): +... ... +""" +import os +import sys + +try: + get_ipython = sys.modules['IPython'].get_ipython + if 'IPKernelApp' not in get_ipython().config: # pragma: no cover + raise ImportError("console") + if 'VSCODE_PID' in os.environ: # pragma: no cover + raise ImportError("vscode") +except Exception: + from .std import tqdm, trange +else: # pragma: no cover + from warnings import warn + + from .notebook import tqdm, trange + from .std import TqdmExperimentalWarning + warn("Using `tqdm.autonotebook.tqdm` in notebook mode." + " Use `tqdm.tqdm` instead to force console mode" + " (e.g. in jupyter console)", TqdmExperimentalWarning, stacklevel=2) +__all__ = ["tqdm", "trange"] |