Skip to content

Commit 90931ce

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 eda9fe3 commit 90931ce

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 _to_purl(*, index, metadata, filename):
281264
"""
282265
Produce a PyPI PURL from the metadata.
@@ -346,11 +329,10 @@ def _whl_library_impl(rctx):
346329
# build deps from PyPI (e.g. `flit_core`) if they are missing.
347330
extra_pip_args.extend(["--find-links", "."])
348331

349-
enable_pipstar_extract = rp_config.bazel_8_or_later
350-
351-
# When pipstar is enabled, Python isn't used, so there's no need
352-
# to setup env vars to run Python, unless we need to build an sdist
353-
if enable_pipstar_extract and whl_path and not rctx.attr.whl_patches:
332+
# When we already have a wheel and there are no patches, Python isn't used,
333+
# so there's no need to setup env vars to run Python, unless we need to
334+
# build an sdist or resolve a requirement.
335+
if whl_path and not rctx.attr.whl_patches:
354336
environment = {}
355337
args = []
356338
python_interpreter = None
@@ -416,17 +398,7 @@ def _whl_library_impl(rctx):
416398
timeout = rctx.attr.timeout,
417399
)
418400

419-
if enable_pipstar_extract:
420-
whl_extract(rctx, whl_path = whl_path, logger = logger)
421-
else:
422-
_extract_whl_py(
423-
rctx,
424-
python_interpreter = python_interpreter,
425-
args = args,
426-
whl_path = whl_path,
427-
environment = environment,
428-
logger = logger,
429-
)
401+
whl_extract(rctx, whl_path = whl_path, logger = logger)
430402

431403
install_dir_path = whl_path.dirname.get_child("site-packages")
432404
metadata = whl_metadata(
@@ -479,9 +451,8 @@ repo(
479451
_remove_files(rctx, "BUILD", "BUILD.bazel")
480452
rctx.file("BUILD.bazel", build_file_contents)
481453

482-
if enable_pipstar_extract:
483-
if hasattr(rctx, "repo_metadata"):
484-
return rctx.repo_metadata(reproducible = True)
454+
if hasattr(rctx, "repo_metadata"):
455+
return rctx.repo_metadata(reproducible = True)
485456

486457
return None
487458

0 commit comments

Comments
 (0)