Skip to content

Commit 6047aa5

Browse files
committed
v0.2.0 update initial commit
--- - Changed param `txt_seq_speed` to `txt_iter_speed`. - Improvements to docstrings. - Fixed "shutter" effect when using text-sequence. - No longer clears entire line each iteration. - Improved tests. - Removed project contribution PyPI install option. - Improved reqs compatibility. - Improvements to "./README.md". - Added "./assets" directory to contain extra "./README.md" files. - Added gifs to "./README.md". Signed-off-by: schlopp96 <71921821+schlopp96@users.noreply.github.com>
1 parent 98020bb commit 6047aa5

7 files changed

Lines changed: 66 additions & 82 deletions

File tree

PyLoadBar/main.py

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,29 @@
1010
sys.path.insert(0, dirname(
1111
dirname(__file__))) # Ensure module can be found by Python.
1212

13-
__version__ = '0.1.1'
13+
__version__ = '0.2.0'
1414

1515

1616
class PyLoadBar:
17-
"""Generate loading sequences with ability to customize start/finish messages, toggle visual progress meter, and set time to completion.
17+
"""Create loading sequences with ability to customize start/finish messages, toggle between bar/text progress sequences, and set length of progress sequences.
1818
1919
---
2020
2121
Settings:
2222
2323
- When instantiating a new :class:`PyLoadBar` object, you can set the sequence type using :param:`bar_sequence`.
2424
25-
- When calling :func:`start(self, msg_loading, msg_complete, label, iter_total, min_iter, max_iter, txt_seq_speed)`:
25+
- When calling :func:`self.start(self, msg_loading, msg_complete, label, iter_total, min_iter, max_iter, txt_iter_speed)`:
2626
- Set custom start/completion messages by passing string to :param:`msg_loading` and :param:`msg_complete` respectively.
27-
- Optionally set the total number of iterations to run using :param:`iter_total`, defaults to 5.
27+
- Optionally set the total number of iterations to run using :param:`iter_total`, defaults to `5`.
2828
2929
- If using bar-sequence:
3030
- Set the minimum/maximum iteration length in seconds using the :param:`min_iter` and :param:`max_iter` parameters respectively.
3131
- Time taken by each individual iteration is randomized within range of :param:`min_iter` and :param:`max_iter`.
3232
- Apply label to progress meter by passing string to :param:`label` (set to `None` by default).
3333
3434
- If using text-sequence:
35-
- Set number of seconds to complete a single text-sequence iteration using :param:`txt_seq_speed`.
35+
- Set number of seconds to complete a single text-sequence iteration using :param:`txt_iter_speed`.
3636
- Defaults to `0.5` seconds per iteration/animation cycle.
3737
"""
3838

@@ -44,7 +44,7 @@ def __init__(self, bar_sequence: bool = True) -> None:
4444
:param bar_sequence: toggle progress-bar loading sequence, defaults to `True`
4545
:type bar_sequence: :class:`bool`, optional
4646
:return: :class:`PyLoadBar` object
47-
:rtype: None
47+
:rtype: `None`
4848
"""
4949

