Skip to content

REF: Spin off tree -> code compilation into a separate module #136

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

Merged
merged 3 commits into from
Aug 9, 2020

Conversation

adriangb
Copy link
Contributor

@adriangb adriangb commented Aug 4, 2020

This small edit splits off the actual code generation based on the models.py classes into its own module. The hope is that it would be possible to swap out the new compiler.py for another module that implements the outputfile_compiler function with the same signature, thus allowing for generation of arbitrary code based on the models.py tree structure.

@@ -70,16 +69,6 @@ def generate_code(
) -> None:
plugin_options = request.parameter.split(",") if request.parameter else []
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does anyone know how to encode an alternative template/compiler (i.e. to swap out betterproto.plugin.compiler.py) as part of the command line options?

Copy link
Contributor Author

@adriangb adriangb Aug 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal here is that at the very least someone could copy compiler.py to my_compiler.py and edit the template (or the rendering method altogether) and pass an option to protoc that would tell plugin.py to import my_compiler.outputfile_compiler and use that instead of the default one. It's not a super clean API or anything but it should be powerful and a good starting place for other changes. This options parsing doesn't need to be part of this PR, just asking for future reference.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you have in mind being able to do something like:

protoc --python_betterproto_out=lib --custom_opt=TYPE_VALIDATION,SILLY_WALKS,WHATEVER -I ...

I like the idea of stuff being modular and potentially configurable in this way. But I wouldn't race to provide an API to support fully support this without a real use case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change stands on it's own, and I agree with you that more discussion is needed before providing an API to do the above, but I do want to make sure that this change is at least compatible with that approach.

@nat-n nat-n merged commit c93351e into danielgtaylor:master Aug 9, 2020
@adriangb adriangb deleted the split-off-compiler branch August 9, 2020 18:15
@abn abn mentioned this pull request Nov 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants