bazel-contrib / bazel-contrib/rules_python

Gazelle python_root directive only adds imports to subfolders

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

Gazelle plugin target generation

### Is this a regression?

No

### Description

python targets that do not share root with the workspace needs `imports = [...]` statements added for imports to work correctly. The gazelle plugin supports this through adding `# gazelle:python_root` directives in `BUILD` files that are at the root of python trees. This works great for source files in subfolders, they have attributes like `imports = ["../.."],` added. However the sources files in the root folder itself does not get any imports attribute, while they need to have `imports = ["."]` to work correctly.

## 🔬 Minimal Reproduction

## 🔥 Exception or Error

Target py_binary file fails on run due to missing import.

## 🌍 Your Environment

**Operating System:**

  

Ubuntu 24.10

**Output of `bazel version`:**

  

Bazelisk version: v1.25.0
Build label: 8.0.1
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Fri Jan 17 19:16:16 2025 (1737141376)
Build timestamp: 1737141376
Build timestamp as int: 1737141376

**Rules_python version:**

  

bazel_dep(name = "rules_python", version = "1.1.0")
bazel_dep(name = "rules_python_gazelle_plugin", version = "1.1.0")

**Anything else relevant?**

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

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

Hướng nghiên cứu

Bắt đầu bằng cách theo dõi quá trình tạo target của plugin Gazelle cho các tệp BUILD chứa chỉ thị `# gazelle:python_root`, tập trung vào các mã nguồn Python ở cấp thư mục gốc và các target `py_binary` được tạo. So sánh các target ở thư mục gốc với các target ở thư mục con và xác minh rằng sau khi hoàn tất việc tạo, `imports = ["."]` được thêm vào khi cần, sau đó xác nhận target chạy mà không gặp lỗi thiếu import.

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
35/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.