3 Helper script to wrap C++ to Python with Pybind.
4 This script is installed via CMake to the user's binary directory
5 and invoked during the wrapping by CMake.
17 arg_parser = argparse.ArgumentParser(
18 formatter_class=argparse.ArgumentDefaultsHelpFormatter)
19 arg_parser.add_argument(
"--src",
22 help=
"Input interface .i/.h file(s)")
23 arg_parser.add_argument(
27 help=
"Name of the Python module to be generated and "
28 "used in the Python `import` statement.",
30 arg_parser.add_argument(
34 help=
"Name of the output pybind .cc file(s)",
36 arg_parser.add_argument(
37 "--use-boost-serialization",
39 help=
"Allow boost based serialization methods",
41 arg_parser.add_argument(
42 "--top_module_namespaces",
45 help=
"C++ namespace for the top module, e.g. `ns1::ns2::ns3`. "
46 "Only the content within this namespace and its sub-namespaces "
47 "will be wrapped. The content of this namespace will be available at "
48 "the top module level, and its sub-namespaces' in the submodules.\n"
49 "For example, `import <module_name>` gives you access to a Python "
50 "`<module_name>.Class` of the corresponding C++ `ns1::ns2::ns3::Class`"
51 "and `from <module_name> import ns4` gives you access to a Python "
52 "`ns4.Class` of the C++ `ns1::ns2::ns3::ns4::Class`. ",
54 arg_parser.add_argument(
58 help=
"A space-separated list of classes to ignore. "
59 "Class names must include their full namespaces.",
61 arg_parser.add_argument(
"--template",
63 help=
"The module template file (e.g. module.tpl).")
64 arg_parser.add_argument(
"--is_submodule",
67 arg_parser.add_argument(
"--xml_source",
70 help=
"The path to the Doxygen-generated XML documentation")
71 args = arg_parser.parse_args()
73 top_module_namespaces = args.top_module_namespaces.split(
"::")
74 if top_module_namespaces[0]:
75 top_module_namespaces = [
''] + top_module_namespaces
77 with open(args.template,
"r", encoding=
"UTF-8")
as f:
78 template_content = f.read()
81 module_name=args.module_name,
82 use_boost_serialization=args.use_boost_serialization,
83 top_module_namespaces=top_module_namespaces,
84 ignore_classes=args.ignore,
85 module_template=template_content,
86 xml_source=args.xml_source,
90 wrapper.wrap_submodule(args.src)
94 sources = args.src.split(
';')
95 wrapper.wrap(sources, args.out)
98 if __name__ ==
"__main__":