1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15+ import inspect
1516import os
1617import pathlib
1718
18- from .extensions import load_type_extensions
19- from .extensions import load_typesupport_extensions
19+ from .extensions import load_type_extensions , load_typesupport_extensions
2020
2121
2222def generate (
@@ -26,7 +26,8 @@ def generate(
2626 include_paths = None ,
2727 output_path = None ,
2828 types = None ,
29- typesupports = None
29+ typesupports = None ,
30+ type_description_files = None
3031):
3132 """
3233 Generate source code from interface definition files.
@@ -57,6 +58,7 @@ def generate(
5758 source code files, defaults to the current working directory
5859 :param types: optional list of type representations to generate
5960 :param typesupports: optional list of type supports to generate
61+ :param type_description_files: Optional list of paths to type description files
6062 :returns: list of lists of paths to generated source code files,
6163 one group per type or type support extension invoked
6264 """
@@ -85,15 +87,39 @@ def generate(
8587 else :
8688 os .makedirs (output_path , exist_ok = True )
8789
88- if len (extensions ) > 1 :
89- return [
90+ def extra_kwargs (func , ** kwargs ):
91+ matched_kwargs = {}
92+ signature = inspect .signature (func )
93+ for name , value in kwargs .items ():
94+ if name in signature .parameters :
95+ if signature .parameters [name ].kind not in [
96+ inspect .Parameter .POSITIONAL_ONLY ,
97+ inspect .Parameter .VAR_POSITIONAL ,
98+ inspect .Parameter .VAR_KEYWORD
99+ ]:
100+ matched_kwargs [name ] = value
101+ return matched_kwargs
102+
103+ generated_files = []
104+ if len (extensions ) == 1 :
105+ extension = extensions [0 ]
106+ generated_files .append (
90107 extension .generate (
91108 package_name , interface_files , include_paths ,
92- output_path = output_path / extension .name )
93- for extension in extensions
94- ]
95-
96- return [extensions [0 ].generate (
97- package_name , interface_files ,
98- include_paths , output_path
99- )]
109+ output_path = output_path ,
110+ ** extra_kwargs (extension .generate , type_description_files = type_description_files )
111+ )
112+ )
113+ else :
114+ for extension in extensions :
115+ generated_files .append (
116+ extension .generate (
117+ package_name , interface_files , include_paths ,
118+ output_path = output_path / extension .name ,
119+ ** extra_kwargs (
120+ extension .generate ,
121+ type_description_files = type_description_files
122+ )
123+ )
124+ )
125+ return generated_files
0 commit comments