How To Package Generated Python Files In Custom Bazel Rule Or Genrule?
Let's say I have a scripts which generates Java and Python code. The files it generates depends on the input config, it can vary based on the config. Now, in the case of Java, I ca
Solution 1:
One way to do this is to write your own Starlark rule that returns a PyInfo provider with your generated files in the transitive_sources
. You'd then add the rule to the deps
attribute of your py_library rule.
The drawback is that you have to know at loading phase (so before the code generation has happened) what files will be generated by your tool, no cheating with zips/jars.
If that's not an option I could think of a hacky workaround where you produce a zip that you depend on in your py_libarary's data deps. You then unpack the file at runtime before you actually import it.
Depending on how you've set up your python rules you might also be able to build a python wheel in your code generator and depend on that.
Post a Comment for "How To Package Generated Python Files In Custom Bazel Rule Or Genrule?"