Created
December 7, 2023 07:03
-
-
Save pinheadtf2/7cbef9f9eeeea02bfec893d53b046341 to your computer and use it in GitHub Desktop.
I figured out a nice way to get the loading bar from the pip installer's rich package
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
from pip._vendor.rich.progress import Progress, TextColumn, SpinnerColumn, TimeElapsedColumn, BarColumn, TaskProgressColumn, TimeRemainingColumn | |
async def loading_bar(): | |
some_dataset = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] | |
progress = Progress( | |
SpinnerColumn(), | |
TimeElapsedColumn(), | |
BarColumn(), | |
TaskProgressColumn(), | |
TimeRemainingColumn(), | |
) | |
with progress: | |
print("\nStarted!") | |
# make sure whatever you're iterating over has progress.track() | |
for entry in progress.track(some_dataset): | |
# simulating work being done | |
await asyncio.sleep(0.5) | |
print("Complete!") | |
# DESCRIPTION EXAMPLE: | |
progress_description = Progress( | |
TextColumn("[progress.description]{task.description}"), | |
SpinnerColumn(), | |
TimeElapsedColumn(), | |
BarColumn(), | |
TaskProgressColumn(), | |
TimeRemainingColumn(), | |
) | |
with progress_description: | |
print("\nStarted!") | |
# you can add custom text in the description field | |
for entry in progress_description.track(some_dataset, description="Working hard..."): | |
# simulating work being done | |
await asyncio.sleep(0.5) | |
print("Complete!") | |
asyncio.run(loading_bar()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment