bazel-contrib / bazel-contrib/rules_python

Add Gazelle support for `importlib.import_module`?

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

# 🚀 feature request

### Relevant Rules

+ gazelle

### Description

First off, I want to say that I'm not sure if this is a good idea or not. So feel free to shoot it down 🤣.

In https://github.com/bazelbuild/rules_python/pull/1931#issuecomment-2141255218, it was said that the gazelle parser only needs to know about a subset of the python language:

> + comments
> + `if __name__ == "__main__"`
> + `from foo import bar`
> + `import foo`

However, there's another way to import other python code: [`importlib.import_module()`](https://docs.python.org/3/library/importlib.html#importlib.import_module).

**Should Gazelle parse these and attempt to add dependencies for them?**

#### Issues

There are a couple pretty big issues with trying to do so:

1. In my experience, `importlib.import_module` is typically used as a way to work around circular dependencies. So having Gazelle parse them would just result in a broken build, probably frustrating users more than helping.
2. There's no way to figure out what the runtime value would be.
+ So we could anything that's a string constant:
`import_module("foo.bar.baz")`
but not
`module = input("Enter a module name: "); import_module(module)` or even
`module = "foo.bar.baz"; import_module(module)`

#### Benefits

Umm... I guess if `import_module` is used in a _very specific_ way, then it would make making build files easier.

### Describe the solution you'd like

N/A

### Describe alternatives you've considered

Manually adding dependencies after running Gazelle. Not a big deal, IMO.

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

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

Hướng nghiên cứu

Bắt đầu với parser Gazelle và phần thảo luận trong rules_python#1931 được issue tham chiếu. Đánh giá các lệnh gọi importlib.import_module sử dụng chuỗi hằng so với các lệnh gọi động xét theo những lo ngại về dependency vòng, sau đó xác định hành vi mong đợi; công việc được xem là hoàn tất khi proposal có phạm vi đã được quyết định và một quy trình validation đã được thống nhất.

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
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/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.