Lifecycle hooks for generators? #1582
sneakers-the-rat
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everyone!
I'm doing a translation from a domain-specific schema to LinkML right now and working on some utility functions that I keep thinking should probably just be a part of the general Generator implementation.
It seems like it would be a common enough problem that people would want to customize the code generation process in idiosyncratic and hard to predict ways (and looking around the issues it seems I'm right), and so I'm wondering if we can do something similar to Sphinx's build phase hooks - eg. the user can provide a function with a specific signature and return type that is called at the different phases of generation.
So, for example, I have to modify the generated pydantic code to avoid shadowing a builtin, but that doesn't belong anywhere in the schema. To do that right now I have just made some skeletal abstraction around the most naive kind of patch that just treats the generated code as a big long string:
and then defined some patch in particular
which is then run with the simplest possible runner:
It seems like this could be generalized with a bit of work, the
Generator
class already looks like it has a decent build phase system, so it would mostly be a matter of providing some decorators/hooks/etc. to say "call this hook before/after this phase with xyz arguments and returning xyz" to be able to make this more formalized.An incomplete list
{:element_type}
- before generating a particular type of LinkML elementWonder what y'all think? I don't have a very good picture of the overall structure of the code yet, so IDK what's possible/desirable, but figured i'd raise for discussion
Beta Was this translation helpful? Give feedback.
All reactions