bazelbuild / rules_python

Bazel Python Rules
https://rules-python.readthedocs.io
Apache License 2.0
530 stars 540 forks source link

`whl_filegroup` fails when no python3 installed on host #2087

Open froody opened 3 months ago

froody commented 3 months ago

🐞 bug report

Affected Rule

The issue is caused by the rule: whl_filegroup

Is this a regression?

No

Description

The whl_filegroup rule runs a python script, but this script depends on /usr/bin/env python3 which in my case isn't present, even though I've set a default python toolchain.

πŸ”¬ Minimal Reproduction

## MODULE.bazel
bazel_dep(name = "rules_python", version = "0.34.0")
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(python_version="3.10", is_default=True, ignore_root_user_error = True)
use_repo(python, "python_3_10")
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
    hub_name = "pip_deps",
    python_version = "3.10",
    requirements_lock = "//:requirements.txt",
)
use_repo(pip, "pip_deps")

## BUILD
load("@rules_python//python:pip.bzl", "whl_filegroup")
whl_filegroup(
    name = "numpy_includes",
    pattern = "numpy/core/include/numpy",
    whl = "@pip_deps//numpy:whl",
)

πŸ”₯ Exception or Error





15.35 ERROR: /opt/builder/BUILD:57:14: Extracting numpy/core/include/numpy files from ../rules_python~~pip~pip_deps_310_numpy/numpy-1.26.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl failed: (Exit 127): extract_wheel_files failed: error executing PyExtractWheelFiles command (from target //:numpy_includes) bazel-out/k8-opt-exec-ST-d57f47055a04/bin/external/rules_python~/python/private/whl_filegroup/extract_wheel_files ... (remaining 3 arguments skipped)
15.35 /usr/bin/env: 'python3': No such file or directory

🌍 Your Environment

Operating System:

  
Ubuntu 22.04
  

Output of bazel version:

  
7.2.0
  

Rules_python version:

  
0.34.0
  

Anything else relevant?

aignas commented 3 months ago

Just a quick note, but I think the recently added exec toolchain should help here. This was added for precompiling stuff, but it should be also applicable here.

rickeylev commented 3 months ago

The exec toolchain shouldn't come into play. The relationship is whl_filegroup has cfg=exec dependency on py_binary //python/private/whl_filegroup:extract_wheel_files.

That py_binary, through toolchain resolution, should end up matching the 3.10 toolchain mentioned in the MODULE.bazel. If it's trying to use /usr/bin/env python3, then it's probably ending up in the autodetecting toolchain somehow.