Skip to content

Commit 04f320b

Browse files
committed
chore: always use starlark-based extraction for wheels
Currently, the Python `installer` library is used for extracting a wheel when Bazel 7 is used. This library only outputs platform-specific extractions, and it was hard-coded to use a unixy style install. This ends up hiding Windows `pythonw`-based scripts and entry points because those are normalized to simply `python` on unix. To fix, use the Starlark-based extraction logic instead. This is a simpler implementation that extracts the wheels mostly as-is, which allows build-phase logic to handle platform-specific differences. This also makes the Starlark based extraction work for Bazel 8.3 and earlier, which previously didn't support it.
1 parent a6e7d34 commit 04f320b

1 file changed

Lines changed: 7 additions & 36 deletions

File tree

python/private/pypi/whl_library.bzl

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
""
1616

17-
load("@rules_python_internal//:rules_python_config.bzl", rp_config = "config")
1817
load("//python/private:auth.bzl", "AUTH_ATTRS", "get_auth")
1918
load("//python/private:envsubst.bzl", "envsubst")
2019
load("//python/private:is_standalone_interpreter.bzl", "is_standalone_interpreter")
@@ -261,22 +260,6 @@ def _create_repository_execution_environment(rctx, python_interpreter, logger =
261260
env[_CPPFLAGS] = " ".join(cppflags)
262261
return env
263262

264-
def _extract_whl_py(rctx, *, python_interpreter, args, whl_path, environment, logger):
265-
pypi_repo_utils.execute_checked(
266-
rctx,
267-
op = "whl_library.ExtractWheel({}, {})".format(rctx.attr.name, whl_path),
268-
python = python_interpreter,
269-
arguments = args + [
270-
"--whl-file",
271-
whl_path,
272-
],
273-
srcs = rctx.attr._python_srcs,
274-
environment = environment,
275-
quiet = rctx.attr.quiet,
276-
timeout = rctx.attr.timeout,
277-
logger = logger,
278-
)
279-
280263
def _get_entry_points(rctx, install_dir_path, metadata):
281264
dist_info_dir = "{}-{}.dist-info".format(
282265
metadata.name.replace("-", "_"),
@@ -376,11 +359,10 @@ def _whl_library_impl(rctx):
376359
# build deps from PyPI (e.g. `flit_core`) if they are missing.
377360
extra_pip_args.extend(["--find-links", "."])
378361

379-
enable_pipstar_extract = rp_config.bazel_8_or_later
380-
381-
# When pipstar is enabled, Python isn't used, so there's no need
382-
# to setup env vars to run Python, unless we need to build an sdist
383-
if enable_pipstar_extract and whl_path and not rctx.attr.whl_patches:
362+
# When we already have a wheel and there are no patches, Python isn't used,
363+
# so there's no need to setup env vars to run Python, unless we need to
364+
# build an sdist or resolve a requirement.
365+
if whl_path and not rctx.attr.whl_patches:
384366
environment = {}
385367
args = []
386368
python_interpreter = None
@@ -446,17 +428,7 @@ def _whl_library_impl(rctx):
446428
timeout = rctx.attr.timeout,
447429
)
448430

449-
if enable_pipstar_extract:
450-
whl_extract(rctx, whl_path = whl_path, logger = logger)
451-
else:
452-
_extract_whl_py(
453-
rctx,
454-
python_interpreter = python_interpreter,
455-
args = args,
456-
whl_path = whl_path,
457-
environment = environment,
458-
logger = logger,
459-
)
431+
whl_extract(rctx, whl_path = whl_path, logger = logger)
460432

461433
install_dir_path = whl_path.dirname.get_child("site-packages")
462434
metadata = whl_metadata(
@@ -513,9 +485,8 @@ repo(
513485
_remove_files(rctx, "BUILD", "BUILD.bazel")
514486
rctx.file("BUILD.bazel", build_file_contents)
515487

516-
if enable_pipstar_extract:
517-
if hasattr(rctx, "repo_metadata"):
518-
return rctx.repo_metadata(reproducible = True)
488+
if hasattr(rctx, "repo_metadata"):
489+
return rctx.repo_metadata(reproducible = True)
519490

520491
return None
521492

0 commit comments

Comments
 (0)