Skip to content

Commit 1d7ba85

Browse files
Reorder methods, use BETTERPROTO_DUMP for dump env var, docs.
1 parent 72d72b4 commit 1d7ba85

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

betterproto/plugin.py

+19-19
Original file line numberDiff line numberDiff line change
@@ -220,22 +220,6 @@ def generate_code(request, response):
220220
print(f"Writing {output_package_name}", file=sys.stderr)
221221

222222

223-
def lookup_method_input_type(method, types):
224-
package, name = parse_source_type_name(method.input_type)
225-
226-
for known_type in types:
227-
if known_type["type"] != "Message":
228-
continue
229-
230-
# Nested types are currently flattened without dots.
231-
# Todo: keep a fully quantified name in types, that is comparable with method.input_type
232-
if (
233-
package == known_type["package"]
234-
and name.replace(".", "") == known_type["name"]
235-
):
236-
return known_type
237-
238-
239223
def read_protobuf_type(item: DescriptorProto, path: List[int], proto_file, content):
240224
input_package_name = content["input_package"]
241225
template_data = content["template_data"]
@@ -369,6 +353,22 @@ def read_protobuf_type(item: DescriptorProto, path: List[int], proto_file, conte
369353
return data
370354

371355

356+
def lookup_method_input_type(method, types):
357+
package, name = parse_source_type_name(method.input_type)
358+
359+
for known_type in types:
360+
if known_type["type"] != "Message":
361+
continue
362+
363+
# Nested types are currently flattened without dots.
364+
# Todo: keep a fully quantified name in types, that is comparable with method.input_type
365+
if (
366+
package == known_type["package"]
367+
and name.replace(".", "") == known_type["name"]
368+
):
369+
return known_type
370+
371+
372372
def read_protobuf_service(
373373
service: ServiceDescriptorProto, index, proto_file, content, output_types
374374
):
@@ -428,7 +428,7 @@ def main():
428428
request = plugin.CodeGeneratorRequest()
429429
request.ParseFromString(data)
430430

431-
dump_file = os.getenv("DUMP_FILE")
431+
dump_file = os.getenv("BETTERPROTO_DUMP")
432432
if dump_file:
433433
dump_request(dump_file, request)
434434

@@ -448,11 +448,11 @@ def main():
448448
def dump_request(dump_file: str, request: CodeGeneratorRequest):
449449
"""
450450
For developers: Supports running plugin.py standalone so its possible to debug it.
451-
Run protoc (or generate.py) with DUMP_FILE="yourfile.bin" to write the request to a file.
451+
Run protoc (or generate.py) with BETTERPROTO_DUMP="yourfile.bin" to write the request to a file.
452452
Then run plugin.py from your IDE in debugging mode, and redirect stdin to the file.
453453
"""
454454
with open(str(dump_file), "wb") as fh:
455-
sys.stderr.write(f"\033[31mWriting: {dump_file}\033[0m\n")
455+
sys.stderr.write(f"\033[31mWriting input from protoc to: {dump_file}\033[0m\n")
456456
fh.write(request.SerializeToString())
457457

458458

0 commit comments

Comments
 (0)