Skip to content

Conversation

nat-n
Copy link
Collaborator

@nat-n nat-n commented Oct 18, 2020

This builds on work started for #152, and will make it easier to support custom options. @adriangb


Make plugin use betterproto generated classes internally

This means the betterproto plugin no longer needs to depend directly on
protobuf.

This requires a small runtime hack to monkey patch some google types to
get around the fact that the compiler uses proto2, but betterproto
expects proto3.

Also:

  • regenerate google.protobuf package
  • fix a regex bug in the logic for determining whether to use a google
    wrapper type.
  • fix a bug causing comments to get mixed up when multiple proto files
    generate code into a single python module

Update deps & add generate_lib task

  • Remove plugin dependency on protobuf since it's no longer required.
  • Update poethepoet to for better pyproject toml syntax support
  • Add handy generate_lib poe task for maintaining generated libs

@nat-n nat-n requested a review from danielgtaylor October 18, 2020 21:04
"""
True if proto_field_obj is a OneOf, otherwise False.

.. warning::
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is referring to monkey_patch_oneof_index

@@ -139,6 +165,7 @@ def get_comment(
class ProtoContentBase:
"""Methods common to MessageCompiler, ServiceCompiler and ServiceMethodCompiler."""

source_file: FileDescriptorProto
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

turns out tracking the source_file is necessary to ensure we look in the right file to find comments, in case there are multiple source proto files in scope.

@@ -360,7 +400,7 @@ def betterproto_field_args(self) -> List[str]:
def field_wraps(self) -> Optional[str]:
"""Returns betterproto wrapped field type or None."""
match_wrapper = re.match(
r"\.google\.protobuf\.(.+)Value", self.proto_obj.type_name
r"\.google\.protobuf\.(.+)Value$", self.proto_obj.type_name
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this was causing chaos by matching EnumValueDescriptorProto as if it were EnumValue.

@nat-n nat-n force-pushed the use_betterproto branch 2 times, most recently from 2113cbf to 2cc3e05 Compare October 19, 2020 16:13
@nat-n nat-n added bug Something isn't working enhancement New feature or request refactor labels Nov 25, 2020
@nat-n nat-n mentioned this pull request Dec 8, 2020
@cetanu
Copy link
Collaborator

cetanu commented Mar 16, 2021

I've gone through, this all looks fine to me except for the one bit that I left a comment on, but even then it's simply me not understanding how it works.

If you want me to go through this more thoroughly I could checkout this branch and play with it for a bit, but if not I'd be keen to get this out the door in the beta release and uncover any small patches that need to be made later.

cetanu
cetanu previously approved these changes Mar 16, 2021
@cetanu
Copy link
Collaborator

cetanu commented Mar 31, 2021

Fixed the merge conflicts

nat-n added 2 commits March 31, 2021 23:26
This means the betterproto plugin no longer needs to depend durectly on
protobuf.

This requires a small runtime hack to monkey patch some google types to
get around the fact that the compiler uses proto2, but betterproto
expects proto3.

Also:
- regenerate google.protobuf package
- fix a regex bug in the logic for determining whether to use a google
  wrapper type.
- fix a bug causing comments to get mixed up when multiple proto files
  generate code into a single python module
- Remove plugin dependency on protobuf since it's no longer required.
- Update poethepoet to for better pyproject toml syntax support
- Add handy generate_lib poe task for maintaining generated libs
@nat-n nat-n force-pushed the use_betterproto branch from 2ea7e44 to 6f1754e Compare March 31, 2021 21:49
@nat-n
Copy link
Collaborator Author

nat-n commented Mar 31, 2021

@cetanu I rebased again and got CI tests to pass. I think it would be awesome to get this merged. There a a few other smaller quality improvement PRs waiting behind it. In my mind this is a minor milestone for betterproto's maturity, to not depend on protobuf to compile.

It's probably worth checking out and doing whatever is necessary satisfy yourself that it's good. I appreciate you taking the time.

@cetanu cetanu merged commit a890514 into master Mar 31, 2021
@cetanu cetanu deleted the use_betterproto branch March 31, 2021 22:49
cetanu referenced this pull request Apr 1, 2021
This means the betterproto plugin no longer needs to depend durectly on
protobuf.

This requires a small runtime hack to monkey patch some google types to
get around the fact that the compiler uses proto2, but betterproto
expects proto3.

Also:
- regenerate google.protobuf package
- fix a regex bug in the logic for determining whether to use a google
  wrapper type.
- fix a bug causing comments to get mixed up when multiple proto files
  generate code into a single python module
@Gobot1234 Gobot1234 mentioned this pull request Oct 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants