Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6a04d38

Browse filesBrowse files
authored
fix(whl_library): track sources in whl_library (bazel-contrib#2526)
This is reusing a bit of code used in `evaluate_markers` and makes use of the RECORD files in the `whl` files that we use to extract whls in `whl_library`. This should be merged before bazel-contrib#2514 to avoid any cache invalidation issues downstream. Fixes bazel-contrib#2468
1 parent 611eda8 commit 6a04d38
Copy full SHA for 6a04d38

File tree

Expand file treeCollapse file tree

4 files changed

+27
-4
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+27
-4
lines changed

‎CHANGELOG.md

Copy file name to clipboardExpand all lines: CHANGELOG.md
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ Unreleased changes template.
8989
are now printing more details and include the currently active flag
9090
values. Fixes [#2466](https://github.com/bazelbuild/rules_python/issues/2466).
9191
* (py_proto_library) Fix import paths in Bazel 8.
92+
* (whl_library) Now the changes to the dependencies are correctly tracked when
93+
PyPI packages used in {bzl:obj}`whl_library` during the `repository_rule` phase
94+
change. Fixes [#2468](https://github.com/bazelbuild/rules_python/issues/2468).
9295
+ (gazelle) Gazelle no longer ignores `setup.py` files by default. To restore
9396
this behavior, apply the `# gazelle:python_ignore_files setup.py` directive.
9497

‎python/private/pypi/deps.bzl

Copy file name to clipboardExpand all lines: python/private/pypi/deps.bzl
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ py_library(
124124

125125
# Collate all the repository names so they can be easily consumed
126126
all_repo_names = [name for (name, _, _) in _RULE_DEPS]
127+
record_files = {
128+
name: Label("@{}//:{}.dist-info/RECORD".format(
129+
name,
130+
url.rpartition("/")[-1].partition("-py3-none")[0],
131+
))
132+
for (name, url, _) in _RULE_DEPS
133+
}
127134

128135
def pypi_deps():
129136
"""

‎python/private/pypi/evaluate_markers.bzl

Copy file name to clipboardExpand all lines: python/private/pypi/evaluate_markers.bzl
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414

1515
"""A simple function that evaluates markers using a python interpreter."""
1616

17+
load(":deps.bzl", "record_files")
1718
load(":pypi_repo_utils.bzl", "pypi_repo_utils")
1819

1920
# Used as a default value in a rule to ensure we fetch the dependencies.
2021
SRCS = [
2122
# When the version, or any of the files in `packaging` package changes,
2223
# this file will change as well.
23-
Label("@pypi__packaging//:packaging-24.0.dist-info/RECORD"),
24+
record_files["pypi__packaging"],
2425
Label("//python/private/pypi/requirements_parser:resolve_target_platforms.py"),
2526
Label("//python/private/pypi/whl_installer:platform.py"),
2627
]

‎python/private/pypi/whl_library.bzl

Copy file name to clipboardExpand all lines: python/private/pypi/whl_library.bzl
+15-3Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ load("//python/private:envsubst.bzl", "envsubst")
1919
load("//python/private:is_standalone_interpreter.bzl", "is_standalone_interpreter")
2020
load("//python/private:repo_utils.bzl", "REPO_DEBUG_ENV_VAR", "repo_utils")
2121
load(":attrs.bzl", "ATTRS", "use_isolated")
22-
load(":deps.bzl", "all_repo_names")
22+
load(":deps.bzl", "all_repo_names", "record_files")
2323
load(":generate_whl_library_build_bazel.bzl", "generate_whl_library_build_bazel")
2424
load(":parse_whl_name.bzl", "parse_whl_name")
2525
load(":patch_whl.bzl", "patch_whl")
@@ -242,14 +242,15 @@ def _whl_library_impl(rctx):
242242
else:
243243
op_tmpl = "whl_library.ResolveRequirement({name}, {requirement})"
244244

245-
repo_utils.execute_checked(
245+
pypi_repo_utils.execute_checked(
246246
rctx,
247247
# truncate the requirement value when logging it / reporting
248248
# progress since it may contain several ' --hash=sha256:...
249249
# --hash=sha256:...' substrings that fill up the console
250250
op = op_tmpl.format(name = rctx.attr.name, requirement = rctx.attr.requirement.split(" ", 1)[0]),
251251
arguments = args,
252252
environment = environment,
253+
srcs = rctx.attr._python_srcs,
253254
quiet = rctx.attr.quiet,
254255
timeout = rctx.attr.timeout,
255256
logger = logger,
@@ -291,13 +292,14 @@ def _whl_library_impl(rctx):
291292
)
292293
]
293294

294-
repo_utils.execute_checked(
295+
pypi_repo_utils.execute_checked(
295296
rctx,
296297
op = "whl_library.ExtractWheel({}, {})".format(rctx.attr.name, whl_path),
297298
arguments = args + [
298299
"--whl-file",
299300
whl_path,
300301
] + ["--platform={}".format(p) for p in target_platforms],
302+
srcs = rctx.attr._python_srcs,
301303
environment = environment,
302304
quiet = rctx.attr.quiet,
303305
timeout = rctx.attr.timeout,
@@ -450,6 +452,16 @@ attr makes `extra_pip_args` and `download_only` ignored.""",
450452
for repo in all_repo_names
451453
],
452454
),
455+
"_python_srcs": attr.label_list(
456+
# Used as a default value in a rule to ensure we fetch the dependencies.
457+
default = [
458+
Label("//python/private/pypi/whl_installer:platform.py"),
459+
Label("//python/private/pypi/whl_installer:wheel.py"),
460+
Label("//python/private/pypi/whl_installer:wheel_installer.py"),
461+
Label("//python/private/pypi/whl_installer:arguments.py"),
462+
Label("//python/private/pypi/whl_installer:namespace_pkgs.py"),
463+
] + record_files.values(),
464+
),
453465
"_rule_name": attr.string(default = "whl_library"),
454466
}, **ATTRS)
455467
whl_library_attrs.update(AUTH_ATTRS)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.