bazel-contrib / bazel-contrib/rules_python

`py_binary` does not have runfiles created if called transitively through `sh_binary`

Đang mở
#2,664 6 bình luận 0 reaction 0 người được giao Xem trên GitHub
type: bug
Ngôn ngữ chính
Starlark
Star
688
Fork
721
Merge trung bình
15 giờ 7 phút
Pull request đã merge (30 ngày)
76

Mô tả

# 🐞 bug report

### Affected Rule

This issue discusses the behavior of a `py_binary` target.

### Is this a regression?

Haven't done a thorough search of past versions yet, but this _does work correctly_ in bazel `6.4.0` and we are now seeing issues in bazel `7.5.0`. During the switch, both systems were running `rules_python` version `0.37.0`.

### Description

When a `py_binary` is invoked, the backend will create the necessary `.runfiles` directory that includes the relevant dependencies for running the target. There are cases in our system where it useful to wrap the calling of this `py_binary` behind a `sh_binary` as a data dependency. One such example is to make use of console scripts like `flake8` in the repository as if they were installed in a virtual environment. If one uses the `py_console_script_binary` target directly, all supplied paths to lint must be absolute since the current working directory is modified by bazel when running the target. By changing the working directory, we can get the benefit of having hermetic tooling as a drop-in replacement for something normally provided in a virtual environment.

## 🔬 Minimal Reproduction

Attached a zip of a repro. Instructions to reproduce the behavior are in the README.

## 🔥 Exception or Error



Traceback (most recent call last):
File "/home/nathanael/.cache/bazel/_bazel_nathanael/e616dc8a3f01de94997c692cfb80f031/execroot/_main/bazel-out/k8-fastbuild/bin/src/hello_world", line 580, in
Main()
File "/home/nathanael/.cache/bazel/_bazel_nathanael/e616dc8a3f01de94997c692cfb80f031/execroot/_main/bazel-out/k8-fastbuild/bin/src/hello_world", line 471, in Main
module_space = FindModuleSpace(main_rel_path)
File "/home/nathanael/.cache/bazel/_bazel_nathanael/e616dc8a3f01de94997c692cfb80f031/execroot/_main/bazel-out/k8-fastbuild/bin/src/hello_world", line 181, in FindModuleSpace
raise AssertionError('Cannot find .runfiles directory for %s' % sys.argv[0])
AssertionError: Cannot find .runfiles directory for /home/nathanael/.cache/bazel/_bazel_nathanael/e616dc8a3f01de94997c692cfb80f031/execroot/_main/bazel-out/k8-fastbuild/bin/src/hello_world

## 🌍 Your Environment

**Operating System:**

  

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.5 LTS
Release: 22.04
Codename: jammy
(mono) ~/devel/rules_pyt

**Output of `bazel version`:**

  

bazel 7.5.0

**Rules_python version:**
0.37.0

[rules_python_runfiles_repro-main.zip](https://github.com/user-attachments/files/19251090/rules_python_runfiles_repro-main.zip)

  


**Anything else relevant?**

Thanks for making `rules_python` 😃 We're doing a lot of cool things with it!

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu với README trong archive rules_python_runfiles_repro đính kèm và chạy bản tái hiện bằng Bazel 7.5.0. So sánh một py_binary được gọi trực tiếp với một py_binary được tiếp cận bắc cầu thông qua sh_binary hoặc py_console_script_binary, sau đó xác minh rằng thư mục target.runfiles dự kiến được tạo và AssertionError được tái hiện không còn xảy ra.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
build-system
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
38/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.