Skip to content

Commit bb4dca4

Browse files
committed
Add generated doc strings and remove exception from pydocstyle
1 parent 888e1f8 commit bb4dca4

File tree

4 files changed

+554
-364
lines changed

4 files changed

+554
-364
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ exclude = [
122122
[tool.pydocstyle]
123123
convention = "google"
124124
# https://github.com/PyCQA/pydocstyle/issues/363#issuecomment-625563088
125-
match_dir = "^(?!(docs|scripts|tests|api|proto|generated|\\.)).*"
125+
match_dir = "^(?!(docs|scripts|tests|api|proto|\\.)).*"
126126
add_ignore = [
127127
# We like to wrap at a certain number of chars, even long summary sentences.
128128
# https://github.com/PyCQA/pydocstyle/issues/184

scripts/gen_bridge_client.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717

1818
def generate_python_services(
1919
file_descriptors: list[FileDescriptor],
20-
output_file: str = "temporalio/bridge/generated/services_generated.py",
20+
output_file: str = "temporalio/bridge/services_generated.py",
2121
):
2222
print("generating python services")
2323

24-
services_template = Template("""# Generated file. DO NOT EDIT
24+
services_template = Template('''# Generated file. DO NOT EDIT
25+
"""Generated RPC calls for Temporal services."""
2526
2627
from __future__ import annotations
2728
@@ -36,7 +37,7 @@ def generate_python_services(
3637
from temporalio.service import ServiceClient
3738
3839
$service_defns
39-
""")
40+
''')
4041

4142
def service_name(s):
4243
return f"import {sanitize_proto_name(s.full_name)[:-len(s.name)-1]}"
@@ -63,13 +64,15 @@ def service_name(s):
6364

6465

6566
def generate_python_service(service_descriptor: ServiceDescriptor) -> str:
66-
service_template = Template("""
67+
service_template = Template('''
6768
class $service_name:
69+
"""RPC calls for the $service_name."""
6870
def __init__(self, client: ServiceClient):
69-
self.client = client
70-
self.service = "$rpc_service_name"
71+
"""Initialize service with the provided ServiceClient."""
72+
self._client = client
73+
self._service = "$rpc_service_name"
7174
$method_calls
72-
""")
75+
''')
7376

7477
sanitized_service_name: str = service_descriptor.name
7578
# The health service doesn't end in "Service" in the proto definition
@@ -88,7 +91,7 @@ def __init__(self, client: ServiceClient):
8891
]
8992

9093
method_calls = [
91-
generate_python_method_call(method)
94+
generate_python_method_call(sanitized_service_name, method)
9295
for method in sorted(methods, key=lambda m: m.name)
9396
]
9497

@@ -99,27 +102,31 @@ def __init__(self, client: ServiceClient):
99102
)
100103

101104

102-
def generate_python_method_call(method_descriptor: MethodDescriptor) -> str:
103-
method_template = Template("""
105+
def generate_python_method_call(
106+
service_name: str, method_descriptor: MethodDescriptor
107+
) -> str:
108+
method_template = Template('''
104109
async def $method_name(
105110
self,
106111
req: $request_type,
107112
retry: bool = False,
108113
metadata: Mapping[str, Union[str, bytes]] = {},
109114
timeout: Optional[timedelta] = None,
110115
) -> $response_type:
111-
return await self.client._rpc_call(
116+
"""Invokes the $service_name.$method_name rpc method."""
117+
return await self._client._rpc_call(
112118
rpc="$method_name",
113119
req=req,
114-
service=self.service,
120+
service=self._service,
115121
resp_type=$response_type,
116122
retry=retry,
117123
metadata=metadata,
118124
timeout=timeout,
119125
)
120-
""")
126+
''')
121127

122128
return method_template.substitute(
129+
service_name=service_name,
123130
method_name=pascal_to_snake(method_descriptor.name),
124131
request_type=sanitize_proto_name(method_descriptor.input_type.full_name),
125132
response_type=sanitize_proto_name(method_descriptor.output_type.full_name),

0 commit comments

Comments
 (0)