5050
self.bar_sequence: bool = bar_sequence
@@ -57,7 +57,7 @@ def start(
5757
iter_total: int = 5,
5858
min_iter: float = 0.01,
5959
max_iter: float = 0.5,
60-
txt_seq_speed: float = 0.5,
60+
txt_iter_speed: float = 0.5,
6161
) -> None:
6262
"""Start loading sequence.
6363
@@ -69,36 +69,36 @@ def start(
6969
- Note that :param:`bar_sequence` must be set to `True` for this to take effect.
7070
7171
- Set the total number of iterations to complete using the :param:`iter_total`.
72-
- Defaults to 5 iterations.
72+
- Defaults to `5` iterations.
7373
7474
- If using bar-sequence:
7575
- Set the minimum/maximum iteration length in seconds using the :param:`min_iter` and :param:`max_iter` parameters respectively.
7676
- Time taken by each individual iteration is randomized within range of :param:`min_iter` and :param:`max_iter`.
77-
- :param:`min_iter` defaults to 0.01 seconds, :param:`max_iter` defaults to 0.5 seconds.
77+
- :param:`min_iter` defaults to `0.01` seconds, :param:`max_iter` defaults to `0.5` seconds.
7878
- Apply label to progress meter by passing string to :param:`label` (set to `None` by default).
7979
8080
- If using text-sequence:
81-
- Set number of seconds to complete a single text-sequence iteration using :param:`txt_seq_speed`.
81+
- Set number of seconds to complete a single text-sequence iteration using :param:`txt_iter_speed`.
8282
- Defaults to `0.5` seconds per iteration/animation cycle.
8383
8484
---
8585
8686
:param msg_loading: initial loading message, defaults to 'Loading'
87-
:type msg_loading: :class:`str` | None, optional
87+
:type msg_loading: :class:`str` | `None`, optional
8888
:param msg_complete: final message displayed upon completion, defaults to 'Done!'
89-
:type msg_complete: :class:`str` | None, optional
90-
:param label: label displayed alongside progress bar, defaults to None
91-
:type label: :class:`str` | None, optional
92-
:param iter_total: total amount of iterations to run, defaults to 5
89+
:type msg_complete: :class:`str` | `None`, optional
90+
:param label: label displayed alongside progress bar, defaults to `None`
91+
:type label: :class:`str` | `None`, optional
92+
:param iter_total: total amount of iterations to run, defaults to `5`
9393
:type iter_total: :class:`int`, optional
94-
:param min_iter: minimum possible time to complete an iteration, defaults to 0.01 seconds
94+
:param min_iter: minimum possible time to complete an iteration, defaults to `0.01` seconds
9595
:type min_iter: :class:`float`, optional
96-
:param max_iter: maximum possible time to complete an iteration, defaults to 0.5 seconds
96+
:param max_iter: maximum possible time to complete an iteration, defaults to `0.5` seconds
9797
:type max_iter: :class:`float`, optional
98-
:param txt_seq_speed: number of seconds to complete a single text-sequence iteration, defaults to 0.5 seconds
99-
:type txt_seq_speed: :class:`float`, optional
98+
:param txt_iter_speed: number of seconds to complete a single text-sequence iteration (only usable if :param:`self.bar_sequence` == :bool:`False`), defaults to `0.5` seconds
99+
:type txt_iter_speed: :class:`float`, optional
100100
:return: loading sequence
101-
:rtype: None
101+
:rtype: `None`
102102
"""
103103

104104
if self.bar_sequence and msg_loading == 'Loading':
@@ -111,7 +111,7 @@ def start(
111111

112112
else:
113113
self.__text_seq(msg_loading, msg_complete, iter_total,
114-
txt_seq_speed)
114+
txt_iter_speed)
115115

