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 args = arg_parser.parse_args()
69 top_module_namespaces = args.top_module_namespaces.split(
"::")
70 if top_module_namespaces[0]:
71 top_module_namespaces = [
''] + top_module_namespaces
73 with open(args.template,
"r", encoding=
"UTF-8")
as f:
74 template_content = f.read()
77 module_name=args.module_name,
78 use_boost_serialization=args.use_boost_serialization,
79 top_module_namespaces=top_module_namespaces,
80 ignore_classes=args.ignore,
81 module_template=template_content,
85 wrapper.wrap_submodule(args.src)
89 sources = args.src.split(
';')
90 wrapper.wrap(sources, args.out)
93 if __name__ ==
"__main__":