-
Notifications
You must be signed in to change notification settings - Fork 229
Fix - No arguments are generated for stub methods when using import
with proto definition
#103
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
Fix - No arguments are generated for stub methods when using import
with proto definition
#103
Conversation
… is flattened into two python packages
… its possible to debug it.
…s fixed before.
…essage # Conflicts: # betterproto/plugin.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Multiple passes is definitely a step in the right direction.
I'd say it's good to go with a couple tweaks.
betterproto/plugin.py
Outdated
Then run plugin.py from your IDE in debugging mode, and redirect stdin to the file. | ||
""" | ||
with open(str(dump_file), "wb") as fh: | ||
sys.stderr.write(f"\033[31mWriting: {dump_file}\033[0m\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sys.stderr.write(f"\033[31mWriting: {dump_file}\033[0m\n") | |
sys.stderr.write(f"\033[31mWriting input from protoc to: {dump_file}\033[0m\n") |
betterproto/plugin.py
Outdated
@@ -386,6 +428,10 @@ def main(): | |||
request = plugin.CodeGeneratorRequest() | |||
request.ParseFromString(data) | |||
|
|||
dump_file = os.getenv("DUMP_FILE") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dump_file = os.getenv("DUMP_FILE") | |
dump_file = os.getenv("BETTERPROTO_DUMP") |
@@ -373,8 +216,207 @@ def generate_code(request, response): | |||
init = response.file.add() | |||
init.name = str(init_file) | |||
|
|||
for filename in sorted(output_paths.union(init_files)): | |||
print(f"Writing {filename}", file=sys.stderr) | |||
for output_package_name in sorted(output_paths.union(init_files)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this diff sucks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, it went pretty bad after splitting up code into methods and renaming a bunch of vars :-/
should happen less and less as we get the code more organized
betterproto/plugin.py
Outdated
print(f"Writing {output_package_name}", file=sys.stderr) | ||
|
||
|
||
def lookup_method_input_type(method, types): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could move this method closer to where it's used (swap with read_protobuf_type)
Just a quick note about debugging: I had good success using VSCode with ptsvd. In def main():
import ptvsd
ptvsd.enable_attach()
ptvsd.wait_for_attach() # blocks execution until debugger is attached And set breakpoints in VSCode wherever you want to drop into. Then in {
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": false,
},
{
"name": "Attach (Remote Debug)",
"type": "python",
"request": "attach",
"localRoot": "${workspaceRoot}",
"remoteRoot": "${workspaceRoot}",
"port": 5678,
"secret": "",
"host":"0.0.0.0",
"justMyCode": false,
},
]
} Now running anything that calls |
Awesome tip! I took a note when you mentioned it on slack, and also found that PyCharm has something similar for those who use it. Haven't tried it yet tho! |
Fixes #23
Due to too much juggling with different branches, and an incorrect test-case, I mistakenly thought this bug was already fixed earlier.
The bug:
The solution
Additionally:
plugin.py
as it is called byprotoc
, so attaching a debugger involves freezing the plugin when it starts, then finding the process id, then attaching, and waiting till the freeze is completed.protoc
to a file, and then runplugin.py
directly with that input (stdin). Now you can debug the plugin with your IDE 💪