31
31
(.*?)
32
32
\)
33
33
"""
34
- resource_pattern = r"//google/cloud:common_resources_proto"
35
- location_pattern = r"//google/cloud/location:location_proto"
36
- iam_pattern = r"//google/iam/v1:iam_policy_proto"
34
+ # match a line which the first character is "#".
35
+ comment_pattern = r"^\s*\#+"
36
+ pattern_to_proto = {
37
+ r"//google/cloud:common_resources_proto" : "google/cloud/common_resources.proto" ,
38
+ r"//google/cloud/location:location_proto" : "google/cloud/location/locations.proto" ,
39
+ r"//google/iam/v1:iam_policy_proto" : "google/iam/v1/iam_policy.proto" ,
40
+ }
37
41
transport_pattern = r"transport = \"(.*?)\""
38
42
rest_pattern = r"rest_numeric_enums = True"
39
43
gapic_yaml_pattern = r"gapic_yaml = \"(.*?)\""
@@ -97,7 +101,9 @@ def parse(
97
101
if len (assembly_target ) > 0 :
98
102
include_samples = __parse_include_samples (assembly_target [0 ])
99
103
if len (gapic_target ) == 0 :
100
- return GapicInputs (include_samples = include_samples )
104
+ return GapicInputs (
105
+ additional_protos = additional_protos , include_samples = include_samples
106
+ )
101
107
102
108
transport = __parse_transport (gapic_target [0 ])
103
109
rest_numeric_enum = __parse_rest_numeric_enums (gapic_target [0 ])
@@ -119,12 +125,16 @@ def parse(
119
125
120
126
def __parse_additional_protos (proto_library_target : str ) -> str :
121
127
res = [" " ]
122
- if len (re .findall (resource_pattern , proto_library_target )) != 0 :
123
- res .append ("google/cloud/common_resources.proto" )
124
- if len (re .findall (location_pattern , proto_library_target )) != 0 :
125
- res .append ("google/cloud/location/locations.proto" )
126
- if len (re .findall (iam_pattern , proto_library_target )) != 0 :
127
- res .append ("google/iam/v1/iam_policy.proto" )
128
+ lines = proto_library_target .split ("\n " )
129
+ for line in lines :
130
+ if len (re .findall (comment_pattern , line )) != 0 :
131
+ # skip a line which the first charactor is "#" since it's
132
+ # a comment.
133
+ continue
134
+ for pattern in pattern_to_proto :
135
+ if len (re .findall (pattern , line )) == 0 :
136
+ continue
137
+ res .append (pattern_to_proto [pattern ])
128
138
return " " .join (res )
129
139
130
140
0 commit comments