Source code for symforce.codegen.backends.python.generate_module_init
# ----------------------------------------------------------------------------# SymForce - Copyright 2022, Skydio, Inc.# This source code is under the Apache 2.0 license found in the LICENSE file.# ----------------------------------------------------------------------------importfunctoolsimportoperatorfromsymforceimporttypingasTfromsymforce.codegen.backends.python.python_configimportPythonConfigfromsymforce.codegen.codegenimportCodegenfromsymforce.codegen.codegenimportGeneratedPathsfromsymforce.codegen.template_utilimportRenderTemplateConfigfromsymforce.codegen.template_utilimportrender_template
[docs]defgenerate_module_init(codegen_objects:T.Iterable[Codegen],generated_paths:T.Iterable[GeneratedPaths],template_config:RenderTemplateConfig=RenderTemplateConfig(),)->None:""" Generate an __init__.py for a directory of generated functions that imports all the functions for convenience Args: specs: The Codegen objects for the generated functions generated_pathses: The generated paths for the functions, returned by Codegen.generate_function template_config: The configuration for rendering the template """ifnotfunctools.reduce(operator.eq,(paths.function_dirforpathsingenerated_paths)):raiseValueError("All generated paths must have the same function directory")render_template(template_path="function/module_init.py.jinja",data={"specs":codegen_objects},config=template_config,template_dir=PythonConfig.template_dir(),output_path=next(iter(generated_paths)).function_dir/"__init__.py",)