@@ -105,77 +105,77 @@ def __validate(self) -> None:
105
105
)
106
106
seen_library_names [library_name ] = library .name_pretty
107
107
108
+ @staticmethod
109
+ def from_yaml (path_to_yaml : str ) -> "GenerationConfig" :
110
+ """
111
+ Parses a yaml located in path_to_yaml.
112
+ :param path_to_yaml: the path to the configuration file
113
+ :return the parsed configuration represented by the "model" classes
114
+ """
115
+ with open (path_to_yaml , "r" ) as file_stream :
116
+ config = yaml .safe_load (file_stream )
117
+
118
+ libraries = _required (config , "libraries" , REPO_LEVEL_PARAMETER )
119
+ if not libraries :
120
+ raise ValueError (f"Library is None in { path_to_yaml } ." )
121
+
122
+ parsed_libraries = list ()
123
+ for library in libraries :
124
+ gapics = _required (library , "GAPICs" )
125
+
126
+ parsed_gapics = list ()
127
+ if not gapics :
128
+ raise ValueError (f"GAPICs is None in { library } ." )
129
+ for gapic in gapics :
130
+ proto_path = _required (gapic , "proto_path" , GAPIC_LEVEL_PARAMETER )
131
+ new_gapic = GapicConfig (proto_path )
132
+ parsed_gapics .append (new_gapic )
133
+
134
+ new_library = LibraryConfig (
135
+ api_shortname = _required (library , "api_shortname" ),
136
+ api_description = _required (library , "api_description" ),
137
+ name_pretty = _required (library , "name_pretty" ),
138
+ product_documentation = _required (library , "product_documentation" ),
139
+ gapic_configs = parsed_gapics ,
140
+ library_type = _optional (library , "library_type" , "GAPIC_AUTO" ),
141
+ release_level = _optional (library , "release_level" , "preview" ),
142
+ api_id = _optional (library , "api_id" , None ),
143
+ api_reference = _optional (library , "api_reference" , None ),
144
+ codeowner_team = _optional (library , "codeowner_team" , None ),
145
+ excluded_poms = _optional (library , "excluded_poms" , None ),
146
+ excluded_dependencies = _optional (library , "excluded_dependencies" , None ),
147
+ client_documentation = _optional (library , "client_documentation" , None ),
148
+ distribution_name = _optional (library , "distribution_name" , None ),
149
+ googleapis_commitish = _optional (library , "googleapis_commitish" , None ),
150
+ group_id = _optional (library , "group_id" , "com.google.cloud" ),
151
+ issue_tracker = _optional (library , "issue_tracker" , None ),
152
+ library_name = _optional (library , "library_name" , None ),
153
+ rest_documentation = _optional (library , "rest_documentation" , None ),
154
+ rpc_documentation = _optional (library , "rpc_documentation" , None ),
155
+ cloud_api = _optional (library , "cloud_api" , True ),
156
+ requires_billing = _optional (library , "requires_billing" , True ),
157
+ extra_versioned_modules = _optional (
158
+ library , "extra_versioned_modules" , None
159
+ ),
160
+ recommended_package = _optional (library , "recommended_package" , None ),
161
+ min_java_version = _optional (library , "min_java_version" , None ),
162
+ transport = _optional (library , "transport" , None ),
163
+ )
164
+ parsed_libraries .append (new_library )
108
165
109
- def from_yaml (path_to_yaml : str ) -> GenerationConfig :
110
- """
111
- Parses a yaml located in path_to_yaml.
112
- :param path_to_yaml: the path to the configuration file
113
- :return the parsed configuration represented by the "model" classes
114
- """
115
- with open (path_to_yaml , "r" ) as file_stream :
116
- config = yaml .safe_load (file_stream )
117
-
118
- libraries = __required (config , "libraries" , REPO_LEVEL_PARAMETER )
119
- if not libraries :
120
- raise ValueError (f"Library is None in { path_to_yaml } ." )
121
-
122
- parsed_libraries = list ()
123
- for library in libraries :
124
- gapics = __required (library , "GAPICs" )
125
-
126
- parsed_gapics = list ()
127
- if not gapics :
128
- raise ValueError (f"GAPICs is None in { library } ." )
129
- for gapic in gapics :
130
- proto_path = __required (gapic , "proto_path" , GAPIC_LEVEL_PARAMETER )
131
- new_gapic = GapicConfig (proto_path )
132
- parsed_gapics .append (new_gapic )
133
-
134
- new_library = LibraryConfig (
135
- api_shortname = __required (library , "api_shortname" ),
136
- api_description = __required (library , "api_description" ),
137
- name_pretty = __required (library , "name_pretty" ),
138
- product_documentation = __required (library , "product_documentation" ),
139
- gapic_configs = parsed_gapics ,
140
- library_type = __optional (library , "library_type" , "GAPIC_AUTO" ),
141
- release_level = __optional (library , "release_level" , "preview" ),
142
- api_id = __optional (library , "api_id" , None ),
143
- api_reference = __optional (library , "api_reference" , None ),
144
- codeowner_team = __optional (library , "codeowner_team" , None ),
145
- excluded_poms = __optional (library , "excluded_poms" , None ),
146
- excluded_dependencies = __optional (library , "excluded_dependencies" , None ),
147
- client_documentation = __optional (library , "client_documentation" , None ),
148
- distribution_name = __optional (library , "distribution_name" , None ),
149
- googleapis_commitish = __optional (library , "googleapis_commitish" , None ),
150
- group_id = __optional (library , "group_id" , "com.google.cloud" ),
151
- issue_tracker = __optional (library , "issue_tracker" , None ),
152
- library_name = __optional (library , "library_name" , None ),
153
- rest_documentation = __optional (library , "rest_documentation" , None ),
154
- rpc_documentation = __optional (library , "rpc_documentation" , None ),
155
- cloud_api = __optional (library , "cloud_api" , True ),
156
- requires_billing = __optional (library , "requires_billing" , True ),
157
- extra_versioned_modules = __optional (
158
- library , "extra_versioned_modules" , None
166
+ parsed_config = GenerationConfig (
167
+ googleapis_commitish = _required (
168
+ config , "googleapis_commitish" , REPO_LEVEL_PARAMETER
159
169
),
160
- recommended_package = __optional ( library , "recommended_package" , None ),
161
- min_java_version = __optional ( library , "min_java_version" , None ),
162
- transport = __optional ( library , "transport" , None ) ,
170
+ gapic_generator_version = _optional ( config , GAPIC_GENERATOR_VERSION , None ),
171
+ libraries_bom_version = _optional ( config , LIBRARIES_BOM_VERSION , None ),
172
+ libraries = parsed_libraries ,
163
173
)
164
- parsed_libraries .append (new_library )
165
-
166
- parsed_config = GenerationConfig (
167
- googleapis_commitish = __required (
168
- config , "googleapis_commitish" , REPO_LEVEL_PARAMETER
169
- ),
170
- gapic_generator_version = __optional (config , GAPIC_GENERATOR_VERSION , None ),
171
- libraries_bom_version = __optional (config , LIBRARIES_BOM_VERSION , None ),
172
- libraries = parsed_libraries ,
173
- )
174
174
175
- return parsed_config
175
+ return parsed_config
176
176
177
177
178
- def __required (config : dict , key : str , level : str = LIBRARY_LEVEL_PARAMETER ):
178
+ def _required (config : dict , key : str , level : str = LIBRARY_LEVEL_PARAMETER ):
179
179
if key not in config :
180
180
message = (
181
181
f"{ level } , { key } , is not found in { config } in yaml."
@@ -186,7 +186,7 @@ def __required(config: dict, key: str, level: str = LIBRARY_LEVEL_PARAMETER):
186
186
return config [key ]
187
187
188
188
189
- def __optional (config : dict , key : str , default : any ):
189
+ def _optional (config : dict , key : str , default : any ):
190
190
if key not in config :
191
191
return default
192
192
return config [key ]
0 commit comments