Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Gazelle support for importlib.import_module? #1938

Open
dougthor42 opened this issue Jun 2, 2024 · 1 comment
Open

Add Gazelle support for importlib.import_module? #1938

dougthor42 opened this issue Jun 2, 2024 · 1 comment
Labels
gazelle Gazelle plugin related issues help wanted

Comments

@dougthor42
Copy link
Contributor

🚀 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 #1931 (comment), 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().

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.

@aignas
Copy link
Collaborator

aignas commented Jun 3, 2024

My thinking is that if somebody is using importlib and gazelle then they now what they are doing and the can use the feature from #1863.

@aignas aignas added the gazelle Gazelle plugin related issues label Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gazelle Gazelle plugin related issues help wanted
Projects
None yet
Development

No branches or pull requests

3 participants