-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add API to support tracking progress while reading from a file #1759
Merged
Merged
Changes from 22 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
cf91bd4
Add `Progress.read` and `rich.progress.read` to track progress readin…
althonos 5b2a4a7
Update documentation of `rich.progress.Progress.read`
althonos a5fa231
Update `Progress.read` to close inner file only if given a path
althonos d6f61d8
Add tests to `tests.test_progress` to make sure files are closed prop…
althonos 5cfa203
Add missing type annotations to `rich.progress._Reader`
althonos 1432457
Add an example showing how to copy a file with a progress bar
althonos 46576a9
Ignore type hint in `rich.progress._Reader.readall`
althonos 97da885
Reformat new `progress` code with `black`
althonos 5e8da24
Fix additional typing issues in `rich.progress`
althonos f3f1bca
Reformat `rich.progress` and document `Progress.read` in `progress.rst`
althonos a270e60
Fix `os.PathLike` type annotations in `rich.progress`
althonos 3008780
Remove unused import from `rich.progress`
althonos 1320046
Split `Progress.read` into `Progress.open` and `Progress.wrap_file` m…
althonos fc341f7
Add test to ensure `Progress.wrap_file` can extract the total from a …
althonos 8663073
Make `Progress.open` have a signature compatible with `open`
althonos 2b8ec3b
Add overloaded annotations for `Progress.open` and `rich.progress.open`
althonos 0406578
Update `CHANGELOG.md` to show the `Progress.open` and `Progress.wrap_…
althonos 2e61862
Merge branch 'master' into progress-reader
althonos b736f8a
Merge branch 'master' into progress-reader
willmcgugan 2e77302
Remove unused `update_period` argument from `rich.progress`
althonos aa5ca60
Fix failing tests in `tests.test_progress`
althonos 130f5b4
Reformat code in `rich.progress`
althonos 5ea3032
Force keyword arguments for `Progress.open` options not in builtin `o…
althonos 54d660d
Update example for `wrap_file` in `rich.progress` API documentation
althonos bb9790e
Force keyword arguments for `Progress.wrap_file` arguments after `total`
althonos 76953e2
Remove `_Reader.readall` method since wrapped object may not all have…
althonos 7a870e4
Merge branch 'master' into progress-reader
darrenburns 5717d8d
Add ignore codes for `mypy` in `rich.progress`
althonos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
""" | ||
A very minimal `cp` clone that displays a progress bar. | ||
""" | ||
import os | ||
import shutil | ||
import sys | ||
|
||
from rich.progress import ( | ||
BarColumn, | ||
DownloadColumn, | ||
Progress, | ||
TaskID, | ||
TextColumn, | ||
TimeRemainingColumn, | ||
TransferSpeedColumn, | ||
) | ||
|
||
progress = Progress( | ||
TextColumn("[bold blue]{task.description}", justify="right"), | ||
BarColumn(bar_width=None), | ||
"[progress.percentage]{task.percentage:>3.1f}%", | ||
"•", | ||
DownloadColumn(), | ||
"•", | ||
TransferSpeedColumn(), | ||
"•", | ||
TimeRemainingColumn(), | ||
) | ||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) == 3: | ||
|
||
with progress: | ||
desc = os.path.basename(sys.argv[1]) | ||
with progress.read(sys.argv[1], description=desc) as src: | ||
with open(sys.argv[2], "wb") as dst: | ||
shutil.copyfileobj(src, dst) | ||
else: | ||
print("Usage:\n\tpython cp_progress.py SRC DST") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the
Progress.open
API 😎