Skip to content

Commit 27b7b3f

Browse files
chore(python): use black==22.3.0 (googleapis#627)
Source-Link: googleapis/synthtool@6fab84a Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:7cffbc10910c3ab1b852c05114a08d374c195a81cdec1d4a67a1d129331d0bfe Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 9b996c6 commit 27b7b3f

36 files changed

Lines changed: 3618 additions & 1119 deletions

.github/.OwlBot.lock.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# limitations under the License.
1414
docker:
1515
image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest
16-
digest: sha256:4e1991042fe54b991db9ca17c8fb386e61b22fe4d1472a568bf0fcac85dcf5d3
16+
digest: sha256:7cffbc10910c3ab1b852c05114a08d374c195a81cdec1d4a67a1d129331d0bfe

docs/conf.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,13 @@
314314
# One entry per manual page. List of tuples
315315
# (source start file, name, description, authors, manual section).
316316
man_pages = [
317-
(root_doc, "google-cloud-pubsub", "google-cloud-pubsub Documentation", [author], 1,)
317+
(
318+
root_doc,
319+
"google-cloud-pubsub",
320+
"google-cloud-pubsub Documentation",
321+
[author],
322+
1,
323+
)
318324
]
319325

320326
# If true, show URL addresses after external links.
@@ -355,7 +361,10 @@
355361
intersphinx_mapping = {
356362
"python": ("https://python.readthedocs.org/en/latest/", None),
357363
"google-auth": ("https://googleapis.dev/python/google-auth/latest/", None),
358-
"google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None,),
364+
"google.api_core": (
365+
"https://googleapis.dev/python/google-api-core/latest/",
366+
None,
367+
),
359368
"grpc": ("https://grpc.github.io/grpc/python/", None),
360369
"proto-plus": ("https://proto-plus-python.readthedocs.io/en/latest/", None),
361370
"protobuf": ("https://googleapis.dev/python/protobuf/latest/", None),

google/cloud/pubsub_v1/publisher/_sequencer/base.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@
2727

2828
class Sequencer(metaclass=abc.ABCMeta):
2929
"""The base class for sequencers for Pub/Sub publishing. A sequencer
30-
sequences messages to be published.
30+
sequences messages to be published.
3131
"""
3232

3333
@abc.abstractmethod
3434
def is_finished(self) -> bool: # pragma: NO COVER
35-
""" Whether the sequencer is finished and should be cleaned up.
35+
"""Whether the sequencer is finished and should be cleaned up.
3636
37-
Returns:
38-
bool: Whether the sequencer is finished and should be cleaned up.
37+
Returns:
38+
bool: Whether the sequencer is finished and should be cleaned up.
3939
"""
4040
raise NotImplementedError
4141

4242
@abc.abstractmethod
4343
def unpause(self) -> None: # pragma: NO COVER
44-
""" Unpauses this sequencer.
44+
"""Unpauses this sequencer.
4545
4646
Raises:
4747
RuntimeError:
@@ -56,7 +56,7 @@ def publish(
5656
retry: "OptionalRetry" = gapic_v1.method.DEFAULT,
5757
timeout: gapic_types.TimeoutType = gapic_v1.method.DEFAULT,
5858
) -> "futures.Future": # pragma: NO COVER
59-
""" Publish message for this ordering key.
59+
"""Publish message for this ordering key.
6060
6161
Args:
6262
message:

google/cloud/pubsub_v1/publisher/_sequencer/ordered_sequencer.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,21 @@ class _OrderedSequencerStatus(str, enum.Enum):
7676

7777

7878
class OrderedSequencer(sequencer_base.Sequencer):
79-
""" Sequences messages into batches ordered by an ordering key for one topic.
79+
"""Sequences messages into batches ordered by an ordering key for one topic.
8080
81-
A sequencer always has at least one batch in it, unless paused or stopped.
82-
When no batches remain, the |publishes_done_callback| is called so the
83-
client can perform cleanup.
81+
A sequencer always has at least one batch in it, unless paused or stopped.
82+
When no batches remain, the |publishes_done_callback| is called so the
83+
client can perform cleanup.
8484
85-
Public methods are thread-safe.
85+
Public methods are thread-safe.
8686
87-
Args:
88-
client:
89-
The publisher client used to create this sequencer.
90-
topic:
91-
The topic. The format for this is ``projects/{project}/topics/{topic}``.
92-
ordering_key:
93-
The ordering key for this sequencer.
87+
Args:
88+
client:
89+
The publisher client used to create this sequencer.
90+
topic:
91+
The topic. The format for this is ``projects/{project}/topics/{topic}``.
92+
ordering_key:
93+
The ordering key for this sequencer.
9494
"""
9595

9696
def __init__(self, client: "PublisherClient", topic: str, ordering_key: str):
@@ -107,23 +107,23 @@ def __init__(self, client: "PublisherClient", topic: str, ordering_key: str):
107107
self._state = _OrderedSequencerStatus.ACCEPTING_MESSAGES
108108

109109
def is_finished(self) -> bool:
110-
""" Whether the sequencer is finished and should be cleaned up.
110+
"""Whether the sequencer is finished and should be cleaned up.
111111
112-
Returns:
113-
Whether the sequencer is finished and should be cleaned up.
112+
Returns:
113+
Whether the sequencer is finished and should be cleaned up.
114114
"""
115115
with self._state_lock:
116116
return self._state == _OrderedSequencerStatus.FINISHED
117117

118118
def stop(self) -> None:
119-
""" Permanently stop this sequencer.
119+
"""Permanently stop this sequencer.
120120
121-
This differs from pausing, which may be resumed. Immediately commits
122-
the first batch and cancels the rest.
121+
This differs from pausing, which may be resumed. Immediately commits
122+
the first batch and cancels the rest.
123123
124-
Raises:
125-
RuntimeError:
126-
If called after stop() has already been called.
124+
Raises:
125+
RuntimeError:
126+
If called after stop() has already been called.
127127
"""
128128
with self._state_lock:
129129
if self._state == _OrderedSequencerStatus.STOPPED:
@@ -143,13 +143,13 @@ def stop(self) -> None:
143143
batch.cancel(batch_base.BatchCancellationReason.CLIENT_STOPPED)
144144

145145
def commit(self) -> None:
146-
""" Commit the first batch, if unpaused.
146+
"""Commit the first batch, if unpaused.
147147
148-
If paused or no batches exist, this method does nothing.
148+
If paused or no batches exist, this method does nothing.
149149
150-
Raises:
151-
RuntimeError:
152-
If called after stop() has already been called.
150+
Raises:
151+
RuntimeError:
152+
If called after stop() has already been called.
153153
"""
154154
with self._state_lock:
155155
if self._state == _OrderedSequencerStatus.STOPPED:
@@ -161,11 +161,11 @@ def commit(self) -> None:
161161
self._ordered_batches[0].commit()
162162

163163
def _batch_done_callback(self, success: bool) -> None:
164-
""" Deal with completion of a batch.
164+
"""Deal with completion of a batch.
165165
166-
Called when a batch has finished publishing, with either a success
167-
or a failure. (Temporary failures are retried infinitely when
168-
ordering keys are enabled.)
166+
Called when a batch has finished publishing, with either a success
167+
or a failure. (Temporary failures are retried infinitely when
168+
ordering keys are enabled.)
169169
"""
170170
ensure_cleanup_and_commit_timer_runs = False
171171
with self._state_lock:
@@ -209,10 +209,10 @@ def _batch_done_callback(self, success: bool) -> None:
209209
self._client.ensure_cleanup_and_commit_timer_runs()
210210

211211
def _pause(self) -> None:
212-
""" Pause this sequencer: set state to paused, cancel all batches, and
213-
clear the list of ordered batches.
212+
"""Pause this sequencer: set state to paused, cancel all batches, and
213+
clear the list of ordered batches.
214214
215-
_state_lock must be taken before calling this method.
215+
_state_lock must be taken before calling this method.
216216
"""
217217
assert (
218218
self._state != _OrderedSequencerStatus.FINISHED
@@ -225,7 +225,7 @@ def _pause(self) -> None:
225225
self._ordered_batches.clear()
226226

227227
def unpause(self) -> None:
228-
""" Unpause this sequencer.
228+
"""Unpause this sequencer.
229229
230230
Raises:
231231
RuntimeError:
@@ -241,7 +241,7 @@ def _create_batch(
241241
commit_retry: "OptionalRetry" = gapic_v1.method.DEFAULT,
242242
commit_timeout: "types.OptionalTimeout" = gapic_v1.method.DEFAULT,
243243
) -> "_batch.thread.Batch":
244-
""" Create a new batch using the client's batch class and other stored
244+
"""Create a new batch using the client's batch class and other stored
245245
settings.
246246
247247
Args:
@@ -266,7 +266,7 @@ def publish(
266266
retry: "OptionalRetry" = gapic_v1.method.DEFAULT,
267267
timeout: "types.OptionalTimeout" = gapic_v1.method.DEFAULT,
268268
) -> futures.Future:
269-
""" Publish message for this ordering key.
269+
"""Publish message for this ordering key.
270270
271271
Args:
272272
message:

google/cloud/pubsub_v1/publisher/_sequencer/unordered_sequencer.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030

3131

3232
class UnorderedSequencer(base.Sequencer):
33-
""" Sequences messages into batches for one topic without any ordering.
33+
"""Sequences messages into batches for one topic without any ordering.
3434
35-
Public methods are NOT thread-safe.
35+
Public methods are NOT thread-safe.
3636
"""
3737

3838
def __init__(self, client: "PublisherClient", topic: str):
@@ -42,10 +42,10 @@ def __init__(self, client: "PublisherClient", topic: str):
4242
self._stopped = False
4343

4444
def is_finished(self) -> bool:
45-
""" Whether the sequencer is finished and should be cleaned up.
45+
"""Whether the sequencer is finished and should be cleaned up.
4646
47-
Returns:
48-
Whether the sequencer is finished and should be cleaned up.
47+
Returns:
48+
Whether the sequencer is finished and should be cleaned up.
4949
"""
5050
# TODO: Implement. Not implementing yet because of possible performance
5151
# impact due to extra locking required. This does mean that
@@ -54,25 +54,25 @@ def is_finished(self) -> bool:
5454
return False
5555

5656
def stop(self) -> None:
57-
""" Stop the sequencer.
57+
"""Stop the sequencer.
5858
59-
Subsequent publishes will fail.
59+
Subsequent publishes will fail.
6060
61-
Raises:
62-
RuntimeError:
63-
If called after stop() has already been called.
61+
Raises:
62+
RuntimeError:
63+
If called after stop() has already been called.
6464
"""
6565
if self._stopped:
6666
raise RuntimeError("Unordered sequencer already stopped.")
6767
self.commit()
6868
self._stopped = True
6969

7070
def commit(self) -> None:
71-
""" Commit the batch.
71+
"""Commit the batch.
7272
73-
Raises:
74-
RuntimeError:
75-
If called after stop() has already been called.
73+
Raises:
74+
RuntimeError:
75+
If called after stop() has already been called.
7676
"""
7777
if self._stopped:
7878
raise RuntimeError("Unordered sequencer already stopped.")
@@ -86,15 +86,15 @@ def commit(self) -> None:
8686
self._current_batch = None
8787

8888
def unpause(self) -> typing.NoReturn:
89-
""" Not relevant for this class. """
89+
"""Not relevant for this class."""
9090
raise NotImplementedError
9191

9292
def _create_batch(
9393
self,
9494
commit_retry: "OptionalRetry" = gapic_v1.method.DEFAULT,
9595
commit_timeout: "types.OptionalTimeout" = gapic_v1.method.DEFAULT,
9696
) -> "_batch.thread.Batch":
97-
""" Create a new batch using the client's batch class and other stored
97+
"""Create a new batch using the client's batch class and other stored
9898
settings.
9999
100100
Args:
@@ -119,7 +119,7 @@ def publish(
119119
retry: "OptionalRetry" = gapic_v1.method.DEFAULT,
120120
timeout: "types.OptionalTimeout" = gapic_v1.method.DEFAULT,
121121
) -> "futures.Future":
122-
""" Batch message into existing or new batch.
122+
"""Batch message into existing or new batch.
123123
124124
Args:
125125
message:

google/cloud/pubsub_v1/publisher/client.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ def api(self):
215215
return super()
216216

217217
def _get_or_create_sequencer(self, topic: str, ordering_key: str) -> SequencerType:
218-
""" Get an existing sequencer or create a new one given the (topic,
219-
ordering_key) pair.
218+
"""Get an existing sequencer or create a new one given the (topic,
219+
ordering_key) pair.
220220
"""
221221
sequencer_key = (topic, ordering_key)
222222
sequencer = self._sequencers.get(sequencer_key)
@@ -232,7 +232,7 @@ def _get_or_create_sequencer(self, topic: str, ordering_key: str) -> SequencerTy
232232
return sequencer
233233

234234
def resume_publish(self, topic: str, ordering_key: str) -> None:
235-
""" Resume publish on an ordering key that has had unrecoverable errors.
235+
"""Resume publish on an ordering key that has had unrecoverable errors.
236236
237237
Args:
238238
topic: The topic to publish messages to.
@@ -403,9 +403,9 @@ def on_publish_done(future):
403403
# use the default retry for the publish GRPC method as a base
404404
transport = self._transport
405405
base_retry = transport._wrapped_methods[transport.publish]._retry
406-
retry = base_retry.with_deadline(2.0 ** 32)
406+
retry = base_retry.with_deadline(2.0**32)
407407
else:
408-
retry = retry.with_deadline(2.0 ** 32)
408+
retry = retry.with_deadline(2.0**32)
409409

410410
# Delegate the publishing to the sequencer.
411411
sequencer = self._get_or_create_sequencer(topic, ordering_key)
@@ -419,18 +419,18 @@ def on_publish_done(future):
419419
return future
420420

421421
def ensure_cleanup_and_commit_timer_runs(self) -> None:
422-
""" Ensure a cleanup/commit timer thread is running.
422+
"""Ensure a cleanup/commit timer thread is running.
423423
424-
If a cleanup/commit timer thread is already running, this does nothing.
424+
If a cleanup/commit timer thread is already running, this does nothing.
425425
"""
426426
with self._batch_lock:
427427
self._ensure_commit_timer_runs_no_lock()
428428

429429
def _ensure_commit_timer_runs_no_lock(self) -> None:
430-
""" Ensure a commit timer thread is running, without taking
431-
_batch_lock.
430+
"""Ensure a commit timer thread is running, without taking
431+
_batch_lock.
432432
433-
_batch_lock must be held before calling this method.
433+
_batch_lock must be held before calling this method.
434434
"""
435435
if not self._commit_thread and self.batch_settings.max_latency < float("inf"):
436436
self._start_commit_thread()
@@ -448,8 +448,7 @@ def _start_commit_thread(self) -> None:
448448
self._commit_thread.start()
449449

450450
def _wait_and_commit_sequencers(self) -> None:
451-
""" Wait up to the batching timeout, and commit all sequencers.
452-
"""
451+
"""Wait up to the batching timeout, and commit all sequencers."""
453452
# Sleep for however long we should be waiting.
454453
time.sleep(self.batch_settings.max_latency)
455454
_LOGGER.debug("Commit thread is waking up")
@@ -461,7 +460,7 @@ def _wait_and_commit_sequencers(self) -> None:
461460
self._commit_thread = None
462461

463462
def _commit_sequencers(self) -> None:
464-
""" Clean up finished sequencers and commit the rest. """
463+
"""Clean up finished sequencers and commit the rest."""
465464
finished_sequencer_keys = [
466465
key
467466
for key, sequencer in self._sequencers.items()

google/cloud/pubsub_v1/publisher/exceptions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ class MessageTooLargeError(ValueError):
2727

2828

2929
class PublishToPausedOrderingKeyException(Exception):
30-
""" Publish attempted to paused ordering key. To resume publishing, call
31-
the resumePublish method on the publisher Client object with this
32-
ordering key. Ordering keys are paused if an unrecoverable error
33-
occurred during publish of a batch for that key.
30+
"""Publish attempted to paused ordering key. To resume publishing, call
31+
the resumePublish method on the publisher Client object with this
32+
ordering key. Ordering keys are paused if an unrecoverable error
33+
occurred during publish of a batch for that key.
3434
"""
3535

3636
def __init__(self, ordering_key: str):

0 commit comments

Comments
 (0)