From da0bf32f08b256a03270ee0447c4dd82151038c3 Mon Sep 17 00:00:00 2001 From: Peter Lamut Date: Thu, 20 Jun 2019 15:52:10 +0200 Subject: [PATCH 1/3] Make synth operations on PubSub types idempotent This commit assures that the code block for injecting FlowControl docs is not added on every synth tool run - it is only added if one does not exist yet. --- pubsub/google/cloud/pubsub_v1/types.py | 66 -------------------------- pubsub/synth.metadata | 10 ++-- pubsub/synth.py | 14 ++++++ 3 files changed, 19 insertions(+), 71 deletions(-) diff --git a/pubsub/google/cloud/pubsub_v1/types.py b/pubsub/google/cloud/pubsub_v1/types.py index 1b90bbb7dbbb..0e73ce6b5588 100644 --- a/pubsub/google/cloud/pubsub_v1/types.py +++ b/pubsub/google/cloud/pubsub_v1/types.py @@ -104,72 +104,6 @@ ) -if sys.version_info >= (3, 5): - FlowControl.__doc__ = ( - "The settings for controlling the rate at which messages are pulled " - "with an asynchronous subscription." - ) - FlowControl.max_bytes.__doc__ = ( - "The maximum total size of received - but not yet processed - messages " - "before pausing the message stream." - ) - FlowControl.max_messages.__doc__ = ( - "The maximum number of received - but not yet processed - messages before " - "pausing the message stream." - ) - FlowControl.resume_threshold.__doc__ = ( - "The relative threshold of the ``max_bytes`` and ``max_messages`` limits " - "below which to resume the message stream. Must be a positive number not " - "greater than ``1.0``." - ) - FlowControl.max_requests.__doc__ = "Currently not in use." - FlowControl.max_request_batch_size.__doc__ = ( - "The maximum number of requests scheduled by callbacks to process and " - "dispatch at a time." - ) - FlowControl.max_request_batch_latency.__doc__ = ( - "The maximum amount of time in seconds to wait for additional request " - "items before processing the next batch of requests." - ) - FlowControl.max_lease_duration.__doc__ = ( - "The maximum amount of time in seconds to hold a lease on a message " - "before dropping it from the lease management." - ) - - -if sys.version_info >= (3, 5): - FlowControl.__doc__ = ( - "The settings for controlling the rate at which messages are pulled " - "with an asynchronous subscription." - ) - FlowControl.max_bytes.__doc__ = ( - "The maximum total size of received - but not yet processed - messages " - "before pausing the message stream." - ) - FlowControl.max_messages.__doc__ = ( - "The maximum number of received - but not yet processed - messages before " - "pausing the message stream." - ) - FlowControl.resume_threshold.__doc__ = ( - "The relative threshold of the ``max_bytes`` and ``max_messages`` limits " - "below which to resume the message stream. Must be a positive number not " - "greater than ``1.0``." - ) - FlowControl.max_requests.__doc__ = "Currently not in use." - FlowControl.max_request_batch_size.__doc__ = ( - "The maximum number of requests scheduled by callbacks to process and " - "dispatch at a time." - ) - FlowControl.max_request_batch_latency.__doc__ = ( - "The maximum amount of time in seconds to wait for additional request " - "items before processing the next batch of requests." - ) - FlowControl.max_lease_duration.__doc__ = ( - "The maximum amount of time in seconds to hold a lease on a message " - "before dropping it from the lease management." - ) - - _shared_modules = [ http_pb2, iam_policy_pb2, diff --git a/pubsub/synth.metadata b/pubsub/synth.metadata index 3838907bf04b..eaa99c8f3fb3 100644 --- a/pubsub/synth.metadata +++ b/pubsub/synth.metadata @@ -1,19 +1,19 @@ { - "updateTime": "2019-06-19T12:19:44.898368Z", + "updateTime": "2019-06-20T13:51:18.842985Z", "sources": [ { "generator": { "name": "artman", - "version": "0.28.0", - "dockerImage": "googleapis/artman@sha256:6ced5a36b08b82a328c69844e629300d58c14067f25cadab47f52542bdef7daf" + "version": "0.29.0", + "dockerImage": "googleapis/artman@sha256:b79c8c20ee51e5302686c9d1294672d59290df1489be93749ef17d0172cc508d" } }, { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "ac13167e31a20314aa05cc9911c95df250880485", - "internalRef": "253867808" + "sha": "45e125f9e30dc5d45b52752b3ab78dd4f6084f2d", + "internalRef": "254026509" } }, { diff --git a/pubsub/synth.py b/pubsub/synth.py index e9a54a5da10a..c4ce8c90e18c 100644 --- a/pubsub/synth.py +++ b/pubsub/synth.py @@ -168,6 +168,20 @@ def _merge_dict(d1, d2): ) # document FlowControl settings in Python 3.5+ + +# ... first remove any existing code that injects the docs +s.replace( + "google/cloud/pubsub_v1/types.py", + r"if sys\.version_info >= \(3, 5\):", + "", +) +s.replace( + "google/cloud/pubsub_v1/types.py", + r" FlowControl\..*?__doc__ = \(.*?\)", + "", + flags=re.DOTALL, +) + s.replace( "google/cloud/pubsub_v1/types.py", "FlowControl.__new__.__defaults__ = \(.*?\)", From 2d91a314497b41440bd1ac645d0278cc45f502b4 Mon Sep 17 00:00:00 2001 From: Peter Lamut Date: Thu, 20 Jun 2019 16:47:53 +0200 Subject: [PATCH 2/3] Document PubSub BatchSettings --- pubsub/google/cloud/pubsub_v1/types.py | 16 ++++++++++++ pubsub/synth.metadata | 2 +- pubsub/synth.py | 35 ++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/pubsub/google/cloud/pubsub_v1/types.py b/pubsub/google/cloud/pubsub_v1/types.py index 0e73ce6b5588..58b880fb125b 100644 --- a/pubsub/google/cloud/pubsub_v1/types.py +++ b/pubsub/google/cloud/pubsub_v1/types.py @@ -44,6 +44,22 @@ 1000, # max_messages: 1,000 ) +if sys.version_info >= (3, 5): + BatchSettings.__doc__ = "The settings for batch publishing the messages." + BatchSettings.max_bytes.__doc__ = ( + "The maximum total size of the messages to collect before automatically " + "publishing the batch." + ) + BatchSettings.max_latency.__doc__ = ( + "The maximum number of seconds to wait for additional messages before " + "automatically publishing the batch." + ) + BatchSettings.max_messages.__doc__ = ( + "The maximum number of messages to collect before automatically " + "publishing the batch." + ) + + # Define the type class and default values for flow control settings. # # This class is used when creating a publisher or subscriber client, and diff --git a/pubsub/synth.metadata b/pubsub/synth.metadata index eaa99c8f3fb3..c35ff66c366b 100644 --- a/pubsub/synth.metadata +++ b/pubsub/synth.metadata @@ -1,5 +1,5 @@ { - "updateTime": "2019-06-20T13:51:18.842985Z", + "updateTime": "2019-06-20T14:57:43.972940Z", "sources": [ { "generator": { diff --git a/pubsub/synth.py b/pubsub/synth.py index c4ce8c90e18c..1f4bce22a195 100644 --- a/pubsub/synth.py +++ b/pubsub/synth.py @@ -223,6 +223,41 @@ def _merge_dict(d1, d2): flags=re.DOTALL, ) +# document BatchSettings in Python 3.5+ + +# ... first make sure to remove any existing code that injects the docs +# (the "if sys version" line is removed by the block above) +s.replace( + "google/cloud/pubsub_v1/types.py", + r" BatchSettings\..*?__doc__ = \(.*?\)", + "", + flags=re.DOTALL, +) + +s.replace( + "google/cloud/pubsub_v1/types.py", + r"BatchSettings\.__new__\.__defaults__ = \(.*?\)", + textwrap.dedent("""\ + \g<0> + + if sys.version_info >= (3, 5): + BatchSettings.__doc__ = "The settings for batch publishing the messages." + BatchSettings.max_bytes.__doc__ = ( + "The maximum total size of the messages to collect before automatically " + "publishing the batch." + ) + BatchSettings.max_latency.__doc__ = ( + "The maximum number of seconds to wait for additional messages before " + "automatically publishing the batch." + ) + BatchSettings.max_messages.__doc__ = ( + "The maximum number of messages to collect before automatically " + "publishing the batch." + ) + """), + flags=re.DOTALL, +) + # ---------------------------------------------------------------------------- # Add templated files # ---------------------------------------------------------------------------- From 2f5f412e2776cbc666fe165ea53e9adad89f98b5 Mon Sep 17 00:00:00 2001 From: Peter Lamut Date: Thu, 20 Jun 2019 18:24:45 +0200 Subject: [PATCH 3/3] Document PubSub types directly (i.e. w/o synth) --- pubsub/synth.metadata | 2 +- pubsub/synth.py | 91 ------------------------------------------- 2 files changed, 1 insertion(+), 92 deletions(-) diff --git a/pubsub/synth.metadata b/pubsub/synth.metadata index c35ff66c366b..0f3f84587b5a 100644 --- a/pubsub/synth.metadata +++ b/pubsub/synth.metadata @@ -1,5 +1,5 @@ { - "updateTime": "2019-06-20T14:57:43.972940Z", + "updateTime": "2019-06-20T16:24:11.087131Z", "sources": [ { "generator": { diff --git a/pubsub/synth.py b/pubsub/synth.py index 1f4bce22a195..f95da65ede0c 100644 --- a/pubsub/synth.py +++ b/pubsub/synth.py @@ -167,97 +167,6 @@ def _merge_dict(d1, d2): """ ) -# document FlowControl settings in Python 3.5+ - -# ... first remove any existing code that injects the docs -s.replace( - "google/cloud/pubsub_v1/types.py", - r"if sys\.version_info >= \(3, 5\):", - "", -) -s.replace( - "google/cloud/pubsub_v1/types.py", - r" FlowControl\..*?__doc__ = \(.*?\)", - "", - flags=re.DOTALL, -) - -s.replace( - "google/cloud/pubsub_v1/types.py", - "FlowControl.__new__.__defaults__ = \(.*?\)", - textwrap.dedent("""\ - \g<0> - - if sys.version_info >= (3, 5): - FlowControl.__doc__ = ( - "The settings for controlling the rate at which messages are pulled " - "with an asynchronous subscription." - ) - FlowControl.max_bytes.__doc__ = ( - "The maximum total size of received - but not yet processed - messages " - "before pausing the message stream." - ) - FlowControl.max_messages.__doc__ = ( - "The maximum number of received - but not yet processed - messages before " - "pausing the message stream." - ) - FlowControl.resume_threshold.__doc__ = ( - "The relative threshold of the ``max_bytes`` and ``max_messages`` limits " - "below which to resume the message stream. Must be a positive number not " - "greater than ``1.0``." - ) - FlowControl.max_requests.__doc__ = "Currently not in use." - FlowControl.max_request_batch_size.__doc__ = ( - "The maximum number of requests scheduled by callbacks to process and " - "dispatch at a time." - ) - FlowControl.max_request_batch_latency.__doc__ = ( - "The maximum amount of time in seconds to wait for additional request " - "items before processing the next batch of requests." - ) - FlowControl.max_lease_duration.__doc__ = ( - "The maximum amount of time in seconds to hold a lease on a message " - "before dropping it from the lease management." - ) - """), - flags=re.DOTALL, -) - -# document BatchSettings in Python 3.5+ - -# ... first make sure to remove any existing code that injects the docs -# (the "if sys version" line is removed by the block above) -s.replace( - "google/cloud/pubsub_v1/types.py", - r" BatchSettings\..*?__doc__ = \(.*?\)", - "", - flags=re.DOTALL, -) - -s.replace( - "google/cloud/pubsub_v1/types.py", - r"BatchSettings\.__new__\.__defaults__ = \(.*?\)", - textwrap.dedent("""\ - \g<0> - - if sys.version_info >= (3, 5): - BatchSettings.__doc__ = "The settings for batch publishing the messages." - BatchSettings.max_bytes.__doc__ = ( - "The maximum total size of the messages to collect before automatically " - "publishing the batch." - ) - BatchSettings.max_latency.__doc__ = ( - "The maximum number of seconds to wait for additional messages before " - "automatically publishing the batch." - ) - BatchSettings.max_messages.__doc__ = ( - "The maximum number of messages to collect before automatically " - "publishing the batch." - ) - """), - flags=re.DOTALL, -) - # ---------------------------------------------------------------------------- # Add templated files # ----------------------------------------------------------------------------