Skip to content

Commit 98d00f0

Browse files
Supports running plugin.py standalone by reading from a dump-file, so its possible to debug it.
1 parent 0af0cf4 commit 98d00f0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

betterproto/plugin.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,10 @@ def main():
386386
request = plugin.CodeGeneratorRequest()
387387
request.ParseFromString(data)
388388

389+
dump_file = os.getenv("DUMP_FILE")
390+
if dump_file:
391+
dump_request(dump_file, request)
392+
389393
# Create response
390394
response = plugin.CodeGeneratorResponse()
391395

@@ -399,5 +403,16 @@ def main():
399403
sys.stdout.buffer.write(output)
400404

401405

406+
def dump_request(dump_file: str, request: CodeGeneratorRequest):
407+
"""
408+
For developers: Supports running plugin.py standalone so its possible to debug it.
409+
Run protoc (or generate.py) with DUMP_FILE="yourfile.bin" to write the request to a file.
410+
Then run plugin.py from your IDE in debugging mode, and redirect stdin to the file.
411+
"""
412+
with open(str(dump_file), "wb") as fh:
413+
sys.stderr.write(f"\033[31mWriting: {dump_file}\033[0m\n")
414+
fh.write(request.SerializeToString())
415+
416+
402417
if __name__ == "__main__":
403418
main()

0 commit comments

Comments
 (0)