Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions python/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
15 changes: 1 addition & 14 deletions python/private/internal_config_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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"
Expand All @@ -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),
Expand Down
3 changes: 0 additions & 3 deletions python/private/pypi/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ bzl_library(
deps = [
":parse_whl_name",
"//python/private:repo_utils",
"@rules_python_internal//:rules_python_config",
],
)

Expand Down Expand Up @@ -371,7 +370,6 @@ bzl_library(
deps = [
"//python/private:repo_utils",
"//python/private:util",
"@bazel_skylib//lib:types",
],
)

Expand Down Expand Up @@ -476,7 +474,6 @@ bzl_library(
deps = [
":whl_metadata",
"//python/private:repo_utils",
"@rules_python_internal//:rules_python_config",
],
)

Expand Down
13 changes: 10 additions & 3 deletions python/private/pypi/patch_whl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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:
Expand Down
7 changes: 5 additions & 2 deletions python/private/pypi/pypi_repo_utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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

Expand Down
14 changes: 11 additions & 3 deletions python/private/pypi/whl_extract.bzl
Original file line number Diff line number Diff line change
@@ -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")

Expand Down Expand Up @@ -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(
Expand Down
7 changes: 5 additions & 2 deletions python/private/util.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
Loading