mirror of https://github.com/tqdm/tqdm.git
Merge branch 'master' into unicode
Conflicts: README.md tqdm/_tqdm.py
This commit is contained in:
commit
0c19feaf0c
|
@ -1,3 +1,4 @@
|
||||||
|
sudo: false
|
||||||
language: python
|
language: python
|
||||||
python: 2.7
|
python: 2.7
|
||||||
env:
|
env:
|
||||||
|
|
|
@ -33,7 +33,7 @@ pip install -e git+https://github.com/tqdm/tqdm.git#egg=master
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def tqdm(iterable, desc=None, total=None, leave=False, file=sys.stderr,
|
def tqdm(iterable, desc=None, total=None, leave=False, file=sys.stderr,
|
||||||
ncols=None, mininterval=0.1, miniters=None, ascii=None):
|
ncols=None, mininterval=0.1, miniters=None, ascii=None, disable=False):
|
||||||
"""
|
"""
|
||||||
Decorate an iterable object, returning an iterator which acts exactly
|
Decorate an iterable object, returning an iterator which acts exactly
|
||||||
like the orignal iterable, but prints a dynamically updating
|
like the orignal iterable, but prints a dynamically updating
|
||||||
|
@ -66,6 +66,8 @@ def tqdm(iterable, desc=None, total=None, leave=False, file=sys.stderr,
|
||||||
ascii : bool, optional
|
ascii : bool, optional
|
||||||
If not set, use unicode (▏▎▋█ █) to fill the meter
|
If not set, use unicode (▏▎▋█ █) to fill the meter
|
||||||
[default: False]. The fallback is to use ASCII characters (1-9 #).
|
[default: False]. The fallback is to use ASCII characters (1-9 #).
|
||||||
|
disable : bool
|
||||||
|
Disable the progress bar if True [default: False].
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
|
|
|
@ -90,9 +90,9 @@ def format_meter(n, total, elapsed, ncols=None, prefix='', ascii=False):
|
||||||
else:
|
else:
|
||||||
bar_length, frac_bar_length = divmod(int(frac * N_BARS * 8), 8)
|
bar_length, frac_bar_length = divmod(int(frac * N_BARS * 8), 8)
|
||||||
|
|
||||||
try:
|
try: # pragma: no cover
|
||||||
unich = unichr
|
unich = unichr
|
||||||
except NameError:
|
except NameError: # pragma: no cover
|
||||||
unich = chr
|
unich = chr
|
||||||
|
|
||||||
bar = unich(0x2588)*bar_length
|
bar = unich(0x2588)*bar_length
|
||||||
|
@ -122,7 +122,7 @@ class StatusPrinter(object):
|
||||||
|
|
||||||
|
|
||||||
def tqdm(iterable, desc=None, total=None, leave=False, file=sys.stderr,
|
def tqdm(iterable, desc=None, total=None, leave=False, file=sys.stderr,
|
||||||
ncols=None, mininterval=0.1, miniters=None, ascii=None):
|
ncols=None, mininterval=0.1, miniters=None, ascii=None, disable=False):
|
||||||
"""
|
"""
|
||||||
Decorate an iterable object, returning an iterator which acts exactly
|
Decorate an iterable object, returning an iterator which acts exactly
|
||||||
like the orignal iterable, but prints a dynamically updating
|
like the orignal iterable, but prints a dynamically updating
|
||||||
|
@ -155,19 +155,24 @@ def tqdm(iterable, desc=None, total=None, leave=False, file=sys.stderr,
|
||||||
ascii : bool, optional
|
ascii : bool, optional
|
||||||
If not set, use unicode (smooth blocks) to fill the meter
|
If not set, use unicode (smooth blocks) to fill the meter
|
||||||
[default: False]. The fallback is to use ASCII characters (1-9 #).
|
[default: False]. The fallback is to use ASCII characters (1-9 #).
|
||||||
|
disable : bool
|
||||||
|
Disable the progress bar if True [default: False].
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
out : decorated iterator.
|
out : decorated iterator.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if disable:
|
||||||
|
for obj in iterable:
|
||||||
|
yield obj
|
||||||
|
return
|
||||||
|
|
||||||
if total is None:
|
if total is None:
|
||||||
try:
|
try:
|
||||||
total = len(iterable)
|
total = len(iterable)
|
||||||
except (TypeError, AttributeError):
|
except (TypeError, AttributeError):
|
||||||
total = None
|
total = None
|
||||||
# not good for slow iterators
|
|
||||||
# elif not miniters:
|
|
||||||
# miniters = int(total/100)
|
|
||||||
|
|
||||||
if miniters is None:
|
if miniters is None:
|
||||||
miniters = 0
|
miniters = 0
|
||||||
|
@ -196,10 +201,8 @@ def tqdm(iterable, desc=None, total=None, leave=False, file=sys.stderr,
|
||||||
if cur_t - last_print_t >= mininterval:
|
if cur_t - last_print_t >= mininterval:
|
||||||
sp.print_status(format_meter(
|
sp.print_status(format_meter(
|
||||||
n, total, cur_t-start_t, ncols, prefix, ascii))
|
n, total, cur_t-start_t, ncols, prefix, ascii))
|
||||||
|
|
||||||
if dynamic_miniters:
|
if dynamic_miniters:
|
||||||
miniters = max(miniters, n - last_print_n + 1)
|
miniters = max(miniters, n - last_print_n + 1)
|
||||||
|
|
||||||
last_print_n = n
|
last_print_n = n
|
||||||
last_print_t = cur_t
|
last_print_t = cur_t
|
||||||
|
|
||||||
|
@ -219,9 +222,9 @@ def trange(*args, **kwargs):
|
||||||
A shortcut for tqdm(xrange(*args), **kwargs).
|
A shortcut for tqdm(xrange(*args), **kwargs).
|
||||||
On Python3+ range is used instead of xrange.
|
On Python3+ range is used instead of xrange.
|
||||||
"""
|
"""
|
||||||
try:
|
try: # pragma: no cover
|
||||||
f = xrange
|
f = xrange
|
||||||
except NameError:
|
except NameError: # pragma: no cover
|
||||||
f = range
|
f = range
|
||||||
|
|
||||||
return tqdm(f(*args), **kwargs)
|
return tqdm(f(*args), **kwargs)
|
||||||
|
|
|
@ -50,7 +50,7 @@ def test_iterate_over_csv_rows():
|
||||||
test_csv_file = StringIO()
|
test_csv_file = StringIO()
|
||||||
writer = csv.writer(test_csv_file)
|
writer = csv.writer(test_csv_file)
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
writer.writerow(['test']*3)
|
writer.writerow(['test'] * 3)
|
||||||
test_csv_file.seek(0)
|
test_csv_file.seek(0)
|
||||||
|
|
||||||
# Test that nothing fails if we iterate over rows
|
# Test that nothing fails if we iterate over rows
|
||||||
|
@ -118,3 +118,11 @@ def test_min_iters():
|
||||||
our_file.write('blank\n')
|
our_file.write('blank\n')
|
||||||
our_file.seek(0)
|
our_file.seek(0)
|
||||||
assert '\nblank\nblank\n' in our_file.read()
|
assert '\nblank\nblank\n' in our_file.read()
|
||||||
|
|
||||||
|
|
||||||
|
def test_disable():
|
||||||
|
our_file = StringIO()
|
||||||
|
for i in tqdm(range(3), file=our_file, disable=True):
|
||||||
|
pass
|
||||||
|
our_file.seek(0)
|
||||||
|
assert our_file.read() == ""
|
||||||
|
|
Loading…
Reference in New Issue