ripe-cpu-85141
08/01/2022, 10:34 PMpants-plugins/tutugen which contains a register.py file and a BUILD file. First, I'm not sure what I should put on the BUILD file. I read about python_source, python_requirement and pants_requirements. I'm not sure which ones should go in the file.
Then, the plugin requires a 3rd party lib named tutu . If I try to exec any pants commands, I get a No module named: 'tutu' error. I'm not sure what is missing :-/happy-kitchen-89482
08/01/2022, 10:43 PMpython_sources should wrap your plugin's source files. Having that depend on a pants_requirements() target is handy shorthand for "depend on the version of Pants I am running in", so you don't have to repeat that version (and ensure it matches the version= value in your pants.toml), as you would if you used a regular python_requirements.happy-kitchen-89482
08/01/2022, 10:43 PMpython_requirement for tutu (or you can put it in a requirements.txt and use a python_requirements() to point to that, as usual)happy-kitchen-89482
08/01/2022, 10:44 PMtutu? If not then you'll need an explicit dep from the plugin's python_sources to the python_requirement target for tutuhappy-kitchen-89482
08/01/2022, 10:45 PMregister.py to your backend_packages in pants.tomlripe-cpu-85141
08/01/2022, 10:45 PMregister.py imports tutu . The error happens when pants tries to load the backendhappy-kitchen-89482
08/01/2022, 10:46 PMpythonpath = ["%(buildroot)s/path/to/plugin/source/root"] in pants.tomlhappy-kitchen-89482
08/01/2022, 10:46 PMpants.toml is set up correctlyhappy-kitchen-89482
08/01/2022, 10:46 PMtutu in a requirements.txt, or a python_requirement ?ripe-cpu-85141
08/01/2022, 10:46 PMhappy-kitchen-89482
08/01/2022, 10:47 PMhappy-kitchen-89482
08/01/2022, 10:47 PMtutu requirement to plugins = [] in pants.tomlripe-cpu-85141
08/01/2022, 10:47 PMpython_requirement on a BUILD file in the module (alongside register.py)happy-kitchen-89482
08/01/2022, 10:47 PMplugins list.hundreds-father-404
08/01/2022, 10:50 PMpants_requirements and python_sources targets for a plugin to work; all that matters is the [GLOBAL].plugins, backend_packages, and pythonpath options.
But, it's a good idea to have pants_requirements and python_sources so that you can run Pants on your plugin code, e.g. format it and lint itripe-cpu-85141
08/01/2022, 10:51 PMripe-cpu-85141
08/01/2022, 10:52 PMripe-cpu-85141
08/01/2022, 10:52 PMhundreds-father-404
08/01/2022, 10:53 PMthe goal export-codegen doesn't existA relevant backend needs to be implemented. We hide irrelevant goals by default. Did you register a
UnionRule(GenerateSourcesRequest, ...)?hundreds-father-404
08/01/2022, 10:53 PMUnionRule(GenerateSourcesRequest, GeneratePythonFromProtobufRequest)ripe-cpu-85141
08/01/2022, 10:54 PMhundreds-father-404
08/01/2022, 10:55 PMregister.py. For example, we often have a dedicated file rules.py. You need to import that and then register its rules inside `register.py`'s def rules() functionripe-cpu-85141
08/01/2022, 10:56 PMregister.py. I have the UnionRule(...)ripe-cpu-85141
08/01/2022, 10:56 PMhundreds-father-404
08/01/2022, 10:57 PMfrom pants.engine.target import Target
class MyTarget(Target):
alias = "my_target"
core_fields = ()
help = "blah"
def target_types():
return [MyTarget]
Then ./pants help targetsripe-cpu-85141
08/01/2022, 10:58 PMhundreds-father-404
08/01/2022, 10:59 PM./pants export-codegen isn't showing up then... GenerateSourcesRequest does have a class property exportable: bool, but it defaults to Truehundreds-father-404
08/01/2022, 10:59 PMripe-cpu-85141
08/01/2022, 11:01 PMripe-cpu-85141
08/01/2022, 11:02 PMripe-cpu-85141
08/01/2022, 11:03 PMhundreds-father-404
08/01/2022, 11:05 PMThe only difference (besides possible typos) is that the Request class parameters input and output have the same typeI think that's legal
hundreds-father-404
08/01/2022, 11:05 PM./pants export-codegen ::?ripe-cpu-85141
08/01/2022, 11:05 PMripe-cpu-85141
08/01/2022, 11:06 PMripe-cpu-85141
08/01/2022, 11:06 PM./pants help goalshundreds-father-404
08/01/2022, 11:07 PMpants.backend.codegen.protobuf.python, does it show up at least?ripe-cpu-85141
08/01/2022, 11:09 PM./pants export-codegen :: , it actually call my backendripe-cpu-85141
08/01/2022, 11:09 PM