From 777314ce9a7f2b5fa842e010d899ea993a3025f7 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Mon, 3 Feb 2014 22:08:20 +1300 Subject: [PATCH 01/17] Ignore PyCharm IDE config files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index ded6067..1a1f52a 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,6 @@ nosetests.xml .mr.developer.cfg .project .pydevproject + +# PyCharm +.idea From da4b29f3cd48726b21d1c37aff854d3e29ce1507 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Mon, 3 Feb 2014 22:45:38 +1300 Subject: [PATCH 02/17] First dumb test --- pytest.ini | 2 ++ tests.py | 9 +++++++++ tox.ini | 12 ++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 pytest.ini create mode 100644 tests.py create mode 100644 tox.ini diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..258cfb7 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +python_files = test*.py \ No newline at end of file diff --git a/tests.py b/tests.py new file mode 100644 index 0000000..bd45004 --- /dev/null +++ b/tests.py @@ -0,0 +1,9 @@ +from __future__ import unicode_literals +from tqdm import format_interval + + +def test_format_interval(): + assert format_interval(60) == '01:00' + assert format_interval(6160) == '1:42:40' + assert format_interval(238113) == '66:08:33' + diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..ecd9f5e --- /dev/null +++ b/tox.ini @@ -0,0 +1,12 @@ +# Tox (http://tox.testrun.org/) is a tool for running tests +# in multiple virtualenvs. This configuration file will run the +# test suite on all supported python versions. To use it, "pip install tox" +# and then run "tox" from this directory. + +[tox] +envlist = py26, py27, py32 + +[testenv] +commands = py.test +deps = + pytest \ No newline at end of file From a16cdc66c0c090e3320ceb4956dd3e711d824a2a Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Mon, 3 Feb 2014 22:47:50 +1300 Subject: [PATCH 03/17] New lines at the end of files --- pytest.ini | 2 +- tox.ini | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pytest.ini b/pytest.ini index 258cfb7..8722621 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,2 @@ [pytest] -python_files = test*.py \ No newline at end of file +python_files = test*.py diff --git a/tox.ini b/tox.ini index ecd9f5e..8493648 100644 --- a/tox.ini +++ b/tox.ini @@ -9,4 +9,4 @@ envlist = py26, py27, py32 [testenv] commands = py.test deps = - pytest \ No newline at end of file + pytest From 2f46d5468b7eaabfb23081669e6c1c2760a1bc16 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Mon, 3 Feb 2014 22:59:28 +1300 Subject: [PATCH 04/17] Test of format_meter (failed on py32) --- tests.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests.py b/tests.py index bd45004..220cfa9 100644 --- a/tests.py +++ b/tests.py @@ -1,5 +1,5 @@ from __future__ import unicode_literals -from tqdm import format_interval +from tqdm import format_interval, format_meter def test_format_interval(): @@ -7,3 +7,9 @@ def test_format_interval(): assert format_interval(6160) == '1:42:40' assert format_interval(238113) == '66:08:33' + +def test_format_meter(): + assert format_meter(231, 1000, 392) == \ + "|##--------| 231/1000 23% [elapsed: " \ + "06:32 left: 12:49, 0.00 iters/sec]" + From 8bb8a1731be429f1a93dbc2b351e747faf355960 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Tue, 4 Feb 2014 22:17:48 +1300 Subject: [PATCH 05/17] Another format meter test --- tests.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests.py b/tests.py index 220cfa9..a208487 100644 --- a/tests.py +++ b/tests.py @@ -9,7 +9,9 @@ def test_format_interval(): def test_format_meter(): + assert format_meter(0, 1000, 13) == \ + "|----------| 0/1000 0% [elapsed: " \ + "00:13 left: ?, 0.00 iters/sec]" assert format_meter(231, 1000, 392) == \ "|##--------| 231/1000 23% [elapsed: " \ "06:32 left: 12:49, 0.00 iters/sec]" - From e2e15d1f4dae5e3dd190cd0ebfee8537723b600d Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Wed, 5 Feb 2014 21:18:41 +1300 Subject: [PATCH 06/17] Fixed the calculation of rate in format_meter --- tests.py | 2 +- tqdm.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tests.py b/tests.py index a208487..f003757 100644 --- a/tests.py +++ b/tests.py @@ -14,4 +14,4 @@ def test_format_meter(): "00:13 left: ?, 0.00 iters/sec]" assert format_meter(231, 1000, 392) == \ "|##--------| 231/1000 23% [elapsed: " \ - "06:32 left: 12:49, 0.00 iters/sec]" + "06:32 left: 21:44, 0.59 iters/sec]" diff --git a/tqdm.py b/tqdm.py index 8c21092..aede108 100644 --- a/tqdm.py +++ b/tqdm.py @@ -1,9 +1,12 @@ -__all__ = ['tqdm', 'trange'] +from __future__ import division import sys import time +__all__ = ['tqdm', 'trange'] + + def format_interval(t): mins, s = divmod(int(t), 60) h, m = divmod(mins, 60) From 5f0c72dfd6a82891bd92c96ff6cae4872faf8357 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Wed, 5 Feb 2014 21:19:33 +1300 Subject: [PATCH 07/17] Readme: how to run tests --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index f65d305..2e2aaf6 100644 --- a/README.md +++ b/README.md @@ -31,3 +31,9 @@ def trange(*args, **kwargs): """A shortcut for writing tqdm(xrange)""" return tqdm(xrange(*args), **kwargs) ``` + +Running tests +------------- + +Please make sure tox (http://tox.testrunner.org/) is installed and type +`tox` from the command line \ No newline at end of file From 7b62451047dc3aa7d2acefccbef1a57cc15e933a Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Wed, 5 Feb 2014 21:20:24 +1300 Subject: [PATCH 08/17] Fixed the link to tox --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2e2aaf6..16d03e9 100644 --- a/README.md +++ b/README.md @@ -35,5 +35,5 @@ def trange(*args, **kwargs): Running tests ------------- -Please make sure tox (http://tox.testrunner.org/) is installed and type +Please make sure tox (http://tox.testrun.org/) is installed and type `tox` from the command line \ No newline at end of file From ff2b39a1537a01c2eae576ba5b8da01dfaa55c8f Mon Sep 17 00:00:00 2001 From: Ford Hurley Date: Wed, 5 Feb 2014 16:13:51 -0500 Subject: [PATCH 09/17] Change 'iterator' to 'iterable' in README http://docs.python.org/2/glossary.html#term-iterable --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f65d305..c77c914 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ tqdm ==== -Instantly make your loops show a progress meter - just wrap any iterator with "tqdm(iterator)", and you're done! +Instantly make your loops show a progress meter - just wrap any iterable with "tqdm(iterable)", and you're done! ![ScreenShot](https://i.imgur.com/he9Aw5C.gif) From 4539ebc92d59dd0388658fa482626185088222b8 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Fri, 7 Feb 2014 14:25:36 +1300 Subject: [PATCH 10/17] Test that tqdm fails when iterating over a csv file --- tests.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tests.py b/tests.py index f003757..8f515ef 100644 --- a/tests.py +++ b/tests.py @@ -1,5 +1,7 @@ from __future__ import unicode_literals -from tqdm import format_interval, format_meter +from StringIO import StringIO +import csv +from tqdm import format_interval, format_meter, tqdm def test_format_interval(): @@ -15,3 +17,17 @@ def test_format_meter(): assert format_meter(231, 1000, 392) == \ "|##--------| 231/1000 23% [elapsed: " \ "06:32 left: 21:44, 0.59 iters/sec]" + + +def test_iterate_over_csv_rows(): + # Create a test csv pseudo file + test_csv_file = StringIO() + writer = csv.writer(test_csv_file) + for i in range(3): + writer.writerow(['test', 'test', 'test']) + test_csv_file.seek(0) + + # Test that nothing fails if we iterate over rows + reader = csv.DictReader(test_csv_file, fieldnames=('row1', 'row2', 'row3')) + for row in tqdm(reader): + pass From f565179a2e4487610790a8fdeccd0cccf2f2e2cb Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Fri, 7 Feb 2014 14:31:14 +1300 Subject: [PATCH 11/17] Another python 3 fix --- tests.py | 2 +- tox.ini | 1 + tqdm.py | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests.py b/tests.py index 8f515ef..bdd31d3 100644 --- a/tests.py +++ b/tests.py @@ -1,5 +1,5 @@ from __future__ import unicode_literals -from StringIO import StringIO +from six import StringIO import csv from tqdm import format_interval, format_meter, tqdm diff --git a/tox.ini b/tox.ini index 8493648..64b1e7b 100644 --- a/tox.ini +++ b/tox.ini @@ -9,4 +9,5 @@ envlist = py26, py27, py32 [testenv] commands = py.test deps = + six pytest diff --git a/tqdm.py b/tqdm.py index aede108..14fcbe5 100644 --- a/tqdm.py +++ b/tqdm.py @@ -20,7 +20,7 @@ def format_meter(n, total, elapsed): # n - number of finished iterations # total - total number of iterations, or None # elapsed - number of seconds passed since start - if n > total: + if total and n > total: total = None elapsed_str = format_interval(elapsed) @@ -74,7 +74,7 @@ def tqdm(iterable, desc='', total=None, leave=False, file=sys.stderr, if total is None: try: total = len(iterable) - except TypeError: + except (TypeError, AttributeError): total = None prefix = desc+': ' if desc else '' From 152dfd55bd5b53e6967acb97286b5b6a8faa7ab8 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Fri, 7 Feb 2014 19:49:09 +1300 Subject: [PATCH 12/17] Some more tests --- tests.py | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/tests.py b/tests.py index bdd31d3..3b49e3d 100644 --- a/tests.py +++ b/tests.py @@ -1,6 +1,8 @@ from __future__ import unicode_literals -from six import StringIO + import csv +import sys +from six import StringIO from tqdm import format_interval, format_meter, tqdm @@ -19,6 +21,12 @@ def test_format_meter(): "06:32 left: 21:44, 0.59 iters/sec]" +def test_nothing_fails(): + """ Just make sure we're able to iterate using tqdm """ + for i in tqdm(range(10)): + pass + + def test_iterate_over_csv_rows(): # Create a test csv pseudo file test_csv_file = StringIO() @@ -31,3 +39,32 @@ def test_iterate_over_csv_rows(): reader = csv.DictReader(test_csv_file, fieldnames=('row1', 'row2', 'row3')) for row in tqdm(reader): pass + + +def test_file_output(): + """ Tests that output to arbitrary file-like objects works """ + our_file = StringIO() + for i in tqdm(range(3), file=our_file): + if i == 1: + our_file.seek(0) + assert '0/3' in our_file.read() + + +def test_leave_option(): + """ + Tests that if leave=True, tqdm will leave the info + about the last iteration on the screen + """ + our_file = StringIO() + for i in tqdm(range(3), file=our_file, leave=True): + pass + our_file.seek(0) + assert '3/3 100%' in our_file.read() + our_file.close() + + our_file2 = StringIO() + for i in tqdm(range(3), file=our_file2, leave=False): + pass + our_file2.seek(0) + assert '3/3 100%' not in our_file2.read() + our_file2.close() \ No newline at end of file From cbc632262f0a8eaf3c5d2d65b866c37f29744513 Mon Sep 17 00:00:00 2001 From: stonebig Date: Sat, 24 Jan 2015 14:23:14 +0100 Subject: [PATCH 13/17] do my wheel ! python setup.py sdist bdist_wheel --- setup.cfg | 2 ++ setup.py | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 setup.cfg diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..2a9acf1 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[bdist_wheel] +universal = 1 diff --git a/setup.py b/setup.py index 7b36604..1e357a0 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,6 @@ #!/usr/bin/env python - -from distutils.core import setup - +# -*- coding: utf-8 -*- +from setuptools import setup setup(name='tqdm', version='1.0', description='A Simple Python Progress Meter', From 3d9fd154bcc75686706d00c4fc7bbe26988be99c Mon Sep 17 00:00:00 2001 From: Mikhail Korobov Date: Fri, 17 Apr 2015 03:49:22 +0500 Subject: [PATCH 14/17] add more interpreters to tox.ini --- tests.py | 3 +-- tox.ini | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests.py b/tests.py index 3b49e3d..c377bf1 100644 --- a/tests.py +++ b/tests.py @@ -1,7 +1,6 @@ from __future__ import unicode_literals import csv -import sys from six import StringIO from tqdm import format_interval, format_meter, tqdm @@ -67,4 +66,4 @@ def test_leave_option(): pass our_file2.seek(0) assert '3/3 100%' not in our_file2.read() - our_file2.close() \ No newline at end of file + our_file2.close() diff --git a/tox.ini b/tox.ini index 64b1e7b..00fd947 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,7 @@ # and then run "tox" from this directory. [tox] -envlist = py26, py27, py32 +envlist = py26, py27, py32, py33, py34, pypy, pypy3 [testenv] commands = py.test From 888775afe7552b0f93bb23f2e86667f677523824 Mon Sep 17 00:00:00 2001 From: Mikhail Korobov Date: Fri, 17 Apr 2015 03:49:46 +0500 Subject: [PATCH 15/17] add Travis CI --- .travis.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..b509775 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +language: python +python: 2.7 +env: +- TOXENV=py26 +- TOXENV=py27 +- TOXENV=py32 +- TOXENV=py33 +- TOXENV=py34 +- TOXENV=pypy +- TOXENV=pypy3 +install: +- pip install tox +script: +- tox From 4c979245b5d7749b381b22daa11ed719369eed9d Mon Sep 17 00:00:00 2001 From: Mikhail Korobov Date: Fri, 17 Apr 2015 04:01:18 +0500 Subject: [PATCH 16/17] add license and Python version info to setup.py --- setup.py | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/setup.py b/setup.py index 1e357a0..2b9a035 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,27 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- from setuptools import setup -setup(name='tqdm', - version='1.0', - description='A Simple Python Progress Meter', - author='Noam Yorav-Raphael', - author_email='noamraph@gmail.com', - url='https://github.com/noamraph/tqdm', - py_modules=['tqdm'], - ) + +setup( + name='tqdm', + version='1.0', + description='A Simple Python Progress Meter', + license='MIT License', + author='Noam Yorav-Raphael', + author_email='noamraph@gmail.com', + url='https://github.com/noamraph/tqdm', + py_modules=['tqdm'], + classifiers=[ + 'Development Status :: 5 - Production/Stable', + 'License :: OSI Approved :: MIT License', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.6', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.2', + 'Programming Language :: Python :: 3.3', + 'Programming Language :: Python :: 3.4', + 'Topic :: Software Development :: Libraries', + 'Intended Audience :: Developers', + ], +) From ecc79f96291ca5f704cf56330598070d4798f89a Mon Sep 17 00:00:00 2001 From: Mikhail Korobov Date: Fri, 17 Apr 2015 04:04:02 +0500 Subject: [PATCH 17/17] add Travis badge to README currently it points to my repo --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 68e5dea..b749ccf 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ tqdm ==== +[![Build Status](https://img.shields.io/travis/kmike/tqdm.svg?branch=all-fixes)](https://travis-ci.org/kmike/tqdm) + Instantly make your loops show a progress meter - just wrap any iterable with "tqdm(iterable)", and you're done! ![ScreenShot](https://i.imgur.com/he9Aw5C.gif) @@ -36,4 +38,4 @@ Running tests ------------- Please make sure tox (http://tox.testrun.org/) is installed and type -`tox` from the command line \ No newline at end of file +`tox` from the command line.