-
Notifications
You must be signed in to change notification settings - Fork 305
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 #6726
Support for Python Rules that are Code Generators #6726
Conversation
Please hold off on review as I am investigating a change in the way the logic will detect the code-generator scenario. |
I have done some investigation to try to avoid the use of the
It is possible to adjust the Python-related Aspect logic in the Plugin to derive the generated Python source from The problem is filtering the code-gen Targets to run with the Plugin's Aspect. The Plugin primarily does this filtering by running a Bazel Whilst it is possible to run a second Bazel The same problem applies for adding an additional attribute to From this investigation, given the constraints of the technology, it seems that the solution of identifying the Python code-generators using an Aside from Python... whilst I can see that the |
@ilanKeshet would it be useful in your case? |
Summary of outcomes on discussion around this;
|
f5e3bf3
to
6788b8e
Compare
It is possible to write Bazel rules that generate Python code and act as a `py_library`. The plugin is augmented with this change to have a means of detecting these sort of rules and be able to work with them.
I would prefer to develop PEP273-based solution, but PyCharm seems not to support it yet, so let's go |
6788b8e
to
eb38453
Compare
It is possible to write Bazel rules that generate Python code and act as a `py_library`. The plugin is augmented with this change to have a means of detecting these sort of rules and be able to work with them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let's merge it, however I'd like to ask you to add a projectview setting that would enable the new query call
|
||
BuildSystem buildSystem = Blaze.getBuildSystemProvider(project).getBuildSystem(); | ||
|
||
BlazeCommand.Builder command = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to keep the whole thing behind a projectview flag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @tpasternak; Thank you for the review. OK I'll try to get that flag / setting in place soon but I can't be sure of time-frames unfortunately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I did it here #6884
Checklist
Please note that the maintainers will not be reviewing this change until all checkboxes are ticked. See
the Contributions section in the README for more
details.
Discussion thread for this change
Issue number: #6725
Description of this change
Discovery and handling of code-generator Rules
The change introduces the ability for a code-generator Rule being able to carry a Tag
intellij-py-code-generator
. The presence of this tags signals...imports
provided on thePyInfo
Provider as the imports for the Rule. These outputimports
need to be mapped so that they look like inputimports
such as would be configured with the likes of thepy_library
Rule.py_library
Kind
as it will feign being apy_library
.In this way, the Plugin will deal with the output of the Rule as sources + imports rather than the input Rule attributes of
srcs
andimports
.After the logic in
SyncProjectTargetsHelper
issues abazel query ...
to find Targets, it will issue a secondbazel query ...
to search for the Tagintellij-py-code-generator
. The mechanism has been implemented in such a way that other languages could potentially use this Tag-based mechanism in the future so the review should consider the generality of the solution. It would be possible to issue a singlecquery
(with Starlark code) to perform both queries in one go, but such acquery
would be in consideration of build options which is probably not what is required in this case.I have also considered the option of querying for the
PyInfo
provider as a signal that a Rule were a code-generator for a Python project. I rejected this approach so far because...PyInfo
.intellij-py-code-generator
is opt-in so is less risky.A second change, this time in
AbstractPyImportResolverStrategy
, will alter the logic of collecting Python sources such that it is able to cope with processing a directory because this scenario is likely to come up with code generators. The source directory is walked looking for.py
files. If it encounters a "boundry file" such asWORKSPACE
orBUILD.bazel
then it will stop traversing the directories. In reality this won't happen with code-generators but it is implemented to ensure that the directory processing will work more generally.The pull request also carries some light documentation and a working example to demonstrate the feature.