forked from googleapis/python-vision
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathowlbot.py
More file actions
125 lines (106 loc) · 5.31 KB
/
Copy pathowlbot.py
File metadata and controls
125 lines (106 loc) · 5.31 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
119
120
121
122
123
124
125
# 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
from synthtool.languages import python
common = gcp.CommonTemplates()
default_version = "v1"
for library in s.get_staging_dirs(default_version):
if library.name == "v1":
s.replace(
library / "google/cloud/vision/__init__.py",
"from google.cloud.vision_v1.services.image_annotator.client import ImageAnnotatorClient",
"from google.cloud.vision_v1 import ImageAnnotatorClient"
)
# Add vision helpers to each version
s.replace(
library / f"google/cloud/vision_{library.name}/__init__.py",
"from .services.image_annotator import ImageAnnotatorClient",
"from google.cloud.vision_helpers.decorators import "
"add_single_feature_methods\n"
"from google.cloud.vision_helpers import VisionHelpers\n\n"
"from .services.image_annotator import ImageAnnotatorClient as IacImageAnnotatorClient",
)
s.replace(
library / f"google/cloud/vision_{library.name}/__init__.py",
"__all__ = \(",
"@add_single_feature_methods\n"
"class ImageAnnotatorClient(VisionHelpers, IacImageAnnotatorClient):\n"
"\t__doc__ = IacImageAnnotatorClient.__doc__\n"
"\tFeature = Feature\n\n"
"__all__ = (",
)
# Temporary workaround due to bug https://github.com/googleapis/proto-plus-python/issues/135
s.replace(
library / f"google/cloud/vision_{library.name}/services/image_annotator/client.py",
"request = image_annotator.BatchAnnotateImagesRequest\(request\)",
"request = image_annotator.BatchAnnotateImagesRequest(request)\n"
" if requests is not None:\n"
" for i in range(len(requests)):\n"
" requests[i] = image_annotator.AnnotateImageRequest(requests[i])"
)
s.replace(
library / f"google/cloud/vision_{library.name}/services/image_annotator/client.py",
"request = image_annotator.BatchAnnotateFilesRequest\(request\)",
"request = image_annotator.BatchAnnotateFilesRequest(request)\n"
" if requests is not None:\n"
" for i in range(len(requests)):\n"
" requests[i] = image_annotator.AnnotateFileRequest(requests[i])"
)
s.replace(
library / f"google/cloud/vision_{library.name}/services/image_annotator/client.py",
"request = image_annotator.AsyncBatchAnnotateImagesRequest\(request\)",
"request = image_annotator.AsyncBatchAnnotateImagesRequest(request)\n"
" if requests is not None:\n"
" for i in range(len(requests)):\n"
" requests[i] = image_annotator.AnnotateImageRequest(requests[i])"
)
s.replace(
library / f"google/cloud/vision_{library.name}/services/image_annotator/client.py",
"request = image_annotator.AsyncBatchAnnotateFilesRequest\(request\)",
"request = image_annotator.AsyncBatchAnnotateFilesRequest(request)\n"
" if requests is not None:\n"
" for i in range(len(requests)):\n"
" requests[i] = image_annotator.AsyncAnnotateFileRequest(requests[i])"
)
s.move(library / f"google/cloud/vision_{library.name}/proto")
s.move(library / f"google/cloud/vision_{library.name}/services")
s.move(library / f"google/cloud/vision_{library.name}/types")
s.move(library / f"google/cloud/vision_{library.name}/__init__.py")
s.move(library / f"google/cloud/vision_{library.name}/py.typed")
s.move(library / f"tests/unit/gapic/vision_{library.name}")
# don't publish docs for these versions
if library.name != "v1p1beta1":
s.move(library / f"docs/vision_{library.name}")
# Move docs configuration
s.move(library / f"docs/conf.py")
s.remove_staging_dirs()
# ----------------------------------------------------------------------------
# Add templated files
# ----------------------------------------------------------------------------
templated_files = common.py_library(
samples=True,
microgenerator=True,
cov_level=99,
system_test_external_dependencies=["google-cloud-storage"]
)
s.move(templated_files, excludes=[".coveragerc"]) # microgenerator has a good .coveragerc file
# Work around bug in templates https://github.com/googleapis/synthtool/pull/1335
s.replace(".github/workflows/unittest.yml", "--fail-under=100", "--fail-under=99")
# ----------------------------------------------------------------------------
# Samples templates
# ----------------------------------------------------------------------------
python.py_samples(skip_readmes=True)
s.shell.run(["nox", "-s", "blacken"], hide_output=False)