Support for Python Rules that are Code Generators
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?
--
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;
The behavior of the IDE confirms the anticipation;
print_riverswill be found because it is not generated source; it is checked-in source via the:static_libBazel Target.- the IDE will fail to "find"
print_citiessymbol because it is generated by a Bazel Rule:generated_files_libthat outputs single files. - the IDE will fail to "find" the
print_plasticssymbol because it is generated by a Bazel Rule:test_codegen_directory_pythat 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;
Now all of the sources are discovered by the IDE which is the desired outcome.
Please see three related follow-up PRs;
For those looking at this later, I added some documentation for this change here
This work is completed now.