Skip to content

enable_pipstar=True breaks extracting wheels when no python interpreter is present #3712

@a-khabarov

Description

@a-khabarov

🐞 bug report

Affected Rule

The issue is caused by the rule:

pip_parse

Is this a regression?

Yes, the bug was not present in 1.7.0. It is present in 1.8.0 and 1.9.0.
89fedb7 is the commit that caused this breakage.

Description

rules_python 1.8.0+ with bootstrap_impl=script and experimental_index_url can attempt to invoke the system python interpreter, causing a failure in any environment that doesn't have a system python installed.

🔬 Minimal Reproduction

.bazelrc

common --@rules_python//python/config_settings:bootstrap_impl=script

.bazelversion

8.4.2

BUILD.bazel
(empty)

MODULE.bazel

module(name = "pre-commit")

bazel_dep(name = "rules_python", version = "1.9.0")
bazel_dep(name = "rules_uv", version = "0.56.0", dev_dependency = True)
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")

python.toolchain(python_version = "3.13")
pip.parse(
    experimental_index_url = "https://pypi.org/simple",
    hub_name = "pre-commit",
    python_version = "3.13",
    requirements_lock = "//pre-commit/requirements:lock.txt",
)

use_repo(pip, pkg = "pre-commit")

pre-commit/BUILD.bazel

alias(
    name = "pkg",
    actual = "@pkg//pre_commit:pkg",
    visibility = ["//visibility:public"],
)

pre-commit/requirements/BUILD.bazel

load("@rules_uv//uv:pip.bzl", "pip_compile")

pip_compile(
    name = "requirements",
    requirements_in = "in.txt",
    requirements_txt = "lock.txt",
    universal = True,
)

pre-commit/requirements/in.txt

pre-commit==4.0.1

Ensure that system python is not installed and that the python3 command is not available.
To reproduce the failure:

bazelisk run pre-commit/requirements
bazelisk build pre-commit:pkg

🔥 Exception or Error

Traceback (most recent call last):
        File ".../external/rules_python+/python/private/pypi/whl_library.bzl", line 302, column 68, in _whl_library_impl
                python_interpreter = pypi_repo_utils.resolve_python_interpreter(
        File ".../external/rules_python+/python/private/pypi/pypi_repo_utils.bzl", line 78, column 54, in _resolve_python_interpreter
                python_interpreter = repo_utils.which_checked(mrctx, python_interpreter)
        File ".../external/rules_python+/python/private/repo_utils.bzl", line 282, column 13, in _which_checked
                fail(result.describe_failure())
Error in fail: Unable to find the binary 'python3' on PATH.

🌍 Your Environment

Operating System:

  
Linux
  

Output of bazel version:

  
Bazelisk version: development
Build label: 8.4.2
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Wed Oct 01 16:46:46 2025 (1759337206)
Build timestamp: 1759337206
Build timestamp as int: 1759337206
  

Rules_python version:

  
1.8.0 and 1.9.0
  

Anything else relevant?

The following patch makes the build pass:

diff --git a/python/private/pypi/hub_builder.bzl b/python/private/pypi/hub_builder.bzl
index f0aa6a73..6c5e28c8 100644
--- a/python/private/pypi/hub_builder.bzl
+++ b/python/private/pypi/hub_builder.bzl
@@ -619,6 +619,8 @@ def _create_whl_repos(
             )
 
 def _common_args(self, module_ctx, *, pip_attr, enable_pipstar):
+    interpreter = _detect_interpreter(self, pip_attr)
+
     # Construct args separately so that the lock file can be smaller and does not include unused
     # attrs.
     whl_library_args = dict(
@@ -633,6 +635,8 @@ def _common_args(self, module_ctx, *, pip_attr, enable_pipstar):
         environment = pip_attr.environment,
         envsubst = pip_attr.envsubst,
         pip_data_exclude = pip_attr.pip_data_exclude,
+        python_interpreter = interpreter.path,
+        python_interpreter_target = interpreter.target,
     )
     if not enable_pipstar:
         maybe_args["experimental_target_platforms"] = pip_attr.experimental_target_platforms

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions