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

Support for Python Rules that are Code Generators #6725

Open
andponlin-canva opened this issue Sep 4, 2024 · 2 comments
Open

Support for Python Rules that are Code Generators #6725

andponlin-canva opened this issue Sep 4, 2024 · 2 comments
Assignees
Labels
awaiting-maintainer Awaiting review from Bazel team on issues product: CLion CLion plugin product: GoLand GoLand plugin product: IntelliJ IntelliJ plugin product: PyCharm PyCharm plugin type: feature request

Comments

@andponlin-canva
Copy link
Contributor

andponlin-canva commented Sep 4, 2024

Description of the feature request:

Please see accompanying PR 6726.

Plugin recognizing code generators

When working with Python in Bazel, it is sometimes desirable to generate code using an Action configured from a Rule. In this situation, the Rule that configures the Action might return a PyInfo and to all intents and purposes behave as a py_library.

In the Intelli-J environment, the Rule would however not be recognized and the outputs of the Rule would not be seen as source code. This means that in logic that uses the generated code, these sources would simply be missing and would show as errors in the IDE.

It would be ideal if there were a means by which Rules could signal to the IDE that their outputs rather than their inputs (srcs attribute) supplied the sources for the Rule.

Plugin handling source supplied as a directory

Code generators are often not able to specify the precise list of output files ahead of time. This might be because the list of files is contingent on the contents of an input such as schema. For this reason the outputs from a code-generators' Rule might be a directory. In this case, The IDE is currently not able to handle a directory of Python source; it is wanting to work with files only. It would be better if the Plugin were able to work with source directories as well.

Which category does this issue belong to?

Intellij, GoLand, CLion, PyCharm

What underlying problem are you trying to solve with this feature?

At the present time when a Python Bazel Project uses the outputs of a code-generator Rule, the sources from the code generator are not recognized in the IDE and show as errors.

What operating system, Intellij IDE and programming languages are you using? Please provide specific versions.

2024.1

Have you found anything relevant by searching the web?

--

Any other information, logs, or outputs that you want to share?

--

@andponlin-canva
Copy link
Contributor Author

Before

If I open the example found at examples/python/simple_code_generator from the PR branch with the Intelli-J / Bazel plugin installed as the mainline build from master (from the Marketplace) then I see the following when I sync and open the main.py file;

before

The behavior of the IDE confirms the anticipation;

  • print_rivers will be found because it is not generated source; it is checked-in source via the :static_lib Bazel Target.
  • the IDE will fail to "find" print_cities symbol because it is generated by a Bazel Rule :generated_files_lib that outputs single files.
  • the IDE will fail to "find" the print_plastics symbol because it is generated by a Bazel Rule :test_codegen_directory_py that outputs a directory of Python source files.

After

If I compile and install the Intelli-J / Bazel plugin from the PR branch (rebased 2024-09-27) then after I resync and open main.py file;

after

Now all of the sources are discovered by the IDE which is the desired outcome.

@andponlin-canva
Copy link
Contributor Author

andponlin-canva commented Oct 12, 2024

Please see three related follow-up PRs;

For those looking at this later, I added some documentation for this change here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-maintainer Awaiting review from Bazel team on issues product: CLion CLion plugin product: GoLand GoLand plugin product: IntelliJ IntelliJ plugin product: PyCharm PyCharm plugin type: feature request
Projects
None yet
Development

No branches or pull requests

4 participants