15
15
# Instructions:
16
16
#
17
17
# Find the artman config file the describes the API you want to generate a client for.
18
+ # Specifiy the artman ARTIFACT_TYPE to generate, e.g. "java_gapic"
18
19
#
19
- # $ python utilities/generate_api.py PATH_TO_ARTMAN_CONFIG_FILE
20
+ # $ python utilities/generate_api.py PATH_TO_ARTMAN_CONFIG_FILE ARTIFACT_TYPE
20
21
21
22
import argparse
22
23
import io
35
36
'spanner-admin-database' : 'google-cloud-spanner'
36
37
}
37
38
39
+ JAVA_GAPIC = "java_gapic"
40
+ JAVA_DISCOGAPIC = "java_discogapic"
38
41
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 :]
42
+ def run_generate_api (config_path , artifact_type , noisy = False ):
43
+ """ Generate an API client library.
44
+
45
+ :param config_path: (str) Path to directory containing artman config file.
46
+ :param artifact_type: (str) artman target, e.g "java_gapic".
47
+ :param noisy: (bool) if console output should be verbose.
48
+
49
+ """
50
+ api_repo_index = config_path .rfind ('/google/' )
51
+ if artifact_type == JAVA_DISCOGAPIC :
52
+ api_repo_index = config_path .rfind ('/gapic/' )
53
+ if api_repo_index == - 1 :
54
+ raise ValueError ('Didn\' t find the API repo in config file path; need absolute path to the artman config file.' )
55
+ root_dir = config_path [0 :api_repo_index ]
56
+ api_dir = config_path [api_repo_index + 1 :]
45
57
46
58
extra_options = []
47
59
if noisy :
48
60
extra_options = ['-v' ]
49
61
50
- subprocess .check_call (['artman' , '--config' , api_dir , '--local' , '--root-dir' , root_dir ] + extra_options + ['generate' , 'java_gapic' ])
62
+ subprocess .check_call (
63
+ ['artman' , '--config' , api_dir , '--local' , '--root-dir' , root_dir ]
64
+ + extra_options + ['generate' , artifact_type ])
51
65
52
66
with io .open (config_path , encoding = 'UTF-8' ) as config_file :
53
67
artman_config_data = yaml .load (config_file , Loader = yaml .Loader )
@@ -60,38 +74,42 @@ def run_generate_api(config_path, noisy=False):
60
74
proto_dirname = 'proto-{}' .format (api_full_name )
61
75
grpc_dirname = 'grpc-{}' .format (api_full_name )
62
76
gapic_dirname = 'gapic-{}' .format (api_full_name )
63
- proto_dir = os .path .join ('artman-genfiles' , 'java' , proto_dirname )
64
- grpc_dir = os .path .join ('artman-genfiles' , 'java' , grpc_dirname )
77
+
65
78
gapic_dir = os .path .join ('artman-genfiles' , 'java' , gapic_dirname )
66
- if not os .path .exists (proto_dir ):
67
- raise ValueError ('generated proto dir doesn\' t exist: {}' .format (proto_dir ))
68
- if not os .path .exists (grpc_dir ):
69
- raise ValueError ('generated grpc dir doesn\' t exist: {}' .format (grpc_dir ))
70
79
if not os .path .exists (gapic_dir ):
71
80
raise ValueError ('generated gapic dir doesn\' t exist: {}' .format (gapic_dir ))
72
81
73
- target_proto_dir = os .path .join ('google-api-grpc' , proto_dirname )
74
- target_grpc_dir = os .path .join ('google-api-grpc' , grpc_dirname )
75
- if os .path .exists (target_proto_dir ):
76
- print ('{} already exists, removing & replacing it.' .format (target_proto_dir ))
77
- if os .path .exists (target_grpc_dir ):
78
- print ('{} already exists, removing & replacing it.' .format (target_grpc_dir ))
79
-
80
- print ('-- ignore any pathspec errors that follow' )
81
-
82
- if os .path .exists (target_proto_dir ):
83
- shutil .rmtree (target_proto_dir )
84
- shutil .copytree (proto_dir , target_proto_dir )
85
- os .remove (os .path .join (target_proto_dir , 'LICENSE' ))
86
- os .remove (os .path .join (target_proto_dir , 'build.gradle' ))
87
- subprocess .call (['git' , 'checkout' , os .path .join (target_proto_dir , 'pom.xml' )])
88
-
89
- if os .path .exists (target_grpc_dir ):
90
- shutil .rmtree (target_grpc_dir )
91
- shutil .copytree (grpc_dir , target_grpc_dir )
92
- os .remove (os .path .join (target_grpc_dir , 'LICENSE' ))
93
- os .remove (os .path .join (target_grpc_dir , 'build.gradle' ))
94
- subprocess .call (['git' , 'checkout' , os .path .join (target_grpc_dir , 'pom.xml' )])
82
+ if artifact_type != JAVA_DISCOGAPIC :
83
+ proto_dir = os .path .join ('artman-genfiles' , 'java' , proto_dirname )
84
+ grpc_dir = os .path .join ('artman-genfiles' , 'java' , grpc_dirname )
85
+
86
+ if not os .path .exists (proto_dir ):
87
+ raise ValueError ('generated proto dir doesn\' t exist: {}' .format (proto_dir ))
88
+ if not os .path .exists (grpc_dir ):
89
+ raise ValueError ('generated grpc dir doesn\' t exist: {}' .format (grpc_dir ))
90
+
91
+ target_proto_dir = os .path .join ('google-api-grpc' , proto_dirname )
92
+ target_grpc_dir = os .path .join ('google-api-grpc' , grpc_dirname )
93
+ if os .path .exists (target_proto_dir ):
94
+ print ('{} already exists, removing & replacing it.' .format (target_proto_dir ))
95
+ if os .path .exists (target_grpc_dir ):
96
+ print ('{} already exists, removing & replacing it.' .format (target_grpc_dir ))
97
+
98
+ print ('-- ignore any pathspec errors that follow' )
99
+
100
+ if os .path .exists (target_proto_dir ):
101
+ shutil .rmtree (target_proto_dir )
102
+ shutil .copytree (proto_dir , target_proto_dir )
103
+ os .remove (os .path .join (target_proto_dir , 'LICENSE' ))
104
+ os .remove (os .path .join (target_proto_dir , 'build.gradle' ))
105
+ subprocess .call (['git' , 'checkout' , os .path .join (target_proto_dir , 'pom.xml' )])
106
+
107
+ if os .path .exists (target_grpc_dir ):
108
+ shutil .rmtree (target_grpc_dir )
109
+ shutil .copytree (grpc_dir , target_grpc_dir )
110
+ os .remove (os .path .join (target_grpc_dir , 'LICENSE' ))
111
+ os .remove (os .path .join (target_grpc_dir , 'build.gradle' ))
112
+ subprocess .call (['git' , 'checkout' , os .path .join (target_grpc_dir , 'pom.xml' )])
95
113
96
114
api_unversioned_name = '{}-{}' .format (org_name , api_name )
97
115
if api_name in dir_overrides :
@@ -113,11 +131,13 @@ def run_generate_api(config_path, noisy=False):
113
131
def main ():
114
132
parser = argparse .ArgumentParser (description = 'Regenerate a single API.' )
115
133
parser .add_argument ('config_file' , help = 'The artman config file for the API' )
134
+ parser .add_argument ('artifact_type' , help = 'The artman artifact type' ,
135
+ default = "java_gapic" )
116
136
parser .add_argument ('--quiet' , action = "store_true" , default = False ,
117
137
help = 'Don\' t print informational instructions' )
118
138
args = parser .parse_args ()
119
139
120
- run_generate_api (args .config_file , not args .quiet )
140
+ run_generate_api (args .config_file , args . artifact_type , not args .quiet )
121
141
122
142
if __name__ == '__main__' :
123
143
main ()
0 commit comments