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.
diff --git a/python/private/internal_config_repo.bzl b/python/private/internal_config_repo.bzl
index 91f786c..fc1f8d3 100644
--- a/python/private/internal_config_repo.bzl
+++ b/python/private/internal_config_repo.bzl
@@ -29,6 +29,7 @@
_CONFIG_TEMPLATE = """
config = struct(
build_python_zip_default = {build_python_zip_default},
+ supports_whl_extraction = {supports_whl_extraction},
enable_pystar = True,
enable_pipstar = {enable_pipstar},
enable_deprecation_warnings = {enable_deprecation_warnings},
@@ -91,8 +92,20 @@
def _internal_config_repo_impl(rctx):
# An empty version signifies a development build, which is treated as
# the latest version.
- bazel_major_version = int(native.bazel_version.split(".")[0]) if native.bazel_version else 99999
+ if native.bazel_version:
+ version_parts = native.bazel_version.split(".")
+ bazel_major_version = int(version_parts[0])
+ bazel_minor_version = int(version_parts[1])
+ else:
+ bazel_major_version = 99999
+ bazel_minor_version = 99999
+
+ supports_whl_extraction = False
if bazel_major_version >= 8:
+ # Extracting .whl files requires Bazel 8.3.0 or later.
+ if bazel_major_version > 8 or bazel_minor_version >= 3:
+ supports_whl_extraction = True
+
builtin_py_info_symbol = "None"
builtin_py_runtime_info_symbol = "None"
builtin_py_cc_link_params_provider = "None"
@@ -107,6 +120,7 @@
enable_deprecation_warnings = _bool_from_environ(rctx, _ENABLE_DEPRECATION_WARNINGS_ENVVAR_NAME, _ENABLE_DEPRECATION_WARNINGS_DEFAULT),
builtin_py_info_symbol = builtin_py_info_symbol,
builtin_py_runtime_info_symbol = builtin_py_runtime_info_symbol,
+ supports_whl_extraction = str(supports_whl_extraction),
builtin_py_cc_link_params_provider = builtin_py_cc_link_params_provider,
bazel_8_or_later = str(bazel_major_version >= 8),
bazel_9_or_later = str(bazel_major_version >= 9),
diff --git a/python/private/pypi/whl_library.bzl b/python/private/pypi/whl_library.bzl
index d8f32ff..044d18a 100644
--- a/python/private/pypi/whl_library.bzl
+++ b/python/private/pypi/whl_library.bzl
@@ -377,10 +377,7 @@
#
# Remove non-pipstar and config_load check when we release rules_python 2.
if enable_pipstar:
- # Extracting .whl files requires Bazel 8.3.0 or later, so require a
- # minimum of Bazel 9.0.0 to ensure compatibilty with earlier versions
- # of Bazel 8.
- if rp_config.bazel_9_or_later:
+ if rp_config.supports_whl_extraction:
extract_path = whl_path
else:
extract_path = rctx.path(whl_path.basename + ".zip")
@@ -389,7 +386,7 @@
archive = extract_path,
output = "site-packages",
)
- if not rp_config.bazel_9_or_later:
+ if not rp_config.supports_whl_extraction:
rctx.delete(extract_path)
metadata = whl_metadata(