Skip to content

Commit 0d08718

Browse files
committed
Merge branch 'release/4.2.0'
2 parents c2a73b1 + 3e997e8 commit 0d08718

File tree

9 files changed

+122
-12
lines changed

9 files changed

+122
-12
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2015, Rick van Hattem (Wolph)
1+
Copyright (c) 2022, Rick van Hattem (Wolph)
22
All rights reserved.
33

44
Redistribution and use in source and binary forms, with or without

docs/history.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. _history:
2+
3+
=======
4+
History
5+
=======
6+
7+
.. include:: ../CHANGES.rst
8+
:start-line: 5

docs/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Welcome to Progress Bar's documentation!
55
.. toctree::
66
:maxdepth: 4
77

8+
usage
89
examples
910
contributing
1011
installation
@@ -13,6 +14,7 @@ Welcome to Progress Bar's documentation!
1314
progressbar.base
1415
progressbar.utils
1516
progressbar.widgets
17+
history
1618

1719
.. include:: ../README.rst
1820

docs/progressbar.bar.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ progressbar.bar module
55
:members:
66
:undoc-members:
77
:show-inheritance:
8+
:member-order: bysource

docs/usage.rst

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
========
2+
Usage
3+
========
4+
5+
There are many ways to use Python Progressbar, you can see a few basic examples
6+
here but there are many more in the :doc:`examples` file.
7+
8+
Wrapping an iterable
9+
------------------------------------------------------------------------------
10+
::
11+
12+
import time
13+
import progressbar
14+
15+
bar = progressbar.ProgressBar()
16+
for i in bar(range(100)):
17+
time.sleep(0.02)
18+
19+
Context wrapper
20+
------------------------------------------------------------------------------
21+
::
22+
23+
import time
24+
import progressbar
25+
26+
with progressbar.ProgressBar(max_value=10) as bar:
27+
for i in range(10):
28+
time.sleep(0.1)
29+
bar.update(i)
30+
31+
Combining progressbars with print output
32+
------------------------------------------------------------------------------
33+
::
34+
35+
import time
36+
import progressbar
37+
38+
bar = progressbar.ProgressBar(redirect_stdout=True)
39+
for i in range(100):
40+
print 'Some text', i
41+
time.sleep(0.1)
42+
bar.update(i)
43+
44+
Progressbar with unknown length
45+
------------------------------------------------------------------------------
46+
::
47+
48+
import time
49+
import progressbar
50+
51+
bar = progressbar.ProgressBar(max_value=progressbar.UnknownLength)
52+
for i in range(20):
53+
time.sleep(0.1)
54+
bar.update(i)
55+
56+
Bar with custom widgets
57+
------------------------------------------------------------------------------
58+
::
59+
60+
import time
61+
import progressbar
62+
63+
bar = progressbar.ProgressBar(widgets=[
64+
' [', progressbar.Timer(), '] ',
65+
progressbar.Bar(),
66+
' (', progressbar.ETA(), ') ',
67+
])
68+
for i in bar(range(20)):
69+
time.sleep(0.1)
70+

progressbar/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
long running operations.
2020
'''.strip().split())
2121
__email__ = '[email protected]'
22-
__version__ = '4.1.1'
22+
__version__ = '4.2.0'
2323
__license__ = 'BSD'
2424
__copyright__ = 'Copyright 2015 Rick van Hattem (Wolph)'
2525
__url__ = 'https://github.com/WoLpH/python-progressbar'

progressbar/bar.py

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
logger = logging.getLogger(__name__)
2828

2929

30+
T = types.TypeVar('T')
31+
32+
3033
class ProgressBarMixinBase(object):
3134

3235
def __init__(self, **kwargs):
@@ -265,16 +268,21 @@ class ProgressBar(StdRedirectMixin, ResizableMixin, ProgressBarBase):
265268
the current progress bar. As a result, you have access to the
266269
ProgressBar's methods and attributes. Although there is nothing preventing
267270
you from changing the ProgressBar you should treat it as read only.
268-
269-
Useful methods and attributes include (Public API):
270-
- value: current progress (min_value <= value <= max_value)
271-
- max_value: maximum (and final) value
272-
- end_time: not None if the bar has finished (reached 100%)
273-
- start_time: the time when start() method of ProgressBar was called
274-
- seconds_elapsed: seconds elapsed since start_time and last call to
275-
update
276271
'''
277272

273+
#: Current progress (min_value <= value <= max_value)
274+
value: T
275+
#: Maximum (and final) value. Beyond this value an error will be raised
276+
#: unless the `max_error` parameter is `False`.
277+
max_value: T
278+
#: The time the progressbar reached `max_value` or when `finish()` was
279+
#: called.
280+
end_time: datetime
281+
#: The time `start()` was called or iteration started.
282+
start_time: datetime
283+
#: Seconds between `start_time` and last call to `update()`
284+
seconds_elapsed: float
285+
278286
_DEFAULT_MAXVAL = base.UnknownLength
279287
# update every 50 milliseconds (up to a 20 times per second)
280288
_MINIMUM_UPDATE_INTERVAL = 0.050
@@ -568,7 +576,10 @@ def __enter__(self):
568576

569577
def __iadd__(self, value):
570578
'Updates the ProgressBar by adding a new value.'
571-
self.update(self.value + value)
579+
return self.increment(value)
580+
581+
def increment(self, value=1, *args, **kwargs):
582+
self.update(self.value + value, *args, **kwargs)
572583
return self
573584

574585
def _format_widgets(self):
@@ -788,6 +799,16 @@ def finish(self, end='\n', dirty=False):
788799
ResizableMixin.finish(self)
789800
ProgressBarBase.finish(self)
790801

802+
@property
803+
def currval(self):
804+
'''
805+
Legacy method to make progressbar-2 compatible with the original
806+
progressbar package
807+
'''
808+
warnings.warn('The usage of `currval` is deprecated, please use '
809+
'`value` instead', DeprecationWarning)
810+
return self.value
811+
791812

792813
class DataTransferBar(ProgressBar):
793814
'''A progress bar with sensible defaults for downloads etc.

tests/test_failure.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ def test_deprecated_poll():
9999
progressbar.ProgressBar(poll=5)
100100

101101

102+
def test_deprecated_currval():
103+
with pytest.warns(DeprecationWarning):
104+
bar = progressbar.ProgressBar(max_value=5)
105+
bar.update(2)
106+
assert bar.currval == 2
107+
108+
102109
def test_unexpected_update_keyword_arg():
103110
p = progressbar.ProgressBar(max_value=10)
104111
with pytest.raises(TypeError):

tests/test_iterators.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ def test_adding_value():
5151
p = progressbar.ProgressBar(max_value=10)
5252
p.start()
5353
p.update(5)
54-
p += 5
54+
p += 2
55+
p.increment(2)
5556
with pytest.raises(ValueError):
5657
p += 5
5758

0 commit comments

Comments
 (0)