Skip to content

Commit fd7a2e9

Browse files
chore(pip): Check for whl extract compatibility in internal_config_repo.bzl (#3456)
Makes the check for whl extraction support slightly more granular, and moves it into internal_config_repo.bzl.
1 parent 7223eb3 commit fd7a2e9

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

python/private/internal_config_repo.bzl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ _ENABLE_DEPRECATION_WARNINGS_DEFAULT = "0"
2929
_CONFIG_TEMPLATE = """
3030
config = struct(
3131
build_python_zip_default = {build_python_zip_default},
32+
supports_whl_extraction = {supports_whl_extraction},
3233
enable_pystar = True,
3334
enable_pipstar = {enable_pipstar},
3435
enable_deprecation_warnings = {enable_deprecation_warnings},
@@ -91,8 +92,20 @@ _TRANSITION_SETTINGS_DEBUG_TEMPLATE = """
9192
def _internal_config_repo_impl(rctx):
9293
# An empty version signifies a development build, which is treated as
9394
# the latest version.
94-
bazel_major_version = int(native.bazel_version.split(".")[0]) if native.bazel_version else 99999
95+
if native.bazel_version:
96+
version_parts = native.bazel_version.split(".")
97+
bazel_major_version = int(version_parts[0])
98+
bazel_minor_version = int(version_parts[1])
99+
else:
100+
bazel_major_version = 99999
101+
bazel_minor_version = 99999
102+
103+
supports_whl_extraction = False
95104
if bazel_major_version >= 8:
105+
# Extracting .whl files requires Bazel 8.3.0 or later.
106+
if bazel_major_version > 8 or bazel_minor_version >= 3:
107+
supports_whl_extraction = True
108+
96109
builtin_py_info_symbol = "None"
97110
builtin_py_runtime_info_symbol = "None"
98111
builtin_py_cc_link_params_provider = "None"
@@ -107,6 +120,7 @@ def _internal_config_repo_impl(rctx):
107120
enable_deprecation_warnings = _bool_from_environ(rctx, _ENABLE_DEPRECATION_WARNINGS_ENVVAR_NAME, _ENABLE_DEPRECATION_WARNINGS_DEFAULT),
108121
builtin_py_info_symbol = builtin_py_info_symbol,
109122
builtin_py_runtime_info_symbol = builtin_py_runtime_info_symbol,
123+
supports_whl_extraction = str(supports_whl_extraction),
110124
builtin_py_cc_link_params_provider = builtin_py_cc_link_params_provider,
111125
bazel_8_or_later = str(bazel_major_version >= 8),
112126
bazel_9_or_later = str(bazel_major_version >= 9),

python/private/pypi/whl_library.bzl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,7 @@ 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-
# Extracting .whl files requires Bazel 8.3.0 or later, so require a
381-
# minimum of Bazel 9.0.0 to ensure compatibilty with earlier versions
382-
# of Bazel 8.
383-
if rp_config.bazel_9_or_later:
380+
if rp_config.supports_whl_extraction:
384381
extract_path = whl_path
385382
else:
386383
extract_path = rctx.path(whl_path.basename + ".zip")
@@ -389,7 +386,7 @@ def _whl_library_impl(rctx):
389386
archive = extract_path,
390387
output = "site-packages",
391388
)
392-
if not rp_config.bazel_9_or_later:
389+
if not rp_config.supports_whl_extraction:
393390
rctx.delete(extract_path)
394391

395392
metadata = whl_metadata(

0 commit comments

Comments
 (0)