1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15+ import inspect
1516import os
1617import pathlib
17- from typing import List , Optional
18+ from typing import Any , Callable , Dict , List , Optional
1819
19- from .extensions import GenerateCommandExtension
20- from .extensions import load_type_extensions
21- from .extensions import load_typesupport_extensions
20+ from .extensions import GenerateCommandExtension , load_type_extensions , load_typesupport_extensions
2221
2322
2423def generate (
@@ -28,7 +27,8 @@ def generate(
2827 include_paths : Optional [List [str ]] = None ,
2928 output_path : Optional [pathlib .Path ] = None ,
3029 types : Optional [List [str ]] = None ,
31- typesupports : Optional [List [str ]] = None
30+ typesupports : Optional [List [str ]] = None ,
31+ type_description_files : Optional [List [str ]] = None
3232) -> List [List [str ]]:
3333 """
3434 Generate source code from interface definition files.
@@ -59,6 +59,7 @@ def generate(
5959 source code files, defaults to the current working directory
6060 :param types: optional list of type representations to generate
6161 :param typesupports: optional list of type supports to generate
62+ :param type_description_files: Optional list of paths to type description files
6263 :returns: list of lists of paths to generated source code files,
6364 one group per type or type support extension invoked
6465 """
@@ -87,15 +88,39 @@ def generate(
8788 else :
8889 os .makedirs (output_path , exist_ok = True )
8990
90- if len (extensions ) > 1 :
91- return [
91+ def extra_kwargs (func : Callable , ** kwargs : Any ) -> Dict [str , Any ]:
92+ matched_kwargs = {}
93+ signature = inspect .signature (func )
94+ for name , value in kwargs .items ():
95+ if name in signature .parameters :
96+ if signature .parameters [name ].kind not in [
97+ inspect .Parameter .POSITIONAL_ONLY ,
98+ inspect .Parameter .VAR_POSITIONAL ,
99+ inspect .Parameter .VAR_KEYWORD
100+ ]:
101+ matched_kwargs [name ] = value
102+ return matched_kwargs
103+
104+ generated_files = []
105+ if len (extensions ) == 1 :
106+ extension = extensions [0 ]
107+ generated_files .append (
92108 extension .generate (
93109 package_name , interface_files , include_paths ,
94- output_path = output_path / extension .name )
95- for extension in extensions
96- ]
97-
98- return [extensions [0 ].generate (
99- package_name , interface_files ,
100- include_paths , output_path
101- )]
110+ output_path = output_path ,
111+ ** extra_kwargs (extension .generate , type_description_files = type_description_files )
112+ )
113+ )
114+ else :
115+ for extension in extensions :
116+ generated_files .append (
117+ extension .generate (
118+ package_name , interface_files , include_paths ,
119+ output_path = output_path / extension .name ,
120+ ** extra_kwargs (
121+ extension .generate ,
122+ type_description_files = type_description_files
123+ )
124+ )
125+ )
126+ return generated_files
0 commit comments