diff --git a/python/private/BUILD.bazel b/python/private/BUILD.bazel index dc0758efa5..1cdd28a847 100644 --- a/python/private/BUILD.bazel +++ b/python/private/BUILD.bazel @@ -907,10 +907,7 @@ bzl_library( bzl_library( name = "util", srcs = ["util.bzl"], - deps = [ - ":py_internal", - "@bazel_skylib//lib:types", - ], + deps = [":py_internal"], ) bzl_library( diff --git a/python/private/internal_config_repo.bzl b/python/private/internal_config_repo.bzl index 8f203bb89e..620be5b4d1 100644 --- a/python/private/internal_config_repo.bzl +++ b/python/private/internal_config_repo.bzl @@ -27,10 +27,8 @@ _ENABLE_DEPRECATION_WARNINGS_DEFAULT = "0" _CONFIG_TEMPLATE = """ config = struct( build_python_zip_default = {build_python_zip_default}, - supports_whl_extraction = {supports_whl_extraction}, enable_pystar = True, enable_deprecation_warnings = {enable_deprecation_warnings}, - extract_needs_chmod = {extract_needs_chmod}, bazel_8_or_later = {bazel_8_or_later}, bazel_9_or_later = {bazel_9_or_later}, bazel_10_or_later = {bazel_10_or_later}, @@ -81,20 +79,11 @@ def _internal_config_repo_impl(rctx): # An empty version signifies a development build, which is treated as # the latest version. if native.bazel_version: - version_parts = native.bazel_version.split(".") - bazel_major_version = int(version_parts[0]) - bazel_minor_version = int(version_parts[1]) + bazel_major_version = int(native.bazel_version.split(".")[0]) else: bazel_major_version = 99999 - bazel_minor_version = 99999 - supports_whl_extraction = False - extract_needs_chmod = bazel_major_version < 8 or (bazel_major_version == 8 and bazel_minor_version < 6) 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" @@ -109,8 +98,6 @@ def _internal_config_repo_impl(rctx): 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), - extract_needs_chmod = str(extract_needs_chmod), builtin_py_cc_link_params_provider = builtin_py_cc_link_params_provider, modules_using_explicit_initpy = str(explicit_init_py_modules), tool_deps_dev_only = str(rctx.attr.tool_deps_dev_only), diff --git a/python/private/pypi/BUILD.bazel b/python/private/pypi/BUILD.bazel index f94d24594f..03a9e113d5 100644 --- a/python/private/pypi/BUILD.bazel +++ b/python/private/pypi/BUILD.bazel @@ -266,7 +266,6 @@ bzl_library( deps = [ ":parse_whl_name", "//python/private:repo_utils", - "@rules_python_internal//:rules_python_config", ], ) @@ -371,7 +370,6 @@ bzl_library( deps = [ "//python/private:repo_utils", "//python/private:util", - "@bazel_skylib//lib:types", ], ) @@ -476,7 +474,6 @@ bzl_library( deps = [ ":whl_metadata", "//python/private:repo_utils", - "@rules_python_internal//:rules_python_config", ], ) diff --git a/python/private/pypi/patch_whl.bzl b/python/private/pypi/patch_whl.bzl index b257f2b4fe..9007a31cf5 100644 --- a/python/private/pypi/patch_whl.bzl +++ b/python/private/pypi/patch_whl.bzl @@ -19,7 +19,6 @@ repack patched wheels. Instead, after extracting and patching, we fix the RECORD file natively in Starlark and repack using system zip. """ -load("@rules_python_internal//:rules_python_config.bzl", rp_config = "config") load("//python/private:repo_utils.bzl", "repo_utils") load(":parse_whl_name.bzl", "parse_whl_name") @@ -93,11 +92,19 @@ def patch_whl(rctx, *, whl_path, patches): """ whl_input = rctx.path(whl_path) + # An empty version is a development build, which is treated as the latest. + bazel_version = (99999, 99999) + if native.bazel_version: + major, minor = native.bazel_version.split(".")[:2] + bazel_version = (int(major), int(minor)) + repo_utils.extract( rctx, archive = whl_input, - supports_whl_extraction = rp_config.supports_whl_extraction, - extract_needs_chmod = rp_config.extract_needs_chmod, + # Extracting `.whl` files requires Bazel 8.3.0 and the extracted files + # need their permissions fixed before Bazel 8.6.0. + supports_whl_extraction = bazel_version >= (8, 3), + extract_needs_chmod = bazel_version < (8, 6), ) if not patches: diff --git a/python/private/pypi/pypi_repo_utils.bzl b/python/private/pypi/pypi_repo_utils.bzl index 8ec7bd1dbe..d8ad340340 100644 --- a/python/private/pypi/pypi_repo_utils.bzl +++ b/python/private/pypi/pypi_repo_utils.bzl @@ -14,7 +14,6 @@ "" -load("@bazel_skylib//lib:types.bzl", "types") load("//python/private:repo_utils.bzl", "repo_utils") load("//python/private:util.bzl", "is_importable_name") @@ -113,7 +112,11 @@ def _execute_prep(mrctx, *, python, srcs, **kwargs): environment = kwargs.pop("environment", {}) pythonpath = environment.get("PYTHONPATH", "") - if pythonpath and not types.is_string(pythonpath): + + # NOTE: `types.is_string` from `@bazel_skylib` is not used, so that this + # file can be loaded before the `WORKSPACE` defines `@bazel_skylib`, e.g. + # via `whl_library` from `python/repositories.bzl`. + if pythonpath and type(pythonpath) != "string": environment["PYTHONPATH"] = _construct_pypath(mrctx, entries = pythonpath) kwargs["environment"] = environment diff --git a/python/private/pypi/whl_extract.bzl b/python/private/pypi/whl_extract.bzl index d7195fd681..dc403e7f32 100644 --- a/python/private/pypi/whl_extract.bzl +++ b/python/private/pypi/whl_extract.bzl @@ -1,6 +1,5 @@ """A simple whl extractor.""" -load("@rules_python_internal//:rules_python_config.bzl", rp_config = "config") load("//python/private:repo_utils.bzl", "repo_utils") load(":whl_metadata.bzl", "find_whl_metadata") @@ -28,12 +27,21 @@ def whl_extract(rctx, *, whl_path, logger): logger: The logger to use """ install_dir_path = rctx.path("site-packages") + + # An empty version is a development build, which is treated as the latest. + bazel_version = (99999, 99999) + if native.bazel_version: + major, minor = native.bazel_version.split(".")[:2] + bazel_version = (int(major), int(minor)) + repo_utils.extract( rctx, archive = whl_path, output = install_dir_path, - supports_whl_extraction = rp_config.supports_whl_extraction, - extract_needs_chmod = rp_config.extract_needs_chmod, + # Extracting `.whl` files requires Bazel 8.3.0 and the extracted files + # need their permissions fixed before Bazel 8.6.0. + supports_whl_extraction = bazel_version >= (8, 3), + extract_needs_chmod = bazel_version < (8, 6), ) metadata_file = find_whl_metadata( diff --git a/python/private/util.bzl b/python/private/util.bzl index 31f317fedf..e96bd569e9 100644 --- a/python/private/util.bzl +++ b/python/private/util.bzl @@ -14,7 +14,6 @@ """Functionality shared by multiple pieces of code.""" -load("@bazel_skylib//lib:types.bzl", "types") load("//python/private:py_internal.bzl", "py_internal") def copy_propagating_kwargs(from_kwargs, into_kwargs = None): @@ -62,7 +61,11 @@ def add_tag(attrs, tag): # Preserve the input type: this allows a test verifying the underlying # rule can accept the tuple for the tags argument. - if types.is_tuple(tags): + # NOTE: `types.is_tuple` from `@bazel_skylib` is not used, so that + # this file can be loaded before the `WORKSPACE` defines + # `@bazel_skylib`, e.g. via `whl_library` from + # `python/repositories.bzl`. + if type(tags) == "tuple": attrs["tags"] = tags + (tag,) else: # List concatenation is necessary because the original value