Repository navigation
fix(pypi): fetch retained wheel archives lazily #4316
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
charleysaintNV
wants to merge
3
commits into
bazel-contrib:main
Choose a base branch
from
charleysaintNV:fix/lazy-wheel-archives
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.
+445
−43
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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,4 @@ | ||||||
| Downloaded wheels are removed after extraction when their original archive can | ||||||
|
Collaborator
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.
Suggested change
|
||||||
| be fetched independently. The existing `whl` and `whl_file` targets fetch the | ||||||
| archive from a separate repository on demand. Patched wheels and wheels built | ||||||
| from source retain their existing archive behavior. | ||||||
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
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,69 @@ | ||
| """Download a wheel without retaining it in the extracted repository.""" | ||
|
|
||
| load("//python/private:auth.bzl", "AUTH_ATTRS", "get_auth") | ||
| load("//python/private:repo_utils.bzl", "REPO_DEBUG_ENV_VAR", "repo_utils") | ||
| load(":attrs.bzl", "ATTRS") | ||
| load(":urllib.bzl", "urllib") | ||
|
|
||
| def download_whl(rctx, *, logger): | ||
| """Download a wheel and return its path, preserving index authentication. | ||
|
|
||
| Args: | ||
| rctx: The repository context. | ||
| logger: The repository logger. | ||
|
|
||
| Returns: | ||
| The path of the downloaded wheel. | ||
| """ | ||
| filename = rctx.attr.filename | ||
| if not filename.endswith(".whl"): | ||
| fail("Only wheels are supported") | ||
| urls = [ | ||
| urllib.absolute_url( | ||
| rctx.attr.index_url, | ||
| url, | ||
| envsubst = rctx.attr.envsubst, | ||
| getenv = rctx.getenv, | ||
| ) | ||
| for url in rctx.attr.urls | ||
| ] | ||
| result = rctx.download( | ||
| url = urls, | ||
| output = filename, | ||
| sha256 = rctx.attr.sha256, | ||
| integrity = rctx.attr.integrity if not rctx.attr.sha256 else "", | ||
| auth = get_auth(rctx, urls), | ||
| ) | ||
| if not rctx.attr.sha256 and not rctx.attr.integrity: | ||
| logger.warn("Please update the requirement line to include the hash:\n{} \\\n --hash=sha256:{}".format( | ||
| rctx.attr.requirement, | ||
| result.sha256, | ||
| )) | ||
| if not result.success: | ||
| fail("could not download the '{}' from {}:\n{}".format(filename, urls, result)) | ||
| return rctx.path(filename) | ||
|
|
||
| whl_download_attrs = { | ||
| "envsubst": ATTRS["envsubst"], | ||
| "filename": attr.string(doc = "The filename of the downloaded wheel."), | ||
| "index_url": attr.string(doc = "The index URL used to resolve relative wheel URLs."), | ||
| "integrity": attr.string(doc = "The expected SRI checksum, used when sha256 is unset."), | ||
| "requirement": attr.string(doc = "The requirement used in download diagnostics."), | ||
| "sha256": attr.string(doc = "The expected SHA256 checksum."), | ||
| "urls": attr.string_list(doc = "The wheel download URLs."), | ||
| } | AUTH_ATTRS | ||
|
|
||
| def _whl_download_impl(rctx): | ||
| whl_path = download_whl(rctx, logger = repo_utils.logger(rctx)) | ||
| rctx.file("BUILD.bazel", "exports_files([{}])\n".format(repr(whl_path.basename))) | ||
| if hasattr(rctx, "repo_metadata"): | ||
| return rctx.repo_metadata(reproducible = True) | ||
| return None | ||
|
|
||
| whl_download = repository_rule( | ||
| implementation = _whl_download_impl, | ||
| attrs = whl_download_attrs | { | ||
| "_rule_name": attr.string(default = "whl_download"), | ||
| }, | ||
| environ = [REPO_DEBUG_ENV_VAR], | ||
| ) |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| load("@rules_python//python:py_binary.bzl", "py_binary") | ||
|
|
||
| exports_files([ | ||
| "storage_pkg-1.0-py3-none-any.whl", | ||
| "wheel.sha256", | ||
| "modify_pkg.patch", | ||
| "uv.lock", | ||
| ]) | ||
|
|
||
| [ | ||
| py_binary( | ||
| name = name, | ||
| srcs = ["main.py"], | ||
| legacy_create_init = 0, | ||
| main = "main.py", | ||
| deps = ["@{}//:pkg".format(name)], | ||
| ) | ||
| for name in [ | ||
| "plain", | ||
| "patched", | ||
| "nonmatching", | ||
| "provided", | ||
| "provided_patched", | ||
| ] | ||
| ] | ||
|
|
||
| py_binary( | ||
| name = "uv_locked", | ||
| srcs = ["main.py"], | ||
| legacy_create_init = 0, | ||
| main = "main.py", | ||
| deps = ["@uv_pip//storage_pkg"], | ||
| ) |
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,22 @@ | ||
| module(name = "integration_test") | ||
|
|
||
| bazel_dep(name = "package_metadata", version = "0.0.7") | ||
| bazel_dep(name = "rules_python", version = "0.0.0") | ||
| local_path_override( | ||
| module_name = "rules_python", | ||
| path = "../../..", | ||
| ) | ||
|
|
||
| python = use_extension("@rules_python//python/extensions:python.bzl", "python") | ||
| python.toolchain(python_version = "3.14") | ||
|
|
||
| wheels = use_extension("//:wheels.bzl", "wheels") | ||
| use_repo(wheels, "nonmatching", "patched", "plain", "provided", "provided_patched") | ||
|
|
||
| pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip") | ||
| pip.parse( | ||
| hub_name = "uv_pip", | ||
| python_version = "3.14", | ||
| uv_lock = "//:uv.lock", | ||
| ) | ||
| use_repo(pip, "uv_pip") |
Empty 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import storage_pkg | ||
|
|
||
| print(f"PATCHED={storage_pkg.PATCHED}") |
Oops, something went wrong.
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.
We could combine these 2 together. Having an extra test has a non-zero cost.