Skip to content

Commit 6c08e70

Browse files
committed
PyLoadBar Hotfix Update v0.0.9.1
- Implemented customizeable iteration length of text-sequence - was missing from v0.0.9. - Expanded upon source code docstrings. - Updated README.md sections and added more content. - Appropriately renamed several parameters. -Rewrote tests. Signed-off-by: schlopp96 <71921821+schlopp96@users.noreply.github.com>
1 parent c7b536a commit 6c08e70

4 files changed

Lines changed: 96 additions & 78 deletions

File tree

PyLoadBar/main.py

Lines changed: 57 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
chdir(dirname(__file__)) # Change working directory to main module.
1515

16-
__version__ = '0.0.9'
16+
__version__ = '0.0.9.1'
1717

1818

1919
class PyLoadBar:
@@ -25,11 +25,11 @@ class PyLoadBar:
2525
2626
- When instantiating a new :class:`PyLoadBar` object, you can set the following parameters:
2727
- Set custom start/completion messages by passing string to :param:`msg_loading` and :param:`msg_complete` respectively.
28-
- Toggle visual progress meter using :param:`enable_display`.
28+
- Toggle visual progress meter using :param:`enable_bar`.
2929
- Apply label to progress meter by passing string to :param:`label` (set to `None` by default)
30-
- Note that :param:`enable_display` must be set to `True` for this to take effect.
30+
- Note that :param:`enable_bar` must be set to `True` for this to take effect.
3131
32-
- When calling :func:`start(self, iter_total, min_iter, max_iter)`:
32+
- When calling :func:`start(self, iter_total, min_iter, max_iter, txt_seq_speed)`:
3333
- Optionally set the total number of iterations to run using :param:`iter_total`, defaults to 5.
3434
- Optionally set the minimum/maximum iteration length in seconds using the :param:`min_iter` and :param:`max_iter` parameters respectively
3535
- Default values are `min_iter: 0.1` seconds and `max_iter: 1.0` seconds
@@ -39,7 +39,7 @@ def __init__(self,
3939
msg_loading: str | None = 'Loading',
4040
msg_complete: str | None = 'Done!',
4141
label: str | None = None,
42-
enable_display: bool = True) -> None:
42+
enable_bar: bool = True) -> None:
4343
"""Initialize loading sequence with set configuration.
4444
4545
---
@@ -50,56 +50,61 @@ def __init__(self,
5050
:type msg_complete: :class:`str` | None, optional
5151
:param label: label displayed alongside progress bar, defaults to None
5252
:type label: :class:`str` | None, optional
53-
:param enable_display: toggle visible progress meter, defaults to `True`
54-
:type enable_display: :class:`bool`, optional
53+
:param enable_bar: toggle visible progress bar, defaults to `True`
54+
:type enable_bar: :class:`bool`, optional
5555
:return: :class:`PyLoadBar` object
5656
:rtype: None
5757
"""
5858

5959
self.msg_loading: str | None = msg_loading
6060
self.msg_complete: str | None = msg_complete
6161
self.label: str | None = label
62-
self.enable_display: bool = enable_display
62+
self.enable_bar: bool = enable_bar
6363

64-
if self.enable_display and self.msg_loading == 'Loading':
65-
self.msg_loading = f'{msg_loading}...' # Add ellipses to default loading message.
64+
if self.enable_bar and self.msg_loading == 'Loading':
65+
self.msg_loading = f'{msg_loading}...' # Add ellipses to default progress-bar starting message.
6666

