Skip to content

Commit e62c38b

Browse files
authored
docs: fix update subscription/snapshot/topic samples (#113)
1 parent 06085c4 commit e62c38b

File tree

3 files changed

+72
-6
lines changed

3 files changed

+72
-6
lines changed

google/cloud/pubsub_v1/gapic/publisher_client.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,13 @@ def update_topic(
349349
>>>
350350
>>> client = pubsub_v1.PublisherClient()
351351
>>>
352-
>>> # TODO: Initialize `topic`:
353-
>>> topic = {}
352+
>>> topic_name = 'projects/my-project/topics/my-topic'
353+
>>> topic_labels = {'source': 'external'}
354+
>>> topic = {'name': topic_name, 'labels': topic_labels}
354355
>>>
355-
>>> # TODO: Initialize `update_mask`:
356-
>>> update_mask = {}
356+
>>> paths_element = 'labels'
357+
>>> paths = [paths_element]
358+
>>> update_mask = {'paths': paths}
357359
>>>
358360
>>> response = client.update_topic(topic, update_mask)
359361

google/cloud/pubsub_v1/gapic/subscriber_client.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,11 @@ def update_subscription(
525525
>>> client = pubsub_v1.SubscriberClient()
526526
>>>
527527
>>> ack_deadline_seconds = 42
528-
>>> subscription = {'ack_deadline_seconds': ack_deadline_seconds}
528+
>>> subscription_name = 'projects/my-project/subscriptions/my-subscription'
529+
>>> subscription = {
530+
... 'name': subscription_name,
531+
... 'ack_deadline_seconds': ack_deadline_seconds,
532+
... }
529533
>>> paths_element = 'ack_deadline_seconds'
530534
>>> paths = [paths_element]
531535
>>> update_mask = {'paths': paths}
@@ -1493,7 +1497,11 @@ def update_snapshot(
14931497
>>>
14941498
>>> seconds = 123456
14951499
>>> expire_time = {'seconds': seconds}
1496-
>>> snapshot = {'expire_time': expire_time}
1500+
>>> snapshot_name = 'projects/my-project/snapshots/my-snapshot'
1501+
>>> snapshot = {
1502+
... 'name': snapshot_name,
1503+
... 'expire_time': expire_time,
1504+
... }
14971505
>>> paths_element = 'expire_time'
14981506
>>> paths = [paths_element]
14991507
>>> update_mask = {'paths': paths}

synth.py

+56
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
"""This script is used to synthesize generated parts of this library."""
1616

17+
import textwrap
18+
1719
import synthtool as s
1820
from synthtool import gcp
1921

@@ -183,6 +185,60 @@ def _merge_dict(d1, d2):
183185
"from google.iam.v1 import iam_policy_pb2_grpc as iam_policy_pb2",
184186
)
185187

188+
# Fix incomplete docstring examples.
189+
s.replace(
190+
"google/cloud/pubsub_v1/gapic/subscriber_client.py",
191+
r"\s+>>> subscription = \{'ack_deadline_seconds': ack_deadline_seconds\}",
192+
textwrap.indent(
193+
"""
194+
>>> subscription_name = 'projects/my-project/subscriptions/my-subscription'
195+
>>> subscription = {
196+
... 'name': subscription_name,
197+
... 'ack_deadline_seconds': ack_deadline_seconds,
198+
... }""",
199+
prefix=" " * 12,
200+
)
201+
)
202+
203+
s.replace(
204+
"google/cloud/pubsub_v1/gapic/subscriber_client.py",
205+
r"\s+>>> snapshot = \{'expire_time': expire_time\}",
206+
textwrap.indent(
207+
"""
208+
>>> snapshot_name = 'projects/my-project/snapshots/my-snapshot'
209+
>>> snapshot = {
210+
... 'name': snapshot_name,
211+
... 'expire_time': expire_time,
212+
... }""",
213+
prefix=" " * 12,
214+
)
215+
)
216+
217+
s.replace(
218+
"google/cloud/pubsub_v1/gapic/publisher_client.py",
219+
r"\s+>>> # TODO: Initialize `topic`:\n\s+>>> topic = \{\}\n",
220+
textwrap.indent(
221+
"""
222+
>>> topic_name = 'projects/my-project/topics/my-topic'
223+
>>> topic_labels = {'source': 'external'}
224+
>>> topic = {'name': topic_name, 'labels': topic_labels}
225+
""",
226+
prefix=" " * 12,
227+
),
228+
)
229+
230+
s.replace(
231+
"google/cloud/pubsub_v1/gapic/publisher_client.py",
232+
r"\s+>>> # TODO: Initialize `update_mask`:\n\s+>>> update_mask = \{\}\n",
233+
textwrap.indent(
234+
"""
235+
>>> paths_element = 'labels'
236+
>>> paths = [paths_element]
237+
>>> update_mask = {'paths': paths}
238+
""",
239+
prefix=" " * 12,
240+
),
241+
)
186242

187243
# ----------------------------------------------------------------------------
188244
# Add templated files

0 commit comments

Comments
 (0)