1717from ._tqdm import tqdm
1818
1919
20- # import IPython/Jupyter base widget and display utilities
21- try : # pragma: no cover
22- # For IPython 4.x using ipywidgets
23- import ipywidgets
24- except ImportError : # pragma: no cover
25- # For IPython 3.x / 2.x
26- import warnings
27- with warnings .catch_warnings ():
28- ipy_deprecation_msg = "The `IPython.html` package has been deprecated"
29- warnings .filterwarnings ('error' ,
30- message = ".*" + ipy_deprecation_msg + ".*" )
31- try :
32- import IPython .html .widgets as ipywidgets
33- except Warning as e :
34- if ipy_deprecation_msg not in str (e ):
35- raise
36- warnings .simplefilter ('ignore' )
20+ if True : # pragma: no cover
21+ # import IPython/Jupyter base widget and display utilities
22+ try : # IPython 4.x
23+ import ipywidgets
24+ except ImportError : # IPython 3.x / 2.x
25+ import warnings
26+ with warnings .catch_warnings ():
27+ ipy_deprecation_msg = "The `IPython.html` package" \
28+ " has been deprecated"
29+ warnings .filterwarnings ('error' ,
30+ message = ".*" + ipy_deprecation_msg + ".*" )
3731 try :
38- import IPython .html .widgets as ipywidgets # NOQA
32+ import IPython .html .widgets as ipywidgets
33+ except Warning as e :
34+ if ipy_deprecation_msg not in str (e ):
35+ raise
36+ warnings .simplefilter ('ignore' )
37+ try :
38+ import IPython .html .widgets as ipywidgets # NOQA
39+ except ImportError :
40+ pass
3941 except ImportError :
4042 pass
43+
44+ try : # IPython 4.x / 3.x
45+ from ipywidgets import IntProgress , HBox , HTML
46+ except ImportError :
47+ try : # IPython 2.x
48+ from ipywidgets import IntProgressWidget as IntProgress
49+ from ipywidgets import ContainerWidget as HBox
50+ from ipywidgets import HTML
4151 except ImportError :
4252 pass
4353
44- try : # pragma: no cover
45- # For IPython 4.x / 3.x
46- from ipywidgets import IntProgress , HBox , HTML
47- except ImportError : # pragma: no cover
4854 try :
49- # For IPython 2.x
50- from ipywidgets import IntProgressWidget as IntProgress
51- from ipywidgets import ContainerWidget as HBox
52- from ipywidgets import HTML
55+ from IPython .display import display # , clear_output
5356 except ImportError :
54- # from ._tqdm import tqdm, trange
55- # def warnWrap(fn, msg):
56- # def inner(*args, **kwargs):
57- # from sys import stderr
58- # stderr.write(msg)
59- # return fn(*args, **kwargs)
60- # return inner
61- # tqdm_notebook = warnWrap(tqdm, "Warning:\n\tNo ipywidgets."
62- # "\ntFalling back to `tqdm`.\n")
63- # tnrange = warnWrap(trange, "Warning:\n\tNo ipywidgets."
64- # "\n\tFalling back to `trange`.\n")
65- # exit
6657 pass
6758
68- try : # pragma: no cover
69- from IPython .display import display # , clear_output
70- except ImportError : # pragma: no cover
71- pass
72-
73- # HTML encoding
74- try : # pragma: no cover
75- from html import escape # python 3.x
76- except ImportError : # pragma: no cover
77- from cgi import escape # python 2.x
59+ # HTML encoding
60+ try : # Py3
61+ from html import escape
62+ except ImportError : # Py2
63+ from cgi import escape
7864
7965
8066__author__ = {"github.com/" : ["lrq3000" , "casperdcl" , "alexanderkuk" ]}
8167__all__ = ['tqdm_notebook' , 'tnrange' ]
8268
8369
84- class tqdm_notebook (tqdm ): # pragma: no cover
70+ class tqdm_notebook (tqdm ):
8571 """
8672 Experimental IPython/Jupyter Notebook widget using tqdm!
8773 """
@@ -97,8 +83,6 @@ def status_printer(file, total=None, desc=None):
9783 # return super(tqdm_notebook, tqdm_notebook).status_printer(file)
9884
9985 fp = file
100- if not getattr (fp , 'flush' , False ): # pragma: no cover
101- fp .flush = lambda : None
10286
10387 # Prepare IPython progress bar
10488 if total :
@@ -224,7 +208,7 @@ def moveto(*args, **kwargs):
224208 return
225209
226210
227- def tnrange (* args , ** kwargs ): # pragma: no cover
211+ def tnrange (* args , ** kwargs ):
228212 """
229213 A shortcut for tqdm_notebook(xrange(*args), **kwargs).
230214 On Python3+ range is used instead of xrange.
0 commit comments