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