bazel-contrib / bazel-contrib/rules_python

`local_runtime_repo` fails on macOS/Xcode Python with watch_tree() error against missing directory

Đang mở
#3,043 7 bình luận 0 reaction 0 người được giao Xem trên GitHub
type: bug type: toolchain
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

`local_runtime_repo`

### Is this a regression?

No

### Description

The metadata for `/usr/bin/python3` on macOS will return a path that does not exist (by default):

```
DEBUG: local_runtime_repo.bzl:101:10: {"major": 3, "minor": 9, "micro": 6, "include": "/Library/Python/3.9/include", "implementation_name": "cpython", "base_executable": "/Applications/Xcode-16.4.0.app/Contents/Developer/usr/bin/python3", "LDLIBRARY": "Python3.framework/Versions/3.9/Python3", "LIBDIR": "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib", "INSTSONAME": "Python3.framework/Versions/3.9/Python3", "PY3LIBRARY": "", "SHLIB_SUFFIX": ".so"}
```

This is pointing to a stock Python3 on macOS. The reported `include` directory does not exist, and will result in the error:

```
Error in watch_tree: can't call watch_tree() on non-directory /Library/Python/3.9/include
```

## 🔬 Minimal Reproduction

Cribbing heavily off of the local toolchain setup in the docs, on macOS 15.5:

```starlark
python.toolchain(python_version = "3.9")

local_runtime_repo = use_repo_rule(
"@rules_python//python/local_toolchains:repos.bzl",
"local_runtime_repo",
)

local_runtime_toolchains_repo = use_repo_rule(
"@rules_python//python/local_toolchains:repos.bzl",
"local_runtime_toolchains_repo",
)

local_runtime_repo(
name = "local_python3",
interpreter_path = "/usr/bin/python3",
on_failure = "warn"
)

local_runtime_toolchains_repo(
name = "local_toolchains",
runtimes = ["local_python3"],
)

# Step 3: Register the toolchains
register_toolchains("@local_toolchains//:all", dev_dependency = True)
```

## 🔥 Exception or Error

2025-07-01 10:07:16 CDT | : in
-- | --
  | 2025-07-01 10:07:16 CDT | Repository rule local_runtime_repo defined at:
  | 2025-07-01 10:07:16 CDT | /Users/buildkite/.cache/bazel/a876e18133e23b0f96cd6798b2a722d4/external/rules_python+/python/private/local_runtime_repo.bzl:149:37: in
  | 2025-07-01 10:07:16 CDT | ERROR: /Users/buildkite/.cache/bazel/a876e18133e23b0f96cd6798b2a722d4/external/rules_python+/python/private/repo_utils.bzl:448:25: An error occurred during the fetch of repository '+_repo_rules+local_python3':
  | 2025-07-01 10:07:16 CDT | Traceback (most recent call last):
  | 2025-07-01 10:07:16 CDT | File "/Users/buildkite/.cache/bazel/a876e18133e23b0f96cd6798b2a722d4/external/rules_python+/python/private/local_runtime_repo.bzl", line 102, column 26, in _local_runtime_repo_impl
  | 2025-07-01 10:07:16 CDT | repo_utils.watch_tree(rctx, rctx.path(info["include"]))
  | 2025-07-01 10:07:16 CDT | File "/Users/buildkite/.cache/bazel/a876e18133e23b0f96cd6798b2a722d4/external/rules_python+/python/private/repo_utils.bzl", line 448, column 25, in _watch_tree
  | 2025-07-01 10:07:16 CDT | mrctx.watch_tree(*args, **kwargs)
  | 2025-07-01 10:07:16 CDT | Error in watch_tree: can't call watch_tree() on non-directory /Library/Python/3.9/include
  | 2025-07-01 10:07:16 CDT | ERROR: no such package '@@+_repo_rules+local_python3//': can't call watch_tree() on non-directory /Library/Python/3.9/include
  | 2025-07-01 10:07:16 CDT | ERROR: /Users/buildkite/.cache/bazel/a876e18133e23b0f96cd6798b2a722d4/external/+_repo_rules2+local_toolchains/BUILD.bazel:6:30: @@+_repo_rules2+local_toolchains//:0001_default_py_cc_toolchain depends on @@+_repo_rules+local_python3//:os in repository @@+_repo_rules+local_python3 which failed to fetch. no such package '@@+_repo_rules+local_python3//': can't call watch_tree() on non-directory /Library/Python/3.9/include
  | 2025-07-01 10:07:16 CDT | ERROR: /Users/buildkite/builds/mbr-buildkite-agent-ios-prod-polite-carp-p6d4-1/slack/ios-pull-request/tools/pipeline_generator/BUILD.bazel:16:10: Analysis failed
  | 2025-07-01 10:07:16 CDT | ERROR: Analysis of target '//tools/pipeline_generator:main' failed; build aborted

## 🌍 Your Environment

**Operating System:** macOS 15.5

**Output of `bazel version`:**

  

Bazelisk version: 1.26.0
INFO: Invocation ID: 6e64a830-cfe4-4daf-bc8e-28424507a9c3
Build label: 8.2.1
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Thu Apr 17 18:31:45 2025 (1744914705)
Build timestamp: 1744914705
Build timestamp as int: 1744914705

**Rules_python version:**

  

1.5.0

**Anything else relevant?**

This can be worked around by creating the include directory:

```
sudo mkdir -p /Library/Python/3.9/include
```

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

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

Hướng nghiên cứu

Bắt đầu trong python/private/local_runtime_repo.bzl, tại lệnh gọi watch_tree khoảng dòng 102, sau đó đọc python/private/repo_utils.bzl quanh _watch_tree. Tái hiện việc thiết lập local_runtime_repo với /usr/bin/python3 trên macOS và xác minh rằng rule không còn thất bại khi đường dẫn include được báo cáo không tồn tại hoặc không phải là một thư mục.

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ó
3/5
Thời gian dự kiến
1-2 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
45/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.