bazel-contrib / bazel-contrib/rules_python

Add Gazelle support for `importlib.import_module`?

Offen
#1,938 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
gazelle help wanted
Vorherrschende Sprache
Starlark
Sterne
688
Forks
721
Ø Merge
15 Std. 7 Min.
Gemergte PRs (30 T.)
76

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit dem Gazelle-Parser und der in der Issue referenzierten Diskussion in rules_python#1931. Bewerte Aufrufe von importlib.import_module mit konstanten Zeichenketten gegenüber dynamischen Aufrufen im Hinblick auf die Bedenken bezüglich zirkulärer Abhängigkeiten und lege anschließend das erwartete Verhalten fest; abgeschlossen ist die Aufgabe, wenn der Vorschlag einen festgelegten Umfang und einen abgestimmten Validierungspfad hat.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
build-system
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.