Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

All-in-one pull request #17

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ nosetests.xml
.mr.developer.cfg
.project
.pydevproject

# PyCharm
.idea
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
tqdm
====

Instantly make your loops show a progress meter - just wrap any iterator with "tqdm(iterator)", and you're done!
[![Build Status](https://img.shields.io/travis/kmike/tqdm.svg?branch=all-fixes)](https://travis-ci.org/kmike/tqdm)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After merging this line should be changed.

  1. Sign in to https://travis-ci.org/, go to your Account settings and turn ON the switch near tqdm repo;
  2. Change this line to show a badge for the official repo:
[![Build Status](https://img.shields.io/travis/noamraph/tqdm.svg)](https://travis-ci.org/noamraph/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)

Expand Down Expand Up @@ -31,3 +33,9 @@ def trange(*args, **kwargs):
"""A shortcut for writing tqdm(xrange)"""
return tqdm(xrange(*args), **kwargs)
```

Running tests
-------------

Please make sure tox (http://tox.testrun.org/) is installed and type
`tox` from the command line.
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
python_files = test*.py
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[bdist_wheel]
universal = 1
35 changes: 25 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from setuptools import setup

from distutils.core import setup

setup(name='tqdm',
version='1.0',
description='A Simple Python Progress Meter',
author='Noam Yorav-Raphael',
author_email='[email protected]',
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='[email protected]',
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',
],
)
69 changes: 69 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from __future__ import unicode_literals

import csv
from six import StringIO
from tqdm import format_interval, format_meter, tqdm


def test_format_interval():
assert format_interval(60) == '01:00'
assert format_interval(6160) == '1:42:40'
assert format_interval(238113) == '66:08:33'


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: 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()
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


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()
13 changes: 13 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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, py33, py34, pypy, pypy3

[testenv]
commands = py.test
deps =
six
pytest
9 changes: 6 additions & 3 deletions tqdm.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -17,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)
Expand Down Expand Up @@ -71,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 ''
Expand Down