Skip to content

Commit 2a67682

Browse files
committed
symlink the whl to a zip file to work around extract limitations in older bazels
1 parent 82d97a8 commit 2a67682

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

python/private/internal_config_repo.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ config = struct(
3232
enable_pystar = True,
3333
enable_pipstar = {enable_pipstar},
3434
enable_deprecation_warnings = {enable_deprecation_warnings},
35+
bazel_8_or_later = {bazel_8_or_later},
3536
bazel_9_or_later = {bazel_9_or_later},
3637
BuiltinPyInfo = getattr(getattr(native, "legacy_globals", None), "PyInfo", {builtin_py_info_symbol}),
3738
BuiltinPyRuntimeInfo = getattr(getattr(native, "legacy_globals", None), "PyRuntimeInfo", {builtin_py_runtime_info_symbol}),
@@ -107,6 +108,7 @@ def _internal_config_repo_impl(rctx):
107108
builtin_py_info_symbol = builtin_py_info_symbol,
108109
builtin_py_runtime_info_symbol = builtin_py_runtime_info_symbol,
109110
builtin_py_cc_link_params_provider = builtin_py_cc_link_params_provider,
111+
bazel_8_or_later = str(bazel_major_version >= 8),
110112
bazel_9_or_later = str(bazel_major_version >= 9),
111113
))
112114

python/private/pypi/patch_whl.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ def patch_whl(rctx, *, python_interpreter, whl_path, patches, **kwargs):
8787
# symlink to a zip file to use bazel's extract so that we can use bazel's
8888
# repository_ctx patch implementation. The whl file may be in a different
8989
# external repository.
90+
#
91+
# TODO @aignas 2025-11-24: remove this symlinking workaround when we drop support for bazel 7
9092
whl_file_zip = whl_input.basename + ".zip"
9193
rctx.symlink(whl_input, whl_file_zip)
9294
rctx.extract(whl_file_zip)

python/private/pypi/whl_library.bzl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,17 @@ def _whl_library_impl(rctx):
377377
#
378378
# Remove non-pipstar and config_load check when we release rules_python 2.
379379
if enable_pipstar:
380+
if rp_config.bazel_8_or_later:
381+
extract_path = whl_path
382+
else:
383+
extract_path = rctx.path(whl_path.basename + ".zip")
384+
rctx.symlink(whl_path, extract_path)
380385
rctx.extract(
381-
archive = whl_path,
386+
archive = extract_path,
382387
output = "site-packages",
383388
)
389+
if not rp_config.bazel_8_or_later:
390+
rctx.delete(extract_path)
384391

385392
metadata = whl_metadata(
386393
install_dir = whl_path.dirname.get_child("site-packages"),

0 commit comments

Comments
 (0)