6767
def start(
6868
self,
69-
iter_total: int = 5,
70-
min_iter: float = 0.05,
71-
max_iter: float = 1.0,
69+
iter_total: int = 10,
70+
min_iter: float = 0.01,
71+
max_iter: float = 0.5,
72+
txt_seq_speed: float = 0.5,
7273
) -> None:
7374
"""Start loading sequence.
7475
7576
---
7677
7778
Settings:
7879
79-
- Set the total number of iterations using the :param:`iter_total` parameter
80+
- Set the total number of iterations to complete using the :param:`iter_total` parameter.
8081
81-
- Set the minimum/maximum iteration length in seconds using the :param:`min_iter` and :param:`max_iter` parameters respectively
82-
- Default values are `min_iter` = 0.1 seconds and `max_iter` = 1.0 seconds
83-
- Time of each iteration is randomized between values of :param:`min_iter` and :param:`max_iter`
82+
- Set the minimum/maximum iteration length in seconds using the :param:`min_iter` and :param:`max_iter` parameters respectively.
83+
- Time taken by each individual iteration is randomized within range of :param:`min_iter` and :param:`max_iter`.
84+
85+
- Set number of seconds to complete a single text-sequence iteration using :param:`txt_seq_speed`.
86+
-
8487
8588
---
8689
8790
:param iter_total: total amount of iterations to run, defaults to 5
8891
:type iter_total: :class:`int`, optional
8992
:param min_iter: minimum possible time to complete an iteration, defaults to 0.05 seconds
90-
:type min_iter: :class:`int`, optional
91-
:param max_iter: maximum possible time to complete an iteration, defaults to 1.0 seconds
92-
:type max_iter: :class:`int`, optional
93-
:return: Loading sequence
93+
:type min_iter: :class:`float`, optional
94+
:param max_iter: maximum possible time to complete an iteration, defaults to 0.25 seconds
95+
:type max_iter: :class:`float`, optional
96+
:param txt_seq_speed: number of seconds to complete a single text-sequence iteration, defaults to 0.5 seconds
97+
:type txt_seq_speed: :class:`float`, optional
98+
:return: enable loading sequence
9499
:rtype: None
95100
"""
96101

97102
try:
98-
if self.enable_display:
99-
self.__loadseq_A(iter_total, min_iter, max_iter)
103+
if self.enable_bar:
104+
self.__bar_seq(iter_total, min_iter, max_iter)
100105

101106
else:
102-
self.__loadseq_B(iter_total)
107+
self.__text_seq(iter_total, txt_seq_speed)
103108

