Source code for symforce.codegen.sym_util_package_codegen
# ----------------------------------------------------------------------------# SymForce - Copyright 2022, Skydio, Inc.# This source code is under the Apache 2.0 license found in the LICENSE file.# ----------------------------------------------------------------------------importtempfilefrompathlibimportPathimportsymforce.symbolicassffromsymforceimportcodegenfromsymforceimportloggerfromsymforceimportpython_utilfromsymforceimporttypingasTfromsymforce.codegenimporttemplate_util
[docs]defgenerate(config:codegen.CodegenConfig,output_dir:T.Optional[Path]=None)->Path:""" Generate the sym util package for the given language. """# Create output directory if neededifoutput_dirisNone:output_dir=Path(tempfile.mkdtemp(prefix=f"sf_codegen_{type(config).__name__.lower()}_",dir="/tmp"))logger.debug(f"Creating temp directory: {output_dir}")# Subdirectory for everything we'll generatepackage_dir=output_dir/"sym"/"util"templates=template_util.TemplateList()ifisinstance(config,codegen.CppConfig):template_dir=config.template_dir()templates.add(template_path="typedefs.h.jinja",output_path=package_dir/"typedefs.h",data={},config=config.render_template_config,template_dir=template_dir,)templates.add(template_path="type_ops.h.jinja",output_path=package_dir/"type_ops.h",data=dict(python_util=python_util,sf=sf,),config=config.render_template_config,template_dir=template_dir,)forfilenamein("epsilon.h","epsilon.cc"):templates.add(template_path=f"{filename}.jinja",output_path=package_dir/filename,data={},config=config.render_template_config,template_dir=template_dir,)else:# sym/util is currently C++ onlypasstemplates.render()returnoutput_dir