|
14 | 14 | import temporalio.bridge.proto.health.v1.health_pb2 as health_service |
15 | 15 |
|
16 | 16 |
|
17 | | -def generate_match_arm(trait_name: str, method: MethodDescriptor) -> str: |
18 | | - match_template = Template("""\ |
19 | | - "$method_name" => { |
20 | | - rpc_call!(retry_client, call, $trait_name, $method_name) |
21 | | - }""") |
| 17 | +def generate_client_impl( |
| 18 | + file_descriptors: list[FileDescriptor], |
| 19 | + output_file: str = "temporalio/bridge/src/client_rpc_generated.rs", |
| 20 | +): |
| 21 | + print("generating bridge rpc calls") |
22 | 22 |
|
23 | | - return match_template.substitute( |
24 | | - method_name=pascal_to_snake(method.name), trait_name=trait_name |
25 | | - ) |
| 23 | + service_calls = [ |
| 24 | + generate_service_call(service_descriptor) |
| 25 | + for file_descriptor in file_descriptors |
| 26 | + for service_descriptor in file_descriptor.services_by_name.values() |
| 27 | + ] |
| 28 | + |
| 29 | + impl_template = Template("""// Generated file. DO NOT EDIT |
| 30 | +
|
| 31 | +use pyo3::exceptions::PyValueError; |
| 32 | +use pyo3::prelude::*; |
| 33 | +
|
| 34 | +use super::{ |
| 35 | + client::{rpc_req, rpc_resp, ClientRef, RpcCall}, |
| 36 | + rpc_call, |
| 37 | +}; |
| 38 | +
|
| 39 | +#[pymethods] |
| 40 | +impl ClientRef { |
| 41 | +$service_calls |
| 42 | +}""") |
| 43 | + |
| 44 | + with open(output_file, "w") as f: |
| 45 | + f.write(impl_template.substitute(service_calls="\n".join(service_calls))) |
| 46 | + |
| 47 | + print(f"successfully generated client at {output_file}") |
26 | 48 |
|
27 | 49 |
|
28 | 50 | def generate_service_call(service_descriptor: ServiceDescriptor) -> str: |
@@ -75,37 +97,15 @@ def generate_service_call(service_descriptor: ServiceDescriptor) -> str: |
75 | 97 | ) |
76 | 98 |
|
77 | 99 |
|
78 | | -def generate_client_impl( |
79 | | - file_descriptors: list[FileDescriptor], |
80 | | - output_file: str = "temporalio/bridge/src/client_rpc_generated.rs", |
81 | | -): |
82 | | - print("generating bridge rpc calls") |
83 | | - |
84 | | - service_calls = [ |
85 | | - generate_service_call(service_descriptor) |
86 | | - for file_descriptor in file_descriptors |
87 | | - for service_descriptor in file_descriptor.services_by_name.values() |
88 | | - ] |
89 | | - |
90 | | - impl_template = Template("""// Generated file. DO NOT EDIT |
91 | | -
|
92 | | -use pyo3::exceptions::PyValueError; |
93 | | -use pyo3::prelude::*; |
94 | | -
|
95 | | -use super::{ |
96 | | - client::{rpc_req, rpc_resp, ClientRef, RpcCall}, |
97 | | - rpc_call, |
98 | | -}; |
99 | | -
|
100 | | -#[pymethods] |
101 | | -impl ClientRef { |
102 | | -$service_calls |
103 | | -}""") |
104 | | - |
105 | | - with open(output_file, "w") as f: |
106 | | - f.write(impl_template.substitute(service_calls="\n".join(service_calls))) |
| 100 | +def generate_match_arm(trait_name: str, method: MethodDescriptor) -> str: |
| 101 | + match_template = Template("""\ |
| 102 | + "$method_name" => { |
| 103 | + rpc_call!(retry_client, call, $trait_name, $method_name) |
| 104 | + }""") |
107 | 105 |
|
108 | | - print(f"successfully generated client at {output_file}") |
| 106 | + return match_template.substitute( |
| 107 | + method_name=pascal_to_snake(method.name), trait_name=trait_name |
| 108 | + ) |
109 | 109 |
|
110 | 110 |
|
111 | 111 | def pascal_to_snake(input: str) -> str: |
|
0 commit comments