Skip to content

Commit

Permalink
Merge pull request #7 from soda480/0.2.4
Browse files Browse the repository at this point in the history
0.2.4
  • Loading branch information
soda480 authored Jul 4, 2022
2 parents 31b27d6 + c9d2644 commit c41ea38
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 157 deletions.
80 changes: 35 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
[![build](https://github.com/soda480/progress1bar/actions/workflows/main.yml/badge.svg)](https://github.com/soda480/progress1bar/actions/workflows/main.yml)
[![codecov](https://codecov.io/gh/soda480/progress1bar/branch/main/graph/badge.svg?token=6zIZLnSJ0T)](https://codecov.io/gh/soda480/progress1bar)
[![Code Grade](https://api.codiga.io/project/25921/status/svg)](https://app.codiga.io/public/project/25921/progress1bar/dashboard)
[![complexity](https://img.shields.io/badge/complexity-Simple:%205-brightgreen)](https://radon.readthedocs.io/en/latest/api.html#module-radon.complexity)
[![vulnerabilities](https://img.shields.io/badge/vulnerabilities-None-brightgreen)](https://pypi.org/project/bandit/)
[![PyPI version](https://badge.fury.io/py/progress1bar.svg)](https://badge.fury.io/py/progress1bar)
[![python](https://img.shields.io/badge/python-3.9-teal)](https://www.python.org/downloads/)
Expand All @@ -17,7 +16,7 @@ pip install progress1bar
### `ProgressBar`

```
ProgressBar(total=None, fill=None, regex=None, completed_message=None, clear_alias=False)
ProgressBar(total=None, fill=None, regex=None, completed_message=None, clear_alias=False, show_prefix=True, show_fraction=True, show_percentage=True, ticker=None)
```

<details><summary>Documentation</summary>
Expand All @@ -32,6 +31,14 @@ ProgressBar(total=None, fill=None, regex=None, completed_message=None, clear_ali
> `clear_alias` - A boolean to designate if the progress bar should clear the alias when complete.
> `show_prefix` - A boolean to designate if the prefix of `Processing ` should be printed prefixing the progress bar.
> `show_fraction` - A boolean to designate if the fraction should be printed with the progress bar.
> `show_percentage` - A boolean to designate if the percentage should be printed with the progress bar.
> `ticker` - A integer representing unicode character to print as the progress bar ticker. Refer to [unicode chart](https://www.ssec.wisc.edu/~tomw/java/unicode.html) for values. Default is 9632 (black square ■).
**Attributes**

> `count` - An integer attribute to increment that designates the current count. When count reaches total the progress bar will show complete.
Expand Down Expand Up @@ -60,7 +67,7 @@ The `ProgressBar` class is used to display function execution as a progress bar.
import time
from progress1bar import ProgressBar

with ProgressBar(total=250) as pb:
with ProgressBar(total=250, show_prefix=False, show_fraction=True) as pb:
for _ in range(pb.total):
pb.count += 1
# simulate work
Expand All @@ -78,16 +85,17 @@ Configure `ProgressBar` to display the item that is currently being processd by
<details><summary>Code</summary>

```Python
import time
import names
from progress1bar import ProgressBar

print('Processing names...')
completed_message = 'Done processing all names'
fill = {'max_total': 999}
with ProgressBar(total=500, completed_message=completed_message, fill=fill, clear_alias=True) as pb:
completed_message = 'Processed names'
with ProgressBar(total=75, completed_message=completed_message, clear_alias=True, show_fraction=False, show_prefix=False) as pb:
for _ in range(pb.total):
pb.alias = names.get_full_name()
# simulate work
time.sleep(.08)
pb.count += 1
```

Expand All @@ -97,41 +105,26 @@ with ProgressBar(total=500, completed_message=completed_message, fill=fill, clea

#### [example3](https://github.com/soda480/progress1bar/tree/master/examples/example3.py)

Configure `ProgressBar` to use regular expressions to determine the `total`, `count` and `alias` attributes:
Configure `ProgressBar` with a non-default ticker, and use regular expressions to determine the `total`, `count` and `alias` attributes:

<details><summary>Code</summary>

```Python
import time
import random
import logging
import names
from progress1bar import ProgressBar

logger = logging.getLogger(__name__)

TOTAL_ITEMS = 325

def process_message(pb, message):
pb.match(message)
logger.debug(message)

regex = {
'total': r'^processing total of (?P<value>\d+)$',
'count': r'^processed .*$',
'alias': r'^processor is (?P<value>.*)$'
}
fill = {
'max_total': TOTAL_ITEMS
}
with ProgressBar(regex=regex, fill=fill) as pb:
last_name = names.get_last_name()
process_message(pb, f'processor is {last_name}')
total = random.randint(50, TOTAL_ITEMS)
process_message(pb, f'processing total of {total}')
with ProgressBar(ticker=9473, regex=regex) as pb:
pb.match(f'processor is {names.get_full_name()}')
total = random.randint(500, 1000)
pb.match(f'processing total of {total}')
for _ in range(total):
process_message(pb, f'processed {names.get_full_name()}')
time.sleep(.01)
pb.match(f'processed {names.get_full_name()}')
```

</details>
Expand All @@ -145,33 +138,30 @@ Configure `ProgressBar` to show and reuse progress for several iterations:
<details><summary>Code</summary>

```Python
import time
import random
import time
import names
from progress1bar import ProgressBar

TOTAL_ITEMS = 150
TOTAL_NAMES = 7
TOTAL_ITEMS = 800
ITERATIONS = 4

fill = {
'max_total': TOTAL_ITEMS,
'max_completed': TOTAL_NAMES
}
print(f'This progress bar will execute {TOTAL_NAMES} iterations of varying counts and keep track of how many have been completed ...')
with ProgressBar(fill=fill) as pb:
total_names = 0
print(f'Execute {ITERATIONS} iterations of varying totals:')
with ProgressBar(show_prefix=False, show_fraction=False) as pb:
iterations = 0
while True:
pb.alias = names.get_last_name()
pb.total = random.randint(50, TOTAL_ITEMS)
if iterations == ITERATIONS:
pb.alias = ''
pb.complete = True
break
pb.alias = names.get_full_name()
pb.total = random.randint(500, TOTAL_ITEMS)
for _ in range(pb.total):
names.get_full_name()
pb.count += 1
time.sleep(.01)
total_names += 1
if total_names == TOTAL_NAMES:
pb.alias = ''
break
iterations += 1
pb.reset()
time.sleep(.4)
```

</details>
Expand All @@ -196,7 +186,7 @@ docker container run \
-it \
-v $PWD:/code \
progress1bar:latest \
/bin/bash
bash
```

Execute the build:
Expand Down
4 changes: 2 additions & 2 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
authors = [Author('Emilio Reyes', 'soda480@gmail.com')]
summary = 'A simple ANSI-based progress bar'
url = 'https://github.com/soda480/progress1bar'
version = '0.2.3'
version = '0.2.4'
default_task = [
'clean',
'analyze',
Expand Down Expand Up @@ -62,5 +62,5 @@ def set_properties(project):
project.set_property('radon_break_build_average_complexity_threshold', 4)
project.set_property('radon_break_build_complexity_threshold', 10)
project.set_property('bandit_break_build', True)
project.set_property('anybadge_exclude', 'coverage')
project.set_property('anybadge_exclude', 'coverage, complexity')
project.set_property('anybadge_use_shields', True)
Binary file modified docs/images/example1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/example2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/example3.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/example4.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/example1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import time
from progress1bar import ProgressBar

with ProgressBar(total=250) as pb:
with ProgressBar(total=250, show_prefix=False, show_fraction=True) as pb:
for _ in range(pb.total):
pb.count += 1
# simulate work
Expand Down
7 changes: 4 additions & 3 deletions examples/example2.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# -*- coding: utf-8 -*-
import time
import names
from progress1bar import ProgressBar

print('Processing names...')
completed_message = 'Done processing all names'
fill = {'max_total': 999}
with ProgressBar(total=500, completed_message=completed_message, fill=fill, clear_alias=True) as pb:
completed_message = 'Processed names'
with ProgressBar(total=75, completed_message=completed_message, clear_alias=True, show_fraction=False, show_prefix=False) as pb:
for _ in range(pb.total):
pb.alias = names.get_full_name()
# simulate work
time.sleep(.08)
pb.count += 1
25 changes: 5 additions & 20 deletions examples/example3.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,16 @@
# -*- coding: utf-8 -*-
import time
import random
import logging
import names
from progress1bar import ProgressBar

logger = logging.getLogger(__name__)

TOTAL_ITEMS = 325

def process_message(pb, message):
pb.match(message)
logger.debug(message)

regex = {
'total': r'^processing total of (?P<value>\d+)$',
'count': r'^processed .*$',
'alias': r'^processor is (?P<value>.*)$'
}
fill = {
'max_total': TOTAL_ITEMS
}
with ProgressBar(regex=regex, fill=fill) as pb:
last_name = names.get_last_name()
process_message(pb, f'processor is {last_name}')
total = random.randint(50, TOTAL_ITEMS)
process_message(pb, f'processing total of {total}')
with ProgressBar(ticker=9644, regex=regex) as pb:
pb.match(f'processor is {names.get_full_name()}')
total = random.randint(500, 1000)
pb.match(f'processing total of {total}')
for _ in range(total):
process_message(pb, f'processed {names.get_full_name()}')
time.sleep(.01)
pb.match(f'processed {names.get_full_name()}')
31 changes: 14 additions & 17 deletions examples/example4.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
# -*- coding: utf-8 -*-
import time
import random
import time
import names
from progress1bar import ProgressBar

TOTAL_ITEMS = 150
TOTAL_NAMES = 7
TOTAL_ITEMS = 800
ITERATIONS = 4

fill = {
'max_total': TOTAL_ITEMS,
'max_completed': TOTAL_NAMES
}
print(f'This progress bar will execute {TOTAL_NAMES} iterations of varying counts and keep track of how many have been completed ...')
with ProgressBar(fill=fill) as pb:
total_names = 0
print(f'Execute {ITERATIONS} iterations of varying totals:')
with ProgressBar(show_prefix=False, show_fraction=False) as pb:
iterations = 0
while True:
pb.alias = names.get_last_name()
pb.total = random.randint(50, TOTAL_ITEMS)
if iterations == ITERATIONS:
pb.alias = ''
pb.complete = True
break
pb.alias = names.get_full_name()
pb.total = random.randint(500, TOTAL_ITEMS)
for _ in range(pb.total):
names.get_full_name()
pb.count += 1
time.sleep(.01)
total_names += 1
if total_names == TOTAL_NAMES:
pb.alias = ''
break
iterations += 1
pb.reset()
time.sleep(.4)
Loading

0 comments on commit c41ea38

Please sign in to comment.