From 69e144cdd4670900d6c832b8245ced4b5ac48b63 Mon Sep 17 00:00:00 2001 From: Peter Lamut Date: Fri, 5 Jun 2020 15:20:04 +0200 Subject: [PATCH 1/3] docs: fix update subscription/snapshot samples --- .../pubsub_v1/gapic/subscriber_client.py | 16 +++++++-- synth.py | 35 +++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/google/cloud/pubsub_v1/gapic/subscriber_client.py b/google/cloud/pubsub_v1/gapic/subscriber_client.py index e98a686bf..def46972e 100644 --- a/google/cloud/pubsub_v1/gapic/subscriber_client.py +++ b/google/cloud/pubsub_v1/gapic/subscriber_client.py @@ -525,7 +525,13 @@ 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' + >>> topic_name = 'projects/my-project/topics/my-topic' + >>> subscription = { + ... 'name': subscription_name, + ... 'topic': topic_name, + ... 'ack_deadline_seconds': ack_deadline_seconds, + ... } >>> paths_element = 'ack_deadline_seconds' >>> paths = [paths_element] >>> update_mask = {'paths': paths} @@ -1493,7 +1499,13 @@ def update_snapshot( >>> >>> seconds = 123456 >>> expire_time = {'seconds': seconds} - >>> snapshot = {'expire_time': expire_time} + >>> snapshot_name = 'projects/my-project/snapshots/my-snapshot' + >>> topic_name = 'projects/my-project/topics/my-topic' + >>> snapshot = { + ... 'name': snapshot_name, + ... 'topic': topic_name, + ... 'expire_time': expire_time, + ... } >>> paths_element = 'expire_time' >>> paths = [paths_element] >>> update_mask = {'paths': paths} diff --git a/synth.py b/synth.py index 645b7955b..7aef601a0 100644 --- a/synth.py +++ b/synth.py @@ -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 @@ -183,6 +185,39 @@ 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' +>>> topic_name = 'projects/my-project/topics/my-topic' +>>> subscription = { +... 'name': subscription_name, +... 'topic': topic_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' +>>> topic_name = 'projects/my-project/topics/my-topic' +>>> snapshot = { +... 'name': snapshot_name, +... 'topic': topic_name, +... 'expire_time': expire_time, +... }""", + prefix=" " * 12, + ) +) + # ---------------------------------------------------------------------------- # Add templated files From b160b813c2f06c05bd59161321b8f98ed22a3762 Mon Sep 17 00:00:00 2001 From: Peter Lamut Date: Sat, 6 Jun 2020 11:36:23 +0200 Subject: [PATCH 2/3] Drop unnecessary topic name from update samples --- google/cloud/pubsub_v1/gapic/subscriber_client.py | 4 ---- synth.py | 4 ---- 2 files changed, 8 deletions(-) diff --git a/google/cloud/pubsub_v1/gapic/subscriber_client.py b/google/cloud/pubsub_v1/gapic/subscriber_client.py index def46972e..502f11a7f 100644 --- a/google/cloud/pubsub_v1/gapic/subscriber_client.py +++ b/google/cloud/pubsub_v1/gapic/subscriber_client.py @@ -526,10 +526,8 @@ def update_subscription( >>> >>> ack_deadline_seconds = 42 >>> subscription_name = 'projects/my-project/subscriptions/my-subscription' - >>> topic_name = 'projects/my-project/topics/my-topic' >>> subscription = { ... 'name': subscription_name, - ... 'topic': topic_name, ... 'ack_deadline_seconds': ack_deadline_seconds, ... } >>> paths_element = 'ack_deadline_seconds' @@ -1500,10 +1498,8 @@ def update_snapshot( >>> seconds = 123456 >>> expire_time = {'seconds': seconds} >>> snapshot_name = 'projects/my-project/snapshots/my-snapshot' - >>> topic_name = 'projects/my-project/topics/my-topic' >>> snapshot = { ... 'name': snapshot_name, - ... 'topic': topic_name, ... 'expire_time': expire_time, ... } >>> paths_element = 'expire_time' diff --git a/synth.py b/synth.py index 7aef601a0..d38871216 100644 --- a/synth.py +++ b/synth.py @@ -192,10 +192,8 @@ def _merge_dict(d1, d2): textwrap.indent( """ >>> subscription_name = 'projects/my-project/subscriptions/my-subscription' ->>> topic_name = 'projects/my-project/topics/my-topic' >>> subscription = { ... 'name': subscription_name, -... 'topic': topic_name, ... 'ack_deadline_seconds': ack_deadline_seconds, ... }""", prefix=" " * 12, @@ -208,10 +206,8 @@ def _merge_dict(d1, d2): textwrap.indent( """ >>> snapshot_name = 'projects/my-project/snapshots/my-snapshot' ->>> topic_name = 'projects/my-project/topics/my-topic' >>> snapshot = { ... 'name': snapshot_name, -... 'topic': topic_name, ... 'expire_time': expire_time, ... }""", prefix=" " * 12, From 8694abc1c311c536724ef5ff71f16a40a9141e5b Mon Sep 17 00:00:00 2001 From: Peter Lamut Date: Sat, 6 Jun 2020 12:17:19 +0200 Subject: [PATCH 3/3] Complete update_topic sample in doscstring --- .../cloud/pubsub_v1/gapic/publisher_client.py | 10 +++++--- synth.py | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/google/cloud/pubsub_v1/gapic/publisher_client.py b/google/cloud/pubsub_v1/gapic/publisher_client.py index 1a981fefa..d59c247af 100644 --- a/google/cloud/pubsub_v1/gapic/publisher_client.py +++ b/google/cloud/pubsub_v1/gapic/publisher_client.py @@ -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) diff --git a/synth.py b/synth.py index d38871216..9e475e781 100644 --- a/synth.py +++ b/synth.py @@ -214,6 +214,31 @@ def _merge_dict(d1, d2): ) ) +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