116116
sleep(
117117
0.5
@@ -137,7 +137,7 @@ def __bar_seq(msg_loading: str | None, msg_complete: str | None,
137137
138138
Loading...
139139
140-
Progress: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████▊| 5/5]
140+
Progress: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████▊| [5/5]
141141
142142
Done!
143143
@@ -146,19 +146,19 @@ def __bar_seq(msg_loading: str | None, msg_complete: str | None,
146146
---
147147
148148
:param msg_loading: initial loading message
149-
:type msg_loading: :class:`str` | None
149+
:type msg_loading: :class:`str` | `None`
150150
:param msg_complete: final message displayed upon completion
151-
:type msg_complete: :class:`str` | None
151+
:type msg_complete: :class:`str` | `None`
152152
:param label: label displayed alongside progress bar
153-
:type label: :class:`str` | None
153+
:type label: :class:`str` | `None`
154154
:param iter_total: total amount of iterations to run
155155
:type iter_total: :class:`int`
156156
:param min_iter: minimum possible time (in seconds) an iteration can take
157157
:type min_iter: :class:`float`
158158
:param max_iter: maximum possible time (in seconds) an iteration can take
159159
:type max_iter: :class:`float`
160160
:return: Loading sequence with graphical progress bar.
161-
:rtype: None
161+
:rtype: `None`
162162
"""
163163

164164
print(f'{msg_loading}\n')
@@ -167,15 +167,15 @@ def __bar_seq(msg_loading: str | None, msg_complete: str | None,
167167
for iter in tqdm.trange(
168168
iter_total,
169169
desc=label,
170-
bar_format='{l_bar}{bar}| {n_fmt}/{total_fmt}]'):
170+
bar_format='{l_bar}{bar}| [{n_fmt}/{total_fmt}]'):
171171
sleep(uniform(min_iter, max_iter))
172172
iter -= 1
173173

174174
print(f'\n{msg_complete}\n') # Print completion message.
175175

176176
@staticmethod
177177
def __text_seq(msg_loading: str | None, msg_complete: str | None,
178-
iter_total: int, iter_speed: float) -> None:
178+
iter_total: int, txt_iter_speed: float) -> None:
179179
"""Run text-based loading sequence.
180180
181181
---
@@ -184,14 +184,14 @@ def __text_seq(msg_loading: str | None, msg_complete: str | None,
184184
185185
```python
186186
>>> bar = PyLoadBar(bar_sequence=False) # Initialize loading sequence.
187-
>>> bar.start(msg_loading='Loading', msg_complete='Done!', iter_total=1, txt_seq_speed=1) # Start loading sequence.
187+
>>> bar.start(msg_loading='Loading', msg_complete='Done!', iter_total=1, txt_iter_speed=1) # Start loading sequence.
188188
>>> # Note that during actual use case, text is printed to same line followed by an animated '.' character sequence:
189189
190190
# Would look like:
191-
It(1) line 1: \r"Loading"
192-
It(2) line 1: \r"Loading."
193-
It(3) line 1: \r"Loading.."
194-
It(4) line 1: \r"Loading..."
191+
It(1) line 1: "Loading"
192+
It(2) line 1: "Loading."
193+
It(3) line 1: "Loading.."
194+
It(4) line 1: "Loading..."
195195
196196
Repeat(...)
197197
@@ -203,26 +203,28 @@ def __text_seq(msg_loading: str | None, msg_complete: str | None,
203203
---
204204
205205
:param msg_loading: initial loading message
206-
:type msg_loading: :class:`str` | None
206+
:type msg_loading: :class:`str` | `None`
207207
:param iter_total: number of iterations to run during loading sequence
208208
:type iter_total: :class:`int`
209-
:param iter_speed: number of seconds to complete a single text-sequence iteration
210-
:type iter_speed: :class:`float`
209+
:param txt_iter_speed: number of seconds to complete a single text-sequence iteration
210+
:type txt_iter_speed: :class:`float`
211211
:return: animated text-based progress sequence
212-
:rtype: None
212+
:rtype: `None`
213213
"""
214214

215215
# Start text animation.
216216
for iter in range(iter_total):
217217
print(f'{msg_loading}', end='', flush=True)
218-
sleep(iter_speed / 4)
218+
sleep(txt_iter_speed / 4)
219219

220-
for _ in range(3): # Add 3 dots to `msg_loading` message.
220+
for _ in range(3): # Add ellipsis to `msg_loading` message
221221
print('.', end='', flush=True)
222-
sleep(iter_speed / 4)
222+
sleep(txt_iter_speed / 4)
223223

224-
print('\x1b[2K\r', end='', flush=True) # Clear line.
224+
print('\b\b\b\033[K\r', end='',
225+
flush=True) # Erase ellipsis from previous iteration.
225226

226227
iter -= 1
227228

228-
print(f'\n{msg_complete}\n') # Print completion message.
229+
print(f'\x1b[2K\r{msg_complete}\n'
230+
) # Clear line and print completion message.

PyLoadBar/tests/PyLoadBar_test.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
1-
from ..main import PyLoadBar
1+
from PyLoadBar.main import PyLoadBar
22

33

4-
def test_seqA():
4+
def test_default_bar():
55
seq = PyLoadBar()
66
assert seq.start() is None
77

88

9-
def test_seqB():
9+
def test_default_text():
1010
seq = PyLoadBar(bar_sequence=False)
1111
assert seq.start() is None
1212

1313

14-
def test_seqC():
14+
def test_bar_params():
1515
seq = PyLoadBar()
16-
assert seq.start(msg_loading='TEST',
17-
msg_complete='COMPLETE',
18-
label="LOADING", iter_total=25, min_iter=0.001, max_iter=0.25) is None
16+
assert seq.start(msg_loading='STARTED TEST',
17+
msg_complete='COMPLETE',
18+
label="TESTING",
19+
iter_total=25,
20+
min_iter=0.001,
21+
max_iter=0.25) is None
1922

2023

21-
def test_seqD():
22-
seq = PyLoadBar(bar_sequence=False,
23-
)
24+
def test_text_params():
25+
seq = PyLoadBar(bar_sequence=False, )
2426
assert seq.start(msg_loading='TEST',
2527
msg_complete='COMPLETE',
2628
iter_total=5,
27-
txt_seq_speed=0.25) is None
29+
iter_speed=0.25) is None
2830

2931

30-
def test_seqE():
32+
def test_numbers_in_message_params():
3133
seq = PyLoadBar()
3234
assert seq.start(
3335
4, 3463463.4, label=123, iter_total=5, min_iter=0.001,

README.md

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# PyLoadBar
22

3-
> _**Customizeable loading sequence/progress bar generator, enabling users to customize start/finish messages, toggle sequence type, and set total iterations among other features.**_
3+
> _**Loading sequence/progress bar generator with options for users to customize start/finish messages, toggle between bar/text sequences, and set total iterations among other features.**_
44
55
---
66

@@ -34,7 +34,7 @@
3434
- 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.
3535

3636
- The _text-based_ loading sequence displays the loading message followed by incrementing dots, all printed to the same line.
37-
- Set number of seconds to complete a single text-sequence iteration using `txt_seq_speed: float`.
37+
- Set number of seconds to complete a single text-sequence iteration using `txt_iter_speed: float`.
3838
- Defaults to `0.5` seconds per animation cycle.
3939

4040
---
@@ -96,13 +96,10 @@ gh repo clone schlopp96/PyLoadBar
9696

9797
>>> important_bar.start(msg_loading='Important Stuff Happening', msg_complete='Day Saved!', label='Saving Day', min_iter=0.05, max_iter=1.0, iter_total=10) # Call `start` method to begin loading sequence.
9898

99-
Important Stuff Happening...
100-
101-
Saving Day: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 10/10
102-
103-
Day Saved!
10499
```
105100

101+
![alt](./assets/bar_sequence.gif)
102+
106103
- Example of animated-text-based loading sequence:
107104

108105
```python
@@ -112,25 +109,9 @@ gh repo clone schlopp96/PyLoadBar
112109

113110
>>> bar.start(msg_loading='Loading', msg_complete='Done!', iter_total=1, txt_iter_speed=1) # Start animated-text loading sequence.
114111

115-
# Note that during actual use case, text is printed to same line followed by incrementing dots:
116-
117-
Loading
118-
Loading.
119-
Loading..
120-
Loading...
121-
122-
Done!
123112
```
124113

125-
---
126-
127-
## Contributing to PyLoadBar
128-
129-
- If you wish to help contribute to this project, please run the following in your virtual env to acquire the necessary dependencies and tools you need to develop and run tests:
130-
131-
```shell
132-
pip install PyLoadBar[dev]
133-
```
114+
![alt](./assets/text_sequence.gif)
134115

135116
---
136117

assets/bar_sequence.gif

86.2 KB
Loading

assets/text_sequence.gif

150 KB
Loading

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
setuptools>=62.1.0
1+
setuptools>=58.1.0
22
tqdm>=4.64.0

setup.py

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

88
setup(
99
name='PyLoadBar',
10-
version="0.1.1",
10+
version="0.2.0",
1111
description=
1212
'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',
@@ -19,7 +19,6 @@
1919
packages=find_packages(),
2020
include_package_data=True,
2121
install_requires=[reqs],
22-
extras_require={"dev": ["pytest>=6.2.5"]},
2322
classifiers=[
2423
"Development Status :: 3 - Alpha", "Intended Audience :: Developers",
2524
"Intended Audience :: End Users/Desktop",
@@ -31,5 +30,5 @@
3130
"Programming Language :: Python :: 3.10", "Topic :: Utilities"
3231
],
3332
keywords=[
34-
'python, load, bar, loading, sequence, progress, simple, easy, utilities, package, module, tqdm, pytest, pyloadbar, developer, tool, tqdm'
33+
'python, load, bar, loading, sequence, progress, progress-bar, simple, easy, utilities, package, module, tqdm, pyloadbar, developer, tool'
3534
])

0 commit comments

Comments
 (0)