Skip to content

Commit

Permalink
docs: fix update subscription/snapshot/topic samples (googleapis#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
plamut authored Jun 6, 2020
1 parent 06085c4 commit e62c38b
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 6 deletions.
10 changes: 6 additions & 4 deletions google/cloud/pubsub_v1/gapic/publisher_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,13 @@ def update_topic(
>>>
>>> client = pubsub_v1.PublisherClient()
>>>
>>> # TODO: Initialize `topic`:
>>> topic = {}
>>> topic_name = 'projects/my-project/topics/my-topic'
>>> topic_labels = {'source': 'external'}
>>> topic = {'name': topic_name, 'labels': topic_labels}
>>>
>>> # TODO: Initialize `update_mask`:
>>> update_mask = {}
>>> paths_element = 'labels'
>>> paths = [paths_element]
>>> update_mask = {'paths': paths}
>>>
>>> response = client.update_topic(topic, update_mask)
Expand Down
12 changes: 10 additions & 2 deletions google/cloud/pubsub_v1/gapic/subscriber_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,11 @@ def update_subscription(
>>> client = pubsub_v1.SubscriberClient()
>>>
>>> ack_deadline_seconds = 42
>>> subscription = {'ack_deadline_seconds': ack_deadline_seconds}
>>> subscription_name = 'projects/my-project/subscriptions/my-subscription'
>>> subscription = {
... 'name': subscription_name,
... 'ack_deadline_seconds': ack_deadline_seconds,
... }
>>> paths_element = 'ack_deadline_seconds'
>>> paths = [paths_element]
>>> update_mask = {'paths': paths}
Expand Down Expand Up @@ -1493,7 +1497,11 @@ def update_snapshot(
>>>
>>> seconds = 123456
>>> expire_time = {'seconds': seconds}
>>> snapshot = {'expire_time': expire_time}
>>> snapshot_name = 'projects/my-project/snapshots/my-snapshot'
>>> snapshot = {
... 'name': snapshot_name,
... 'expire_time': expire_time,
... }
>>> paths_element = 'expire_time'
>>> paths = [paths_element]
>>> update_mask = {'paths': paths}
Expand Down
56 changes: 56 additions & 0 deletions synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

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

import textwrap

import synthtool as s
from synthtool import gcp

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

# Fix incomplete docstring examples.
s.replace(
"google/cloud/pubsub_v1/gapic/subscriber_client.py",
r"\s+>>> subscription = \{'ack_deadline_seconds': ack_deadline_seconds\}",
textwrap.indent(
"""
>>> subscription_name = 'projects/my-project/subscriptions/my-subscription'
>>> subscription = {
... 'name': subscription_name,
... 'ack_deadline_seconds': ack_deadline_seconds,
... }""",
prefix=" " * 12,
)
)

s.replace(
"google/cloud/pubsub_v1/gapic/subscriber_client.py",
r"\s+>>> snapshot = \{'expire_time': expire_time\}",
textwrap.indent(
"""
>>> snapshot_name = 'projects/my-project/snapshots/my-snapshot'
>>> snapshot = {
... 'name': snapshot_name,
... 'expire_time': expire_time,
... }""",
prefix=" " * 12,
)
)

s.replace(
"google/cloud/pubsub_v1/gapic/publisher_client.py",
r"\s+>>> # TODO: Initialize `topic`:\n\s+>>> topic = \{\}\n",
textwrap.indent(
"""
>>> topic_name = 'projects/my-project/topics/my-topic'
>>> topic_labels = {'source': 'external'}
>>> topic = {'name': topic_name, 'labels': topic_labels}
""",
prefix=" " * 12,
),
)

s.replace(
"google/cloud/pubsub_v1/gapic/publisher_client.py",
r"\s+>>> # TODO: Initialize `update_mask`:\n\s+>>> update_mask = \{\}\n",
textwrap.indent(
"""
>>> paths_element = 'labels'
>>> paths = [paths_element]
>>> update_mask = {'paths': paths}
""",
prefix=" " * 12,
),
)

# ----------------------------------------------------------------------------
# Add templated files
Expand Down

0 comments on commit e62c38b

Please sign in to comment.