Skip to content
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

Implement command line interface #165

Draft
wants to merge 54 commits into
base: master
Choose a base branch
from

Conversation

Gobot1234
Copy link
Collaborator

@Gobot1234 Gobot1234 commented Oct 19, 2020

Implements a command line interface for the module abstracting away the use of protoc to under the hood.

Objectives

  • An improvement over the current implementation using protoc
  • Ability to easily add options to compilation.
  • Backwards compatible.
  • Programmatic access to compile files.

How to improve current implementation

  • Show information on what is currently happening.
  • Make it easier to develop betterproto and hook into the plugin.
  • Use typer/click for command line implementation and parsing.
  • Show helpful messages when something is a protoc SyntaxError etc.
  • Make it easier to debug.

Custom options

  • Typer can easily add more arguments to the cli without breaking anything.

Backwards compatibility

This is obviously important. I plan to achieve this with an ENV var which will determine whether or not protoc was invoked with the plugin if it wasn't invoked with protoc I would like to display a warning saying that direct invocation of protoc is depreciated and the command they could use in the future.

Programmatic access

I plan to make a few functions accessible using the betterproto API under the name compile_protobufs in the plugin package using https://github.com/Gobot1234/protobuf-parser.

TODO:

  • Better error handling.
  • Cleanup.
  • Make this a "well behaved CLI" (with return codes and stdout/stderr separation.
  • Testing
% betterproto compile --help

Usage: betterproto compile [OPTIONS] PATHS...

  The recommended way to compile your protobuf files.

Arguments:
  PATHS...  The protobuf files to compile  [required]

Options:
  -v, --verbose                   Whether or not to be verbose  [default:
                                  False]

  -l, --line-length INTEGER       The line length to format with  [default:
                                  88]

  --generate-services / --no-generate-services
                                  Whether or not to generate servicer stubs
                                  [default: True]

  --output DIRECTORY              The name of the output directory
  -h, --help                      Show this message and exit.

Main entry point for compilation is with betterproto compile this will make it potentially easier to add custom arguments for compilation down the road and makes invocation much simpler as with the old system you would have to run:

protoc --python_betterproto_out=betterproto_out -I betterproto_out.parent files...

Whereas now it is:

betterproto compile files...

Gobot1234 and others added 11 commits August 24, 2020 14:04
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
@Gobot1234
Copy link
Collaborator Author

grcp support still needs to be tested but I currently can't do that myself.

@Gobot1234 Gobot1234 marked this pull request as draft January 16, 2021 18:05
@Gobot1234 Gobot1234 marked this pull request as ready for review January 31, 2021 16:09
@Gobot1234 Gobot1234 marked this pull request as draft March 27, 2021 00:10
# Conflicts:
#	poetry.lock
#	pyproject.toml
#	src/betterproto/plugin/main.py
#	src/betterproto/plugin/models.py
#	src/betterproto/plugin/parser.py
#	tests/inputs/oneof/test_oneof.py
#	tests/util.py
@Gobot1234
Copy link
Collaborator Author

Small update on this and my parsing library, I can successfully parse file inputs using protoc, unfortunately making a run function doesn't appear to be very feasible ATM, but I'm hopeful I can get this figured out relatively quickly.

Gobot1234 and others added 7 commits July 18, 2021 19:25
# Conflicts:
#	README.md
#	pyproject.toml
#	src/betterproto/plugin/compiler.py
#	src/betterproto/plugin/main.py
#	src/betterproto/plugin/models.py
#	src/betterproto/plugin/parser.py
#	tests/generate.py
#	tests/test_features.py
#	tests/util.py
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.

2 participants