Skip to content

Commit

Permalink
autonotebook: check for ipywidgets
Browse files Browse the repository at this point in the history
- closes #1218
- fixes #1082
- fixes #1217
  • Loading branch information
casperdcl committed Feb 27, 2022
1 parent 01ae86b commit 7cdbfee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 6 additions & 2 deletions tqdm/autonotebook.py
Expand Up @@ -8,18 +8,22 @@
"""
import os
import sys
from warnings import warn

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")
from .notebook import WARN_NOIPYW, IProgress
if IProgress is None:
from .std import TqdmWarning
warn(WARN_NOIPYW, TqdmWarning, stacklevel=2)
raise ImportError('ipywidgets')
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."
Expand Down
8 changes: 4 additions & 4 deletions tqdm/notebook.py
Expand Up @@ -71,6 +71,9 @@

__author__ = {"github.com/": ["lrq3000", "casperdcl", "alexanderkuk"]}
__all__ = ['tqdm_notebook', 'tnrange', 'tqdm', 'trange']
WARN_NOIPYW = ("IProgress not found. Please update jupyter and ipywidgets."
" See https://ipywidgets.readthedocs.io/en/stable"
"/user_install.html")


class TqdmHBox(HBox):
Expand Down Expand Up @@ -112,10 +115,7 @@ def status_printer(_, total=None, desc=None, ncols=None):

# Prepare IPython progress bar
if IProgress is None: # #187 #451 #558 #872
raise ImportError(
"IProgress not found. Please update jupyter and ipywidgets."
" See https://ipywidgets.readthedocs.io/en/stable"
"/user_install.html")
raise ImportError(WARN_NOIPYW)
if total:
pbar = IProgress(min=0, max=total)
else: # No total? Show info style bar with no progress tqdm status
Expand Down

0 comments on commit 7cdbfee

Please sign in to comment.