bazel-contrib / bazel-contrib/rules_python

Add Gazelle support for `importlib.import_module`?

オープン
#1,938 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
gazelle help wanted
主要言語
Starlark
スター
688
フォーク
721
平均マージ
15時間 7分
マージ済み PR(30日)
76

説明

# 🚀 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.

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

Gazelle parser と、issue で参照されている rules_python#1931 の議論から始めてください。循環依存に関する懸念を踏まえて、定数文字列を使う importlib.import_module 呼び出しと動的な呼び出しを評価し、そのうえで期待される動作を確立してください。提案のスコープが決定され、合意された検証パスが定まれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
build-system
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。