|
27 | 27 |
|
28 | 28 | for library in s.get_staging_dirs(default_version): |
29 | 29 | # 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""". |
32 | 33 | Attributes:""", |
33 | | - r""".\n |
| 34 | + r""".\n |
34 | 35 | Attributes:""", |
35 | 36 | ) |
36 | 37 |
|
37 | 38 | # 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""". |
40 | 42 | Attributes:""", |
41 | | - r""".\n |
| 43 | + r""".\n |
42 | 44 | Attributes:""", |
43 | 45 | ) |
44 | 46 |
|
|
63 | 65 | # Modify GRPC options in transports. |
64 | 66 | count = s.replace( |
65 | 67 | [ |
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}/*", |
68 | 70 | ], |
69 | 71 | "options=\[.*?\]", |
70 | 72 | """options=[ |
|
83 | 85 | library / f"google/pubsub_{library.name}/services/publisher/client.py", |
84 | 86 | library / f"google/pubsub_{library.name}/services/subscriber/client.py", |
85 | 87 | ] |
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." |
92 | 90 | ) |
93 | 91 |
|
| 92 | + count = s.replace(clients_to_patch, r"import os", "import functools\n\g<0>") |
| 93 | + |
94 | 94 | if count < len(clients_to_patch): |
95 | 95 | raise Exception(err_msg) |
96 | 96 |
|
97 | 97 | count = s.replace( |
98 | 98 | clients_to_patch, |
99 | 99 | f"from google\.pubsub_{library.name}\.types import pubsub", |
100 | | - "\g<0>\n\nimport grpc" |
| 100 | + "\g<0>\n\nimport grpc", |
101 | 101 | ) |
102 | 102 |
|
103 | 103 | if count < len(clients_to_patch): |
|
154 | 154 | ((?P<indent>[^\n\S]+)\#\ Wrap\ the\ RPC\ method) |
155 | 155 | """, |
156 | 156 | textwrap.dedent( |
157 | | - """ |
| 157 | + """ |
158 | 158 | \g<1> |
159 | 159 | \g<indent>if request.return_immediately: |
160 | 160 | \g<indent> warnings.warn( |
161 | 161 | \g<indent> "The return_immediately flag is deprecated and should be set to False.", |
162 | 162 | \g<indent> category=DeprecationWarning, |
163 | 163 | \g<indent> ) |
164 | 164 |
|
165 | | - \g<2>"""), |
| 165 | + \g<2>""" |
| 166 | + ), |
166 | 167 | flags=re.MULTILINE | re.DOTALL | re.VERBOSE, |
167 | 168 | ) |
168 | 169 |
|
|
179 | 180 | count = s.replace( |
180 | 181 | library / f"tests/unit/gapic/pubsub_{library.name}/test_subscriber.py", |
181 | 182 | textwrap.dedent( |
182 | | - r""" |
| 183 | + r""" |
183 | 184 | ([^\n\S]+# Call the method with a truthy value for each flattened field, |
184 | 185 | [^\n\S]+# using the keyword arguments to the method\.) |
185 | 186 | \s+(client\.pull\(.*?\))""" |
|
188 | 189 | with warnings.catch_warnings(): |
189 | 190 | warnings.simplefilter("ignore", category=DeprecationWarning) |
190 | 191 | \g<2>""", |
191 | | - flags = re.MULTILINE | re.DOTALL, |
| 192 | + flags=re.MULTILINE | re.DOTALL, |
192 | 193 | ) |
193 | 194 |
|
194 | 195 | if count < 1: |
|
206 | 207 | with warnings.catch_warnings(): |
207 | 208 | warnings.simplefilter("ignore", category=DeprecationWarning) |
208 | 209 | \g<2>""", |
209 | | - flags = re.MULTILINE | re.DOTALL, |
| 210 | + flags=re.MULTILINE | re.DOTALL, |
210 | 211 | ) |
211 | 212 |
|
212 | 213 | if count < 1: |
|
215 | 216 | # Make sure that client library version is present in user agent header. |
216 | 217 | s.replace( |
217 | 218 | [ |
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", |
219 | 221 | 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", |
222 | 226 | 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", |
225 | 231 | 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", |
227 | 234 | ], |
228 | 235 | r"""gapic_version=(pkg_resources\.get_distribution\(\s+)['"]google-pubsub['"]""", |
229 | 236 | "client_library_version=\g<1>'google-cloud-pubsub'", |
230 | 237 | ) |
231 | 238 |
|
232 | 239 | # Docstrings of *_iam_policy() methods are formatted poorly and must be fixed |
233 | 240 | # 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 | + ) |
235 | 246 | s.replace( |
236 | 247 | library / f"google/pubsub_{library.name}/services/*er/client.py", |
237 | 248 | r"(\s+)\*\*JSON Example\*\*\s+::", |
|
254 | 265 | s.replace( |
255 | 266 | library / f"google/pubsub_{library.name}/types/__init__.py", |
256 | 267 | r"from \.pubsub import \(", |
257 | | - "from typing import Union\n\n\g<0>" |
| 268 | + "from typing import Union\n\n\g<0>", |
258 | 269 | ) |
259 | 270 |
|
260 | 271 | s.replace( |
261 | 272 | library / f"google/pubsub_{library.name}/types/__init__.py", |
262 | 273 | r"__all__ = \(\n", |
263 | | - textwrap.dedent('''\ |
| 274 | + textwrap.dedent( |
| 275 | + '''\ |
264 | 276 | TimeoutType = Union[ |
265 | 277 | int, |
266 | 278 | float, |
|
269 | 281 | ] |
270 | 282 | """The type of the timeout parameter of publisher client methods.""" |
271 | 283 |
|
272 | | - \g<0> "TimeoutType",''') |
| 284 | + \g<0> "TimeoutType",''' |
| 285 | + ), |
273 | 286 | ) |
274 | 287 |
|
275 | 288 | s.replace( |
276 | 289 | library / f"google/pubsub_{library.name}/services/publisher/*client.py", |
277 | 290 | 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", |
279 | 292 | ) |
280 | 293 |
|
281 | 294 | s.replace( |
|
293 | 306 | s.replace( |
294 | 307 | library / f"google/pubsub_{library.name}/services/publisher/*client.py", |
295 | 308 | 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"), |
300 | 310 | ) |
301 | 311 |
|
302 | 312 | # The namespace package declaration in google/cloud/__init__.py should be excluded |
|
311 | 321 | if count < 1: |
312 | 322 | raise Exception(".coveragerc replacement failed.") |
313 | 323 |
|
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 | | - |
385 | 324 | s.remove_staging_dirs() |
386 | 325 |
|
387 | 326 | # ---------------------------------------------------------------------------- |
|
400 | 339 | # ---------------------------------------------------------------------------- |
401 | 340 | python.py_samples() |
402 | 341 |
|
| 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 | + |
403 | 401 | s.shell.run(["nox", "-s", "blacken"], hide_output=False) |
0 commit comments