forked from googleapis/google-cloud-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsynth.py
More file actions
118 lines (101 loc) · 3.92 KB
/
Copy pathsynth.py
File metadata and controls
118 lines (101 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""This script is used to synthesize generated parts of this library."""
import re
import synthtool as s
from synthtool import gcp
gapic = gcp.GAPICGenerator()
common = gcp.CommonTemplates()
version = "v1"
# ----------------------------------------------------------------------------
# Generate pubsub GAPIC layer
# ----------------------------------------------------------------------------
library = gapic.py_library(
"pubsub",
version,
config_path="/google/pubsub/artman_pubsub.yaml",
include_protos=True,
)
s.move(
library,
excludes=[
"docs/**/*",
"nox.py",
"README.rst",
"setup.py",
"google/cloud/pubsub_v1/__init__.py",
"google/cloud/pubsub_v1/types.py",
],
)
# Adjust tests to import the clients directly.
s.replace(
"tests/unit/gapic/v1/test_publisher_client_v1.py",
"from google.cloud import pubsub_v1",
"from google.cloud.pubsub_v1.gapic import publisher_client",
)
s.replace(
"tests/unit/gapic/v1/test_publisher_client_v1.py", " pubsub_v1", " publisher_client"
)
s.replace(
"tests/unit/gapic/v1/test_subscriber_client_v1.py",
"from google.cloud import pubsub_v1",
"from google.cloud.pubsub_v1.gapic import subscriber_client",
)
s.replace(
"tests/unit/gapic/v1/test_subscriber_client_v1.py",
" pubsub_v1",
" subscriber_client",
)
# DEFAULT SCOPES are being used. so let's force them in.
s.replace(
"google/cloud/pubsub_v1/gapic/*er_client.py",
"# The name of the interface for this client. This is the key used to",
"""# The scopes needed to make gRPC calls to all of the methods defined in
# this service
_DEFAULT_SCOPES = (
'https://www.googleapis.com/auth/cloud-platform',
'https://www.googleapis.com/auth/pubsub', )
\g<0>""",
)
s.replace(
"google/cloud/pubsub_v1/gapic/publisher_client.py",
"import google.api_core.gapic_v1.method\n",
"\g<0>import google.api_core.path_template\n",
)
# Doc strings are formatted poorly
s.replace(
"google/cloud/pubsub_v1/proto/pubsub_pb2.py",
'DESCRIPTOR = _MESSAGESTORAGEPOLICY,\n\s+__module__.*\n\s+,\n\s+__doc__ = """',
"\g<0>A message storage policy.\n\n\n ",
)
s.replace(
"google/cloud/pubsub_v1/gapic/subscriber_client.py",
"subscription \(str\): The subscription whose backlog .*\n(.*\n)+?"
"\s+Format is .*",
"""subscription (str): The subscription whose backlog the snapshot retains.
Specifically, the created snapshot is guaranteed to retain: \\
(a) The existing backlog on the subscription. More precisely, this is \\
defined as the messages in the subscription's backlog that are \\
unacknowledged upon the successful completion of the \\
`CreateSnapshot` request; as well as: \\
(b) Any messages published to the subscription's topic following the \\
successful completion of the CreateSnapshot request. \\
Format is ``projects/{project}/subscriptions/{sub}``.""",
)
# ----------------------------------------------------------------------------
# Add templated files
# ----------------------------------------------------------------------------
templated_files = gcp.CommonTemplates().py_library(unit_cov_level=97, cov_level=100)
s.move(templated_files)
s.shell.run(["nox", "-s", "blacken"], hide_output=False)