-
Notifications
You must be signed in to change notification settings - Fork 3.1k
add size to pylock.toml #13395
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
Open
stonebig
wants to merge
10
commits into
pypa:main
Choose a base branch
from
stonebig:size
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
add size to pylock.toml #13395
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
63f7d26
add size to pylock.toml
stonebig 705d315
add news entry
stonebig 214aed7
fix bug on test_link
stonebig 0f4de30
fix tests with size
stonebig f89dbbd
make my size
stonebig 85a7415
backpedal on archives
stonebig e263c15
again
stonebig 89538df
again
stonebig eee2171
last try
stonebig 184011e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add size attribute to pylock.toml |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -508,6 +508,23 @@ def hash_name(self) -> str | None: | |
def show_url(self) -> str: | ||
return posixpath.basename(self._url.split("#", 1)[0].split("?", 1)[0]) | ||
|
||
@property | ||
def size(self) -> int | None: | ||
"""Fetch the size of the file from HTTP headers if available.""" | ||
from pip._internal.network.session import PipSession | ||
|
||
try: | ||
session = PipSession() | ||
response = session.head(self.url, allow_redirects=True) | ||
response.raise_for_status() | ||
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. This probably should be handled. Does ValueError cover this? It is not obvious. |
||
# Check if the 'Content-Length' header is present | ||
size = response.headers.get("Content-Length") | ||
if size: | ||
return int(size) | ||
except ValueError as e: | ||
logger.warning("Could not fetch size for %s: %s", self.url, e) | ||
return None | ||
|
||
@property | ||
def is_file(self) -> bool: | ||
return self.scheme == "file" | ||
|
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
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
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
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'm not convinced we should do additional network access to get the sizes.
I would rather envision an approach where we add a size attribute to InstallRequirement.download_info (as in a subclass of DirectUrl, or another class that would be more specialized to record the provenance URL, PEP710-style), and populate it at the same time as we currently populate download_info. This also means storing the original size in the cache (
origin.json
) next to the hashes.It's more complex but like more efficient and robust.
That's just an intuition though, as I have not investigated deeply.
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.
it's a patch over an "experimental" feature. you need the "complex" and "efficient" version at this point ?
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.
My understanding is the term experimental means here is that pip may change the CLI or semantics of the feature between releases. Not that the solution isn't expected to be robust.
I have the same concern here, particularly for the use case of locking a large existing environment, doing hundreds of extra network requests may cause the lock to be significantly slower or fail.
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.
Another reason is that it would make sense for file sizes to follow the same flow as hashes, as they are closely related. I believe the could be obtained and verified at the same places in the codebase. It will likely make things easier to follow and understand.
Uh oh!
There was an error while loading. Please reload this page.
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.
OK, I agree, but that is a bigger change, will need time. Competitive PR is welcomed