Skip to content
This repository was archived by the owner on Mar 9, 2026. It is now read-only.

Commit 23eea83

Browse files
committed
Move replacement rules to correct place + blacken
1 parent a0411ff commit 23eea83

File tree

1 file changed

+104
-106
lines changed

1 file changed

+104
-106
lines changed

owlbot.py

Lines changed: 104 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,20 @@
2727

2828
for library in s.get_staging_dirs(default_version):
2929
# Work around gapic generator bug https://github.com/googleapis/gapic-generator-python/issues/902
30-
s.replace(library / f"google/pubsub_{library.name}/types/*.py",
31-
r""".
30+
s.replace(
31+
library / f"google/pubsub_{library.name}/types/*.py",
32+
r""".
3233
Attributes:""",
33-
r""".\n
34+
r""".\n
3435
Attributes:""",
3536
)
3637

3738
# Work around gapic generator bug https://github.com/googleapis/gapic-generator-python/issues/902
38-
s.replace(library / f"google/pubsub_{library.name}/types/*.py",
39-
r""".
39+
s.replace(
40+
library / f"google/pubsub_{library.name}/types/*.py",
41+
r""".
4042
Attributes:""",
41-
r""".\n
43+
r""".\n
4244
Attributes:""",
4345
)
4446

@@ -63,8 +65,8 @@
6365
# Modify GRPC options in transports.
6466
count = s.replace(
6567
[
66-
library / f"google/pubsub_{library.name}/services/*/transports/grpc*",
67-
library / f"tests/unit/gapic/pubsub_{library.name}/*"
68+
library / f"google/pubsub_{library.name}/services/*/transports/grpc*",
69+
library / f"tests/unit/gapic/pubsub_{library.name}/*",
6870
],
6971
"options=\[.*?\]",
7072
"""options=[
@@ -83,21 +85,19 @@
8385
library / f"google/pubsub_{library.name}/services/publisher/client.py",
8486
library / f"google/pubsub_{library.name}/services/subscriber/client.py",
8587
]
86-
err_msg = "Expected replacements for gRPC channel to use with the emulator not made."
87-
88-
count = s.replace(
89-
clients_to_patch,
90-
r"import os",
91-
"import functools\n\g<0>"
88+
err_msg = (
89+
"Expected replacements for gRPC channel to use with the emulator not made."
9290
)
9391

92+
count = s.replace(clients_to_patch, r"import os", "import functools\n\g<0>")
93+
9494
if count < len(clients_to_patch):
9595
raise Exception(err_msg)
9696

9797
count = s.replace(
9898
clients_to_patch,
9999
f"from google\.pubsub_{library.name}\.types import pubsub",
100-
"\g<0>\n\nimport grpc"
100+
"\g<0>\n\nimport grpc",
101101
)
102102

103103
if count < len(clients_to_patch):
@@ -154,15 +154,16 @@
154154
((?P<indent>[^\n\S]+)\#\ Wrap\ the\ RPC\ method)
155155
""",
156156
textwrap.dedent(
157-
"""
157+
"""
158158
\g<1>
159159
\g<indent>if request.return_immediately:
160160
\g<indent> warnings.warn(
161161
\g<indent> "The return_immediately flag is deprecated and should be set to False.",
162162
\g<indent> category=DeprecationWarning,
163163
\g<indent> )
164164
165-
\g<2>"""),
165+
\g<2>"""
166+
),
166167
flags=re.MULTILINE | re.DOTALL | re.VERBOSE,
167168
)
168169

