bazel-contrib / bazel-contrib/rules_python
pip library import masked by a local directory leading to failures
- 主要语言
- Starlark
- 星标
- 688
- 派生
- 721
- 平均合并
- 15 小时 7 分钟
- 30 天内合并 PR
- 76
描述
# 🐞 bug report
I'm seeing an unexpected testing failure when I import `google-cloud-storage` via pip, where there is also a subfolder called `grpc` local to the `py_library` under test.
It feels like a bug in how `py_library` resolves, certainly running the test with `python -m unittest [module]` works in the self-contained repro linked below.
### Affected Rule
`py_library` seems to be most likely rule.
### Is this a regression?
Uncertain, going back a few versions of rules_python hit the same issue.
### Description
The key parts is as follows:
`utils/BUILD.bazel:`
```
load("@rules_python//python:defs.bzl", "py_library", "py_test")
py_library(
name = "utils",
srcs = ["lib.py"],
visibility = ["//:__subpackages__"],
deps = [
"//utils/grpc",
"@pip//google_cloud_storage",
],
)
py_test(
name = "lib_test",
srcs = ["lib_test.py"],
deps = [":utils"],
)
```
The local `utils/grpc` subfolder just contains another trivial `py_library` that has a function that prints to stdout.
## 🔬 Minimal Reproduction
See https://github.com/paulannetts/bazel_py_issue_apr24
## 🔥 Exception or Error
Truncated error of `bazel test //utils:lib_test` (full error log available which jumps via the various pip dependencies of `google_cloud_storage`)
File "/private/var/tmp/_bazel_paul_lu/44119f469120dfe26bc0215a4f182a9c/sandbox/darwin-sandbox/9/execroot/_main/bazel-out/darwin_x86_64-fastbuild/bin/utils/lib_test.runfiles/rules_python~~pip~pip_39_google_auth/site-packages/google/auth/transport/grpc.py", line 37, in
class AuthMetadataPlugin(grpc.AuthMetadataPlugin):
AttributeError: module 'grpc' has no attribute 'AuthMetadataPlugin'
## 🌍 Your Environment
**Operating System:**
MacOS Sonoma
**Output of `bazel version`:**
Bazelisk version: development
Starting local Bazel server and connecting to it...
Build label: 7.1.1
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Thu Mar 21 18:08:59 2024 (1711044539)
Build timestamp: 1711044539
Build timestamp as int: 1711044539
**Rules_python version:**
`rules_python 0.31.0`
**Other info:**
Using bzlmod
`gazelle 0.35`
`python 3.9`
贡献指南
调研方向
从链接的最小复现开始,并运行 `bazel test //utils:lib_test`。阅读 `utils/BUILD.bazel`、`lib.py`、`lib_test.py` 以及本地的 `utils/grpc` 库,以跟踪 `google_cloud_storage` 依赖是如何导入的。完成的标准是:测试不再将本地 `grpc` 目录解析为 pip 依赖的替代项,并且成功通过。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- build-system
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100