Hey, guys! I've just started using pants and it i...
# plugins
w
Hey, guys! I've just started using pants and it is awesome. Currently learning to do plugin integration. I have two questions, mainly 1. The first one is about integration of https://prisma-client-py.readthedocs.io into the pantsbuild -- how would one approach the system like this? On the one hand side, it is a codegen that transforms spec into the python client to interact with the DB, on the other hand side, this is a migration engine, which creates commitable SQL files inside the service directory. 2. I have my own (just published) project (https://github.com/g-usi/asyncapi-python) that takes an AsyncAPI (https://www.asyncapi.com) spec and generates an Application python module from it. I am able to trigger
export-codegen
and it works correctly. It is also able to run, when I add it as a dependency of
python_soruce
, however, the generated modules do not appear in the generated
export
resolve, as protobuf sources would, and thus are invisible to my IDE. I was following https://www.pantsbuild.org/stable/docs/writing-plugins/common-plugin-tasks/add-codegen, is there anything I am missing?
g
For (2), I'd investigate
--export-py-generated-sources
works and potentially see if that is enough; or if you need to add support to your plugin.
For (1), I'm a bit unsure. I recall there's been discussion about similar (sqlalchemy, alembic?) in the context of django. Might be worth searching a bit and maybe checking issues/discussions on GitHub.
w
Thanks @gorgeous-winter-99296, thanks for your response For (1), I will continue my research. Prisma ORM is gaining a lot of popularity due to type safety that is portable to any programming language -- it will certainly be a good integration into Pantsbuild. For (2), my test project has the following export config:
Copy code
[export]
py_editable_in_resolve = ["python-default"]
py_generated_sources_in_resolve = ["python-default"]
py_resolve_format = "mutable_virtualenv"
I have both protobuf and asyncapi (my plugin) targets. They have identical behavior on
export-codegen
. My plugin contains only one rule. I wonder if this is the reason -- that I need a separate export rule.
Copy code
@rule
async def generate_python_from_asyncapi(
    request: GeneratePythonFromAsyncapiRequest,
    asyncapi: AsyncapiPython,
    platform: Platform,
) -> GeneratedSources: ...
g
I'm not too familiar with all the mechanics here; but the relevant code is here: https://github.com/pantsbuild/pants/blob/main/src/python/pants/backend/python/goals/export.py#L446-L468 Just at a quick glance, the following requirements have to be met: • Your target should have a resolve field, and the value of that field has to match the export • Your target should have a source field, and it cannot be a Python source field
w
@gorgeous-winter-99296, thanks a lot, I shall study the given source to build a proper rule