@@ -179,7 +180,7 @@
179180
count = s.replace(
180181
library / f"tests/unit/gapic/pubsub_{library.name}/test_subscriber.py",
181182
textwrap.dedent(
182-
r"""
183+
r"""
183184
([^\n\S]+# Call the method with a truthy value for each flattened field,
184185
[^\n\S]+# using the keyword arguments to the method\.)
185186
\s+(client\.pull\(.*?\))"""
@@ -188,7 +189,7 @@
188189
with warnings.catch_warnings():
189190
warnings.simplefilter("ignore", category=DeprecationWarning)
190191
\g<2>""",
191-
flags = re.MULTILINE | re.DOTALL,
192+
flags=re.MULTILINE | re.DOTALL,
192193
)
193194

194195
if count < 1:
@@ -206,7 +207,7 @@
206207
with warnings.catch_warnings():
207208
warnings.simplefilter("ignore", category=DeprecationWarning)
208209
\g<2>""",
209-
flags = re.MULTILINE | re.DOTALL,
210+
flags=re.MULTILINE | re.DOTALL,
210211
)
211212

212213
if count < 1:
@@ -215,23 +216,33 @@
215216
# Make sure that client library version is present in user agent header.
216217
s.replace(
217218
[
218-
library / f"google/pubsub_{library.name}/services/publisher/async_client.py",
219+
library
220+
/ f"google/pubsub_{library.name}/services/publisher/async_client.py",
219221
library / f"google/pubsub_{library.name}/services/publisher/client.py",
220-
library / f"google/pubsub_{library.name}/services/publisher/transports/base.py",
221-
library / f"google/pubsub_{library.name}/services/schema_service/async_client.py",
222+
library
223+
/ f"google/pubsub_{library.name}/services/publisher/transports/base.py",
224+
library
225+
/ f"google/pubsub_{library.name}/services/schema_service/async_client.py",
222226
library / f"google/pubsub_{library.name}/services/schema_service/client.py",
223-
library / f"google/pubsub_{library.name}/services/schema_service/transports/base.py",
224-
library / f"google/pubsub_{library.name}/services/subscriber/async_client.py",
227+
library
228+
/ f"google/pubsub_{library.name}/services/schema_service/transports/base.py",
229+
library
230+
/ f"google/pubsub_{library.name}/services/subscriber/async_client.py",
225231
library / f"google/pubsub_{library.name}/services/subscriber/client.py",
226-
library / f"google/pubsub_{library.name}/services/subscriber/transports/base.py",
232+
library
233+
/ f"google/pubsub_{library.name}/services/subscriber/transports/base.py",
227234
],
228235
r"""gapic_version=(pkg_resources\.get_distribution\(\s+)['"]google-pubsub['"]""",
229236
"client_library_version=\g<1>'google-cloud-pubsub'",
230237
)
231238

232239
# Docstrings of *_iam_policy() methods are formatted poorly and must be fixed
233240
# in order to avoid docstring format warnings in docs.
234-
s.replace(library / f"google/pubsub_{library.name}/services/*er/client.py", r"(\s+)Args:", "\n\g<1>Args:")
241+
s.replace(
242+
library / f"google/pubsub_{library.name}/services/*er/client.py",
243+
r"(\s+)Args:",
244+
"\n\g<1>Args:",
245+
)
235246
s.replace(
236247
library / f"google/pubsub_{library.name}/services/*er/client.py",
237248
r"(\s+)\*\*JSON Example\*\*\s+::",
@@ -254,13 +265,14 @@
254265
s.replace(
255266
library / f"google/pubsub_{library.name}/types/__init__.py",
256267
r"from \.pubsub import \(",
257-
"from typing import Union\n\n\g<0>"
268+
"from typing import Union\n\n\g<0>",
258269
)
259270

260271
s.replace(
261272
library / f"google/pubsub_{library.name}/types/__init__.py",
262273
r"__all__ = \(\n",
263-
textwrap.dedent('''\
274+
textwrap.dedent(
275+
'''\
264276
TimeoutType = Union[
265277
int,
266278
float,
@@ -269,13 +281,14 @@
269281
]
270282
"""The type of the timeout parameter of publisher client methods."""
271283
272-
\g<0> "TimeoutType",''')
284+
\g<0> "TimeoutType",'''
285+
),
273286
)
274287

275288
s.replace(
276289
library / f"google/pubsub_{library.name}/services/publisher/*client.py",
277290
r"from google.api_core import retry as retries.*\n",
278-
"\g<0>from google.api_core import timeout as timeouts # type: ignore\n"
291+
"\g<0>from google.api_core import timeout as timeouts # type: ignore\n",
279292
)
280293

281294
s.replace(
@@ -293,10 +306,7 @@
293306
s.replace(
294307
library / f"google/pubsub_{library.name}/services/publisher/*client.py",
295308
r"([^\S\r\n]+)timeout \(float\): (.*)\n",
296-
(
297-
"\g<1>timeout (TimeoutType):\n"
298-
"\g<1> \g<2>\n"
299-
),
309+
("\g<1>timeout (TimeoutType):\n" "\g<1> \g<2>\n"),
300310
)
301311

302312
# The namespace package declaration in google/cloud/__init__.py should be excluded
@@ -311,77 +321,6 @@
311321
if count < 1:
312322
raise Exception(".coveragerc replacement failed.")
313323

314-
# Remove the replacements below once
315-
# https://github.com/googleapis/synthtool/pull/1188 is merged
316-
317-
# Update googleapis/repo-automation-bots repo to main in .kokoro/*.sh files
318-
s.replace(
319-
".kokoro/*.sh",
320-
"repo-automation-bots/tree/master",
321-
"repo-automation-bots/tree/main",
322-
)
323-
324-
# Customize CONTRIBUTING.rst to replace master with main
325-
s.replace(
326-
"CONTRIBUTING.rst",
327-
"fetch and merge changes from upstream into master",
328-
"fetch and merge changes from upstream into main",
329-
)
330-
331-
s.replace(
332-
"CONTRIBUTING.rst",
333-
"git merge upstream/master",
334-
"git merge upstream/main",
335-
)
336-
337-
s.replace(
338-
"CONTRIBUTING.rst",
339-
"""export GOOGLE_CLOUD_TESTING_BRANCH=\"master\"""",
340-
"""export GOOGLE_CLOUD_TESTING_BRANCH=\"main\"""",
341-
)
342-
343-
s.replace(
344-
"CONTRIBUTING.rst",
345-
"remote \(``master``\)",
346-
"remote (``main``)",
347-
)
348-
349-
s.replace(
350-
"CONTRIBUTING.rst",
351-
"blob/master/CONTRIBUTING.rst",
352-
"blob/main/CONTRIBUTING.rst",
353-
)
354-
355-
s.replace(
356-
"CONTRIBUTING.rst",
357-
"blob/master/noxfile.py",
358-
"blob/main/noxfile.py",
359-
)
360-
361-
s.replace(
362-
"docs/conf.py",
363-
"master_doc",
364-
"root_doc",
365-
)
366-
367-
s.replace(
368-
"docs/conf.py",
369-
"# The master toctree document.",
370-
"# The root toctree document.",
371-
)
372-
373-
s.move(
374-
library,
375-
excludes=[
376-
"docs/**/*",
377-
"nox.py",
378-
"README.rst",
379-
"setup.py",
380-
f"google/cloud/pubsub_{library.name}/__init__.py",
381-
f"google/cloud/pubsub_{library.name}/types.py",
382-
],
383-
)
384-
385324
s.remove_staging_dirs()
386325

387326
# ----------------------------------------------------------------------------
@@ -400,4 +339,63 @@
400339
# ----------------------------------------------------------------------------
401340
python.py_samples()
402341

342+
# Remove the replacements below once
343+
# https://github.com/googleapis/synthtool/pull/1188 is merged
344+
345+
# Update googleapis/repo-automation-bots repo to main in .kokoro/*.sh files
346+
s.replace(
347+
".kokoro/*.sh",
348+
"repo-automation-bots/tree/master",
349+
"repo-automation-bots/tree/main",
350+
)
351+
352+
# Customize CONTRIBUTING.rst to replace master with main
353+
s.replace(
354+
"CONTRIBUTING.rst",
355+
"fetch and merge changes from upstream into master",
356+
"fetch and merge changes from upstream into main",
357+
)
358+
359+
s.replace(
360+
"CONTRIBUTING.rst", "git merge upstream/master", "git merge upstream/main",
361+
)
362+
363+
s.replace(
364+
"CONTRIBUTING.rst",
365+
"""export GOOGLE_CLOUD_TESTING_BRANCH=\"master\"""",
366+
"""export GOOGLE_CLOUD_TESTING_BRANCH=\"main\"""",
367+
)
368+
369+
s.replace(
370+
"CONTRIBUTING.rst", "remote \(``master``\)", "remote (``main``)",
371+
)
372+
373+
s.replace(
374+
"CONTRIBUTING.rst", "blob/master/CONTRIBUTING.rst", "blob/main/CONTRIBUTING.rst",
375+
)
376+
377+
s.replace(
378+
"CONTRIBUTING.rst", "blob/master/noxfile.py", "blob/main/noxfile.py",
379+
)
380+
381+
s.replace(
382+
"docs/conf.py", "master_doc", "root_doc",
383+
)
384+
385+
s.replace(
386+
"docs/conf.py", "# The master toctree document.", "# The root toctree document.",
387+
)
388+
389+
s.move(
390+
library,
391+
excludes=[
392+
"docs/**/*",
393+
"nox.py",
394+
"README.rst",
395+
"setup.py",
396+
f"google/cloud/pubsub_{library.name}/__init__.py",
397+
f"google/cloud/pubsub_{library.name}/types.py",
398+
],
399+
)
400+
403401
s.shell.run(["nox", "-s", "blacken"], hide_output=False)

0 commit comments

Comments
 (0)