bazel-contrib / bazel-contrib/rules_python

Gazelle generates py_proto_library with imports attribute when in a non-root python_root

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

描述

# 🐞 bug report

### Affected Rule

`gazelle`

### Is this a regression?

No, I believe it's a new feature introduced by https://github.com/bazel-contrib/rules_python/issues/2994 and it seems to be not working as expected in the specific situation of this report.

### Description

When using gazelle to generate [`py_proto_library`](https://github.com/bazel-contrib/rules_python/issues/2994), it doesn't work as expected when the proto file is in a subfolder of a python root that differs from the repo root (specified with the directive `# gazelle:python_root`).

Gazelle generates the target with an `imports` attribute, which is not supported and thus the target fails to build.

## 🔬 Minimal Reproduction

https://github.com/regb/issue-reports/tree/main/rules_python/py_proto_imports

## 🔥 Exception or Error

Gazelle runs smoothly but generates the invalid targets, then running build generate this error:



$ bazel build ...
ERROR: /home/regb/vcs/issue-reports/rules_python/py_proto_imports/src/mypackage/BUILD.bazel:10:17: //src/mypackage:example_py_pb2: no such attribute 'imports' in 'py_proto_library' rule
ERROR: package contains errors: src/mypackage
ERROR: package contains errors: src/mypackage: //src/mypackage:example_py_pb2: no such attribute 'imports' in 'py_proto_library' rule
WARNING: Target pattern parsing failed.
ERROR: Skipping '...': Error evaluating '...': error loading package 'src/mypackage': Package 'src/mypackage' contains errors
ERROR: Error evaluating '...': error loading package 'src/mypackage': Package 'src/mypackage' contains errors
INFO: Elapsed time: 0.136s
INFO: 0 processes.
ERROR: Build did NOT complete successfully

## 🌍 Your Environment

**Operating System:**

  

Ubuntun 22.04

**Output of `bazel version`:**

  

8.5.0

**Rules_python version:**

  

1.7.0 (also tested 1.6.3)

贡献指南

打开贡献指南

调研方向

从 regb/issue-reports/rules_python/py_proto_imports 中的最小复现开始,检查 src/mypackage 下生成的 BUILD.bazel,重点关注 # gazelle:python_root 指令和生成的 py_proto_library 目标。运行 Gazelle,然后运行 bazel build ...;当生成的目标不再包含不受支持的 imports 属性且构建成功时,即表示完成。

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

评估

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

把新 issue 发到你的邮箱

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