104109
sleep(
105110
0.5
@@ -108,10 +113,10 @@ def start(
108113
except Exception as e:
109114
print(f'Error: {e}')
110115

111-
def __loadseq_A(self, iter_total: int, min_iter: float,
112-
max_iter: float) -> None:
116+
def __bar_seq(self, iter_total: int, min_iter: float,
117+
max_iter: float) -> None:
113118
"""
114-
Run loading sequence and display current progress with graphical progress bar.
119+
Run loading sequence with progress bar.
115120
116121
---
117122
@@ -141,54 +146,64 @@ def __loadseq_A(self, iter_total: int, min_iter: float,
141146
:rtype: None
142147
"""
143148

144-
print(f'\n{self.msg_loading}\n')
149+
print(f'{self.msg_loading}\n')
145150

146-
# Start loading sequence.
151+
# Start progress-bar iteration.
147152
for iter in tqdm.trange(
148153
iter_total,
149154
desc=self.label,
150155
bar_format='{l_bar}{bar}| {n_fmt}/{total_fmt}]'):
151156
sleep(uniform(min_iter, max_iter))
152157
iter -= 1
153158

154-
print(f'\n{self.msg_complete}\n') # Print completion message.
159+
print(f'{self.msg_complete}\n') # Print completion message.
155160

156-
def __loadseq_B(self, iter_total: int) -> None:
157-
"""Run loading sequence with animated text instead of graphical progress bar.
161+
def __text_seq(self, iter_total: int, iter_speed: float) -> None:
162+
"""Run text-based loading sequence.
158163
159164
---
160165
161166
Example:
162167
163168
```python
164-
>>> bar = PyLoadBar(msg_loading='Loading', msg_complete='Done!', enable_display=False) # Initialize loading sequence.
169+
>>> bar = PyLoadBar(msg_loading='Loading', msg_complete='Done!', enable_bar=False) # Initialize loading sequence.
165170
>>> bar.start(iter_total=1) # Start loading sequence.
166-
>>> # Note that during actual use case, text is printed to same line with an animated dot sequence:
171+
>>> # Note that during actual use case, text is printed to same line followed by an animated '.' character sequence:
167172
168-
> Loading > Loading. > Loading.. > Loading...
173+
# Would look like:
174+
It(1) line 1: \r`bar.msg_loading`
175+
It(2) line 1: \r`bar.msg_loading`.
176+
It(3) line 1: \r`bar.msg_loading`..
177+
It(4) line 1: \r`bar.msg_loading`...
169178
170-
Done!
179+
Repeat(...)
180+
181+
182+
Line 3: `bar.msg_complete`
171183
172184
```
173185
174186
---
175187
176188
:param iter_total: Amount of iterations to run loading sequence
177189
:type iter_total: :class:`int`
178-
:return: loading sequence with animated text instead of progress bar.
190+
:param iter_speed: Seconds per text-sequence iteration
191+
:type iter_speed: :class:`float`
192+
:return: animated text-based progress sequence
179193
:rtype: None
180194
"""
181195

196+
# Start text animation.
182197
for iter in range(iter_total):
183198
print(f'{self.msg_loading}', end='', flush=True)
184-
sleep(0.3)
199+
sleep(iter_speed / 4)
185200

186-
for _ in range(3): # Animate dot sequence.
187-
print('.', end='')
188-
sleep(0.3)
201+
for _ in range(3): # Add 3 dots to `msg_loading` message.
202+
print('.', end='', flush=True)
203+
sleep(iter_speed / 4)
189204

190205
print('\x1b[2K\r', end='', flush=True) # Clear line.
191206

192-
iter -= 1 # Decrement iteration counter.
207+
iter -= 1
193208

194209
print(f'\n{self.msg_complete}\n') # Print completion message.

PyLoadBar/tests/PyLoadBar_test.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
from ..main import PyLoadBar
22

33

4+
def test_seqA():
5+
seq = PyLoadBar()
6+
assert seq.start() is None
47

5-
def test_loadA():
6-
bar = PyLoadBar()
7-
assert bar.start() is None
88

9+
def test_seqB():
10+
seq = PyLoadBar(enable_bar=False)
11+
assert seq.start() is None
912

10-
def test_loadB():
11-
bar = PyLoadBar("Taking sweet time",
12-
"Finally...\n\nTook long enough.", enable_display=False)
13-
assert bar.start(iter_total=3) is None
1413

14+
def test_seqC():
15+
seq = PyLoadBar(msg_loading='TEST',
16+
msg_complete='COMPLETE',
17+
label="LOADING")
18+
assert seq.start(iter_total=25, min_iter=0.001, max_iter=0.25) is None
1519

16-
def test_loadC():
17-
bar = PyLoadBar('Exiting', 'Finished!!')
18-
assert bar.start() is None
1920

21+
def test_seqD():
22+
seq = PyLoadBar(enable_bar=False,
23+
msg_loading='TEST',
24+
msg_complete='COMPLETE')
25+
assert seq.start(iter_total=5, txt_seq_speed=0.25) is None
2026

21-
def test_loadD():
22-
bar = PyLoadBar(
23-
4,
24-
3463463.4)
25-
assert bar.start(min_iter=0.3, max_iter=0.05) is None
27+
28+
def test_seqE():
29+
seq = PyLoadBar(4, 3463463.4, label=123)
30+
assert seq.start(iter_total=5, min_iter=0.001, max_iter=0.25) is None

README.md

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,37 @@
11
# PyLoadBar
22

3-
> _**Minimalist load sequence/progress bar module.**_
3+
> _**Customizeable loading sequence/progress bar generator, enabling users to customize start/finish messages, toggle sequence type, and set total iterations among other features.**_
44
55
---
66

77
## About
88

9-
- Useful for small intermittent pauses between console text returns, or code actions.
9+
- Useful for small intermittent pauses between console text returns, or visualizing the progress of a long-running process.
1010

11-
- Customizable/optional loading and completion messages are available to print to the console (stdout).
11+
- Users can choose between two different loading sequences:
12+
13+
- **A.** Progress-bar style loading sequence
14+
- **B.** Animated-text style loading sequence
15+
16+
- The desired loading sequence **can be toggled** using the `enable_bar: bool` parameter.
17+
18+
- If `enable_bar: bool` is `False`, the progress-bar sequence will not be used, and the animated text-based loading sequence will be used instead.
19+
20+
- The text-based loading sequence displays the loading message followed by incrementing dots, all printed to the same line.
1221

1322
- Messages can be customized by passing custom strings to the `msg_loading: str` and `msg_complete: str` parameters respectively.
1423

15-
- The sequence loading message defaults to `"Loading..."`
16-
- The sequence completion message defaults to `"Done!"`
24+
- The loading message defaults to `"Loading..."`
25+
- The completion message defaults to `"Done!"`
1726

1827
- You may apply a label to the progress bar using the `label: str` parameter (defaults to `None`).
1928

20-
- `enable_display: bool` must be set to `True` for a label to be assigned to the progress bar.
29+
- **NOTE:** `enable_bar: bool` must be set to `True` for a label to be assigned to the progress bar.
2130

2231
- The time taken to complete each iteration can be determined using the `min_iter: float` and `max_iter: float` parameters.
23-
2432
- Each iteration length is randomized to a value between `min_iter: float` and `max_iter: float` seconds.
2533
- e.g. `start(min_iter=0.5, max_iter=1.5)` would take anywhere between 0.5 - 1.5 seconds to complete a single iteration.
2634

27-
- Users can choose between two different loading sequences:
28-
**A.** Progress-bar style loading sequence
29-
**B.** Animated-text style loading sequence
30-
31-
- If `enable_display: bool` is `False, the progress-bar-based sequence will not be used, and the animated text-based loading sequence will be used instead.
32-
33-
- The desired loading sequence **can be toggled** using the `enable_display: bool` parameter.
34-
35-
- The text-based loading sequence displays the loading message followed by incrementing dots, all printed to the same line
36-
3735
---
3836

3937
## Installing PyLoadBar
@@ -91,7 +89,7 @@ gh repo clone schlopp96/PyLoadBar
9189

9290
>>> important_bar = PyLoadBar(msg_loading='Important Stuff Happening', msg_complete='Day Saved!', label='Saving Day') # Initialize a new `PyLoadBar` instance.
9391

94-
>>> important_bar.start(min_iter=0.05, max_iter=1.0, iter_total=10) # Call `start` method to start loading sequence.
92+
>>> important_bar.start(min_iter=0.05, max_iter=1.0, iter_total=10) # Call `start` method to begin loading sequence.
9593

9694
Important Stuff Happening...
9795

@@ -105,7 +103,7 @@ gh repo clone schlopp96/PyLoadBar
105103
```python
106104
>>> from PyLoadBar import PyLoadBar
107105

108-
>>> bar = PyLoadBar(msg_loading='Loading', msg_complete='Done!', enable_display=False) # Initialize loading sequence.
106+
>>> bar = PyLoadBar(msg_loading='Loading', msg_complete='Done!', enable_bar=False) # Initialize loading sequence.
109107

110108
>>> bar.start(iter_total=1) # Start animated-text loading sequence.
111109

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
setup(
99
name='PyLoadBar',
10-
version="0.0.9",
10+
version="0.0.9.1",
1111
description=
12-
'Easy-to-use loading sequence/progress bar generator, enabling users to customize start/finish messages, toggle visual progress meter, set amount of iterations, among other features.',
12+
'Customizeable loading sequence/progress bar generator, enabling users to customize start/finish messages, toggle sequence type, and set total iterations among other features.',
1313
url='https://github.com/schlopp96/PyLoadBar',
1414
author='schlopp96',
1515
author_email='schloppdaddy@gmail.com',

0 commit comments

Comments
 (0)