Skip to content

Commit

Permalink
Reorganize tqdm modules architecture to avoid unnecessary imports
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen L. <lrq3000@gmail.com>
  • Loading branch information
lrq3000 committed Jul 18, 2016
1 parent bb53160 commit 9b7cf20
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 42 deletions.
25 changes: 3 additions & 22 deletions tqdm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,9 @@
from ._tqdm import tqdm
from ._tqdm import trange
from ._tqdm_gui import tqdm_gui
from ._tqdm_gui import tgrange
from ._tqdm_pandas import tqdm_pandas
from .core import tqdm
from .core import trange
from ._main import main
from ._main import TqdmKeyError
from ._main import TqdmTypeError
from ._version import __version__ # NOQA

__all__ = ['tqdm', 'tqdm_gui', 'trange', 'tgrange', 'tqdm_pandas',
'tqdm_notebook', 'tnrange', 'main', 'TqdmKeyError', 'TqdmTypeError',
__all__ = ['tqdm', 'trange', 'main', 'TqdmKeyError', 'TqdmTypeError',
'__version__']


def tqdm_notebook(*args, **kwargs): # pragma: no cover
"""See tqdm._tqdm_notebook.tqdm_notebook for full documentation"""
from ._tqdm_notebook import tqdm_notebook as _tqdm_notebook
return _tqdm_notebook(*args, **kwargs)


def tnrange(*args, **kwargs): # pragma: no cover
"""
A shortcut for tqdm_notebook(xrange(*args), **kwargs).
On Python3+ range is used instead of xrange.
"""
from ._tqdm_notebook import tnrange as _tnrange
return _tnrange(*args, **kwargs)
2 changes: 1 addition & 1 deletion tqdm/_main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ._tqdm import tqdm
from .core import tqdm
from ._version import __version__ # NOQA
import sys
import re
Expand Down
2 changes: 1 addition & 1 deletion tqdm/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
__all__ = ["__version__"]

# major, minor, patch, -extra
version_info = 4, 7, 6
version_info = 5, 0, 0

# Nice string for the version
__version__ = '.'.join(map(str, version_info))
Expand Down
File renamed without changes.
16 changes: 8 additions & 8 deletions tqdm/_tqdm_gui.py → tqdm/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Includes a default (x)range iterator printing to stderr.
Usage:
>>> from tqdm_gui import tgrange[, tqdm_gui]
>>> for i in tgrange(10): #same as: for i in tqdm_gui(xrange(10))
>>> from tqdm.gui import trange[, tqdm]
>>> for i in trange(10): #same as: for i in tqdm(xrange(10))
... ...
"""
# future division is important to divide integers and get as
Expand All @@ -15,14 +15,14 @@
from time import time
from ._utils import _range
# to inherit from the tqdm class
from ._tqdm import tqdm
from .core import tqdm


__author__ = {"github.com/": ["casperdcl", "lrq3000"]}
__all__ = ['tqdm_gui', 'tgrange']
__all__ = ['tqdm', 'trange']


class tqdm_gui(tqdm): # pragma: no cover
class tqdm(tqdm): # pragma: no cover
"""
Experimental GUI version of tqdm!
"""
Expand Down Expand Up @@ -354,9 +354,9 @@ def close(self):
self.plt.close(self.fig)


def tgrange(*args, **kwargs):
def trange(*args, **kwargs):
"""
A shortcut for tqdm_gui(xrange(*args), **kwargs).
A shortcut for tqdm(xrange(*args), **kwargs).
On Python3+ range is used instead of xrange.
"""
return tqdm_gui(_range(*args), **kwargs)
return tqdm(_range(*args), **kwargs)
14 changes: 7 additions & 7 deletions tqdm/_tqdm_notebook.py → tqdm/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Includes a default (x)range iterator printing to stderr.
Usage:
>>> from tqdm_notebook import tnrange[, tqdm_notebook]
>>> for i in tnrange(10): #same as: for i in tqdm_notebook(xrange(10))
>>> from tqdm.notebook import trange[, tqdm]
>>> for i in trange(10): #same as: for i in tqdm(xrange(10))
... ...
"""
# future division is important to divide integers and get as
Expand All @@ -14,7 +14,7 @@
import sys
from ._utils import _range
# to inherit from the tqdm class
from ._tqdm import tqdm
from .core import tqdm


if True: # pragma: no cover
Expand Down Expand Up @@ -64,10 +64,10 @@


__author__ = {"github.com/": ["lrq3000", "casperdcl", "alexanderkuk"]}
__all__ = ['tqdm_notebook', 'tnrange']
__all__ = ['tqdm', 'trange']


class tqdm_notebook(tqdm):
class tqdm(tqdm):
"""
Experimental IPython/Jupyter Notebook widget using tqdm!
"""
Expand Down Expand Up @@ -211,9 +211,9 @@ def moveto(*args, **kwargs):
return


def tnrange(*args, **kwargs):
def trange(*args, **kwargs):
"""
A shortcut for tqdm_notebook(xrange(*args), **kwargs).
A shortcut for tqdm(xrange(*args), **kwargs).
On Python3+ range is used instead of xrange.
"""
return tqdm_notebook(_range(*args), **kwargs)
File renamed without changes.
6 changes: 3 additions & 3 deletions tqdm/tests/tests_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_pandas_groupby_apply():
""" Test pandas.DataFrame.groupby(...).progress_apply """
try:
from numpy.random import randint
from tqdm import tqdm_pandas
from tqdm.pandas import tqdm_pandas
import pandas as pd
except:
raise SkipTest
Expand Down Expand Up @@ -39,7 +39,7 @@ def test_pandas_apply():
""" Test pandas.DataFrame[.series].progress_apply """
try:
from numpy.random import randint
from tqdm import tqdm_pandas
from tqdm.pandas import tqdm_pandas
import pandas as pd
except:
raise SkipTest
Expand All @@ -66,7 +66,7 @@ def test_pandas_leave():
""" Test pandas with `leave=True` """
try:
from numpy.random import randint
from tqdm import tqdm_pandas
from tqdm.pandas import tqdm_pandas
import pandas as pd
except:
raise SkipTest
Expand Down

0 comments on commit 9b7cf20

Please sign in to comment.