bazel-contrib / bazel-contrib/rules_python

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

未关闭
#3,043 7 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
type: bug type: toolchain
主要语言
Starlark
星标
688
派生
721
平均合并
15 小时 7 分钟
30 天内合并 PR
76

描述

# 🐞 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
```

贡献指南

打开贡献指南

调研方向

从 python/private/local_runtime_repo.bzl 中第 102 行附近的 watch_tree 调用开始,然后阅读 python/private/repo_utils.bzl 中 _watch_tree 附近的内容。使用 /usr/bin/python3 在 macOS 上复现 local_runtime_repo 的设置,并验证当报告的 include 路径不存在或不是目录时,该规则不再失败。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
build-system
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。