forked from googleapis/python-dialogflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsynth.py
More file actions
100 lines (82 loc) · 3.38 KB
/
Copy pathsynth.py
File metadata and controls
100 lines (82 loc) · 3.38 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
# 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 synthtool as s
from synthtool import gcp
gapic = gcp.GAPICGenerator()
versions = ['v2beta1', 'v2']
for version in versions:
library = gapic.py_library('dialogflow', version)
s.move(
library,
excludes=[
'google/**/*', 'setup.py', 'README.rst', 'docs/index.rst', 'nox.py'])
s.move(
library / f'google/cloud/dialogflow_{version}',
f'dialogflow_{version}')
# Due to dialogflow being unique to the other google-cloud-* libraries,
# a decent number of edits need to be done to correct naming and namespaces
docs_paths = ['docs/**/*.rst', 'docs/conf.py']
s.replace(docs_paths, 'google-cloud-dialogflow', 'dialogflow')
s.replace(docs_paths, 'google.cloud.dialogflow', 'dialogflow')
code_paths = ['tests/unit/gapic/**/*.py',
f'dialogflow_{version}/**/*.py']
s.replace(
code_paths, 'import google.cloud.dialogflow', 'import dialogflow')
s.replace(code_paths, 'from google.cloud\.', 'from ')
s.replace(code_paths, 'from google.cloud import', 'import')
s.replace(code_paths, 'google-cloud-dialogflow', 'dialogflow')
s.replace(code_paths, "'-dialogflow'", "'dialogflow'")
s.replace(
code_paths,
"(Returns:\n\s+)([a-zA-Z]+Client:)",
f"\g<1>dialogflow_{version}.\g<2>")
s.replace(
code_paths,
'(`Dialogflow documentation <.*?>`)_\.',
'\g<1>__.')
# Unexpected Indentation: https://github.com/googleapis/gapic-generator/issues/2157
# For now strip this example.
s.replace(f'dialogflow_{version}/gapic/agents_client.py',
'Example for.*\n\s+<pre>.*\n(.*\n)+?.*?</pre>', '')
# Some docstrings have oddly placed literal markers
s.replace(
[f'dialogflow_{version}/gapic/entity_types_client.py',
f'dialogflow_{version}/gapic/intents_client.py'],
"^\s+::\n\n",
"")
# Some files are missing the appropriate utf-8 header
# -*- coding: utf-8 -*-
s.replace(
["dialogflow_v2beta1/proto/session_pb2.py",
'dialogflow_v2beta1/proto/intent_pb2_grpc.py',
'dialogflow_v2/proto/intent_pb2_grpc.py',
'dialogflow_v2/proto/session_pb2.py',
],
"# Generated by the .*",
"# -*- coding: utf-8 -*-\n\g<0>")
s.replace(
['dialogflow_v2beta1/gapic/intents_client.py',
'dialogflow_v2beta1/gapic/sessions_client.py',
'dialogflow_v2/gapic/intents_client.py',
],
"# Copyright 2018 Google LLC",
"# -*- coding: utf-8 -*-\n\g<0>")
# Docstring has an extra '\' at the end of it '}\" \'
s.replace(
'dialogflow_v2/gapic/agents_client.py',
r'}\\\" [\\]\n(\s+retry \(Optional)',
'}\\"\n\g<1>')
s.replace('dialogflow_v2/proto/agent_pb2.py', ':math:', '')
s.replace('dialogflow_v2/proto/agent_pb2.py', ':raw-latex:', '')