-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Show install progress when using --progress-bar=raw
#12601
Open
joeyballentine
wants to merge
9
commits into
pypa:main
Choose a base branch
from
joeyballentine:install-progress-raw
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
59972c7
Show install progress when using `--progress-bar=raw`
joeyballentine 9b5001e
Add changelog entry
joeyballentine fa26d51
Fix types
joeyballentine 9b8540e
Actually fix type
joeyballentine fb1859f
wrap with iter
joeyballentine 6c95fb4
use Any in raw progress return type
joeyballentine 3b42fa5
rename chunk_size to unit_size
joeyballentine 99de154
use TypeVar
joeyballentine 31d8dad
default to 0 instead of None
joeyballentine 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Output install progress when 'raw' progress_bar type is in use | ||
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 |
---|---|---|
@@ -1,6 +1,15 @@ | ||
import functools | ||
import sys | ||
from typing import Callable, Generator, Iterable, Iterator, Optional, Tuple | ||
from typing import ( | ||
Callable, | ||
Generator, | ||
Iterable, | ||
Iterator, | ||
Optional, | ||
Sized, | ||
Tuple, | ||
TypeVar, | ||
) | ||
|
||
from pip._vendor.rich.progress import ( | ||
BarColumn, | ||
|
@@ -16,9 +25,12 @@ | |
) | ||
|
||
from pip._internal.cli.spinners import RateLimiter | ||
from pip._internal.req.req_install import InstallRequirement | ||
from pip._internal.utils.logging import get_indentation | ||
|
||
DownloadProgressRenderer = Callable[[Iterable[bytes]], Iterator[bytes]] | ||
P = TypeVar("P") | ||
|
||
ProgressRenderer = Callable[[Iterable[P]], Iterator[P]] | ||
|
||
|
||
def _rich_progress_bar( | ||
|
@@ -57,11 +69,15 @@ def _rich_progress_bar( | |
progress.update(task_id, advance=len(chunk)) | ||
|
||
|
||
T = TypeVar("T", bound=Sized) | ||
|
||
|
||
def _raw_progress_bar( | ||
iterable: Iterable[bytes], | ||
iterable: Iterable[T], | ||
*, | ||
size: Optional[int], | ||
) -> Generator[bytes, None, None]: | ||
unit_size: int = 0, | ||
) -> Generator[T, None, None]: | ||
def write_progress(current: int, total: int) -> None: | ||
sys.stdout.write("Progress %d of %d\n" % (current, total)) | ||
sys.stdout.flush() | ||
|
@@ -72,7 +88,7 @@ def write_progress(current: int, total: int) -> None: | |
|
||
write_progress(current, total) | ||
for chunk in iterable: | ||
current += len(chunk) | ||
current += unit_size or len(chunk) | ||
joeyballentine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if rate_limiter.ready() or current == total: | ||
write_progress(current, total) | ||
rate_limiter.reset() | ||
|
@@ -81,14 +97,29 @@ def write_progress(current: int, total: int) -> None: | |
|
||
def get_download_progress_renderer( | ||
*, bar_type: str, size: Optional[int] = None | ||
) -> DownloadProgressRenderer: | ||
) -> ProgressRenderer[bytes]: | ||
"""Get an object that can be used to render the download progress. | ||
|
||
Returns a callable, that takes an iterable to "wrap". | ||
""" | ||
if bar_type == "on": | ||
return functools.partial(_rich_progress_bar, bar_type=bar_type, size=size) | ||
elif bar_type == "raw": | ||
return functools.partial(_raw_progress_bar, size=size) | ||
return functools.partial[Iterator[bytes]](_raw_progress_bar, size=size) | ||
else: | ||
return iter # no-op, when passed an iterator | ||
|
||
|
||
def get_install_progress_renderer( | ||
*, bar_type: str, total: Optional[int] = None | ||
) -> ProgressRenderer[Tuple[str, InstallRequirement]]: | ||
"""Get an object that can be used to render the install progress. | ||
|
||
Returns a callable, that takes an iterable to "wrap". | ||
""" | ||
if bar_type == "raw": | ||
return functools.partial[Iterator[Tuple[str, InstallRequirement]]]( | ||
_raw_progress_bar, size=total, unit_size=1 | ||
) | ||
Comment on lines
+120
to
+123
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried dropping the |
||
else: | ||
return iter # no-op, when passed an iterator |
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
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.