Skip to content

Commit 8682ac5

Browse files
Creating batch_generate_apis.py (#3428)
1 parent 9e136cf commit 8682ac5

File tree

3 files changed

+130
-19
lines changed

3 files changed

+130
-19
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,7 @@ src/test/resources/gcd-v1beta2-rev1-2.1.1.zip
3737

3838
# API key file containing value of GOOGLE_API_KEY for integration tests
3939
api_key
40+
41+
# Python utilities
42+
*.pyc
43+
artman-genfiles

utilities/batch_generate_apis.py

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Instructions:
16+
#
17+
# Check out the googleapis repo somewhere locally (e.g. from
18+
# https://github.com/googleapis/googleapis):
19+
#
20+
# $ git checkout https://github.com/googleapis/googleapis.git
21+
#
22+
# Run this script:
23+
#
24+
# $ python utilities/batch_generate_apis.py PATH_TO_GOOGLEAPIS
25+
26+
import argparse
27+
import os
28+
29+
import generate_api
30+
31+
32+
def run(googleapis):
33+
def generate(artman_yaml):
34+
generate_api.run_generate_api(os.path.join(googleapis, artman_yaml))
35+
36+
# TODO Needs to have java_proto called instead of java_grpc
37+
#generate('google/datastore/artman_datastore.yaml')
38+
39+
generate('google/cloud/bigquery/datatransfer/artman_bigquerydatatransfer.yaml')
40+
generate('google/bigtable/artman_bigtable.yaml')
41+
generate('google/bigtable/admin/artman_bigtableadmin.yaml')
42+
generate('google/container/artman_container.yaml')
43+
generate('google/cloud/dataproc/artman_dataproc_v1.yaml')
44+
generate('google/cloud/dialogflow/artman_dialogflow_v2.yaml')
45+
generate('google/cloud/dialogflow/artman_dialogflow_v2beta1_java.yaml')
46+
generate('google/privacy/dlp/artman_dlp_v2.yaml')
47+
generate('google/devtools/clouderrorreporting/artman_errorreporting.yaml')
48+
generate('google/firestore/artman_firestore.yaml')
49+
generate('google/cloud/language/artman_language_v1.yaml')
50+
generate('google/cloud/language/artman_language_v1beta2.yaml')
51+
generate('google/logging/artman_logging.yaml')
52+
generate('google/monitoring/artman_monitoring.yaml')
53+
generate('google/pubsub/artman_pubsub.yaml')
54+
generate('google/cloud/oslogin/artman_oslogin_v1.yaml')
55+
generate('google/cloud/redis/artman_redis_v1beta1.yaml')
56+
generate('google/spanner/artman_spanner.yaml')
57+
generate('google/spanner/admin/database/artman_spanner_admin_database.yaml')
58+
generate('google/spanner/admin/instance/artman_spanner_admin_instance.yaml')
59+
generate('google/cloud/speech/artman_speech_v1.yaml')
60+
generate('google/cloud/speech/artman_speech_v1beta1.yaml')
61+
generate('google/cloud/speech/artman_speech_v1p1beta1.yaml')
62+
generate('google/cloud/texttospeech/artman_texttospeech_v1.yaml')
63+
generate('google/cloud/texttospeech/artman_texttospeech_v1beta1.yaml')
64+
generate('google/devtools/cloudtrace/artman_cloudtrace_v1.yaml')
65+
generate('google/devtools/cloudtrace/artman_cloudtrace_v2.yaml')
66+
generate('google/cloud/videointelligence/artman_videointelligence_v1beta1.yaml')
67+
generate('google/cloud/videointelligence/artman_videointelligence_v1beta2.yaml')
68+
generate('google/cloud/videointelligence/artman_videointelligence_v1p1beta1.yaml')
69+
generate('google/cloud/videointelligence/artman_videointelligence_v1.yaml')
70+
generate('google/cloud/vision/artman_vision_v1.yaml')
71+
generate('google/cloud/vision/artman_vision_v1p1beta1.yaml')
72+
generate('google/cloud/vision/artman_vision_v1p2beta1.yaml')
73+
generate('google/cloud/websecurityscanner/artman_websecurityscanner_v1alpha.yaml')
74+
75+
76+
def main():
77+
# TODO Make the docker image the default, add --local option
78+
parser = argparse.ArgumentParser(description='Batch generate all APIs.')
79+
parser.add_argument('googleapis', help='The path to the googleapis repo')
80+
args = parser.parse_args()
81+
82+
run(args.googleapis)
83+
84+
if __name__ == '__main__':
85+
main()

utilities/generate_api.py

+41-19
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
# Instructions:
16+
#
17+
# Find the artman config file the describes the API you want to generate a client for.
18+
#
19+
# $ python utilities/generate_api.py PATH_TO_ARTMAN_CONFIG_FILE
20+
1521
import argparse
1622
import io
1723
import os
@@ -21,14 +27,27 @@
2127
from distutils import dir_util
2228
from ruamel import yaml
2329

24-
def run(config_path):
25-
api_dir_index = config_path.find('/google/')
26-
if api_dir_index == -1:
27-
raise ValueError('Didn\'t find /google/ in config file path; need absolute path to the artman config file.')
28-
root_dir = config_path[0:api_dir_index]
29-
api_dir = config_path[api_dir_index+1:]
3030

31-
subprocess.check_call(['artman', '--config', api_dir, '--local', '-v', '--root-dir', root_dir, 'generate', 'java_gapic'])
31+
dir_overrides = {
32+
'bigtable-admin': 'google-cloud-bigtable',
33+
'error-reporting': 'google-cloud-errorreporting',
34+
'spanner-admin-instance': 'google-cloud-spanner',
35+
'spanner-admin-database': 'google-cloud-spanner'
36+
}
37+
38+
39+
def run_generate_api(config_path, noisy=False):
40+
googleapis_index = config_path.rfind('/google/')
41+
if googleapis_index == -1:
42+
raise ValueError('Didn\'t find /googleapis/ in config file path; need absolute path to the artman config file.')
43+
root_dir = config_path[0:googleapis_index]
44+
api_dir = config_path[googleapis_index+1:]
45+
46+
extra_options = []
47+
if noisy:
48+
extra_options = ['-v']
49+
50+
subprocess.check_call(['artman', '--config', api_dir, '--local', '--root-dir', root_dir] + extra_options + ['generate', 'java_gapic'])
3251

3352
with io.open(config_path, encoding='UTF-8') as config_file:
3453
artman_config_data = yaml.load(config_file, Loader=yaml.Loader)
@@ -44,9 +63,6 @@ def run(config_path):
4463
proto_dir = os.path.join('artman-genfiles', 'java', proto_dirname)
4564
grpc_dir = os.path.join('artman-genfiles', 'java', grpc_dirname)
4665
gapic_dir = os.path.join('artman-genfiles', 'java', gapic_dirname)
47-
print(proto_dir)
48-
print(grpc_dir)
49-
print(gapic_dir)
5066
if not os.path.exists(proto_dir):
5167
raise ValueError('generated proto dir doesn\'t exist: {}'.format(proto_dir))
5268
if not os.path.exists(grpc_dir):
@@ -78,24 +94,30 @@ def run(config_path):
7894
subprocess.call(['git', 'checkout', os.path.join(target_grpc_dir, 'pom.xml')])
7995

8096
api_unversioned_name = '{}-{}'.format(org_name, api_name)
97+
if api_name in dir_overrides:
98+
api_unversioned_name = dir_overrides[api_name]
99+
81100
target_gapic_dir = os.path.join('google-cloud-clients', api_unversioned_name)
82101
dir_util.copy_tree(os.path.join(gapic_dir, 'src'), os.path.join(target_gapic_dir, 'src'))
83102

84-
print('**** REMAINING MANUAL WORK: *****')
85-
print('This script doesn\'t set up new clients. If this is a new client, you need to:')
86-
print('1. Add the new proto and grpc modules into google-api-grpc/pom.xml')
87-
print('3. Copy an existing client pom.xml to the new client directory, update its text')
88-
print('4. Copy an existing client README.md to the new client directory, update its text')
89-
print('5. Add the new proto, grpc, and client modules into versions.txt')
90-
print('6. Add the new proto, grpc, and client modules into google-cloud-bom/pom.xml')
91-
print('7. Run `utilities/replace_versions.py` to update the module versions')
103+
if noisy:
104+
print('**** REMAINING MANUAL WORK: *****')
105+
print('This script doesn\'t set up new clients. If this is a new client, you need to:')
106+
print('1. Add the new proto and grpc modules into google-api-grpc/pom.xml')
107+
print('3. Copy an existing client pom.xml to the new client directory, update its text')
108+
print('4. Copy an existing client README.md to the new client directory, update its text')
109+
print('5. Add the new proto, grpc, and client modules into versions.txt')
110+
print('6. Add the new proto, grpc, and client modules into google-cloud-bom/pom.xml')
111+
print('7. Run `utilities/replace_versions.py` to update the module versions')
92112

93113
def main():
94114
parser = argparse.ArgumentParser(description='Regenerate a single API.')
95115
parser.add_argument('config_file', help='The artman config file for the API')
116+
parser.add_argument('--quiet', action="store_true", default=False,
117+
help='Don\'t print informational instructions')
96118
args = parser.parse_args()
97119

98-
run(args.config_file)
120+
run_generate_api(args.config_file, not args.quiet)
99121

100122
if __name__ == '__main__':
101123
main()

0 commit comments

Comments
 (0)