4 Helper script to wrap C++ to Python with Pybind. 5 This script is installed via CMake to the user's binary directory 6 and invoked during the wrapping by CMake. 20 arg_parser = argparse.ArgumentParser(
21 formatter_class=argparse.ArgumentDefaultsHelpFormatter)
22 arg_parser.add_argument(
26 help=
"Input interface .i/.h file")
27 arg_parser.add_argument(
31 help=
"Name of the Python module to be generated and " 32 "used in the Python `import` statement.",
34 arg_parser.add_argument(
38 help=
"Name of the output pybind .cc file",
40 arg_parser.add_argument(
43 help=
"using boost's shared_ptr instead of std's",
45 arg_parser.add_argument(
46 "--top_module_namespaces",
49 help=
"C++ namespace for the top module, e.g. `ns1::ns2::ns3`. " 50 "Only the content within this namespace and its sub-namespaces " 51 "will be wrapped. The content of this namespace will be available at " 52 "the top module level, and its sub-namespaces' in the submodules.\n" 53 "For example, `import <module_name>` gives you access to a Python " 54 "`<module_name>.Class` of the corresponding C++ `ns1::ns2::ns3::Class`" 55 "and `from <module_name> import ns4` gives you access to a Python " 56 "`ns4.Class` of the C++ `ns1::ns2::ns3::ns4::Class`. ",
58 arg_parser.add_argument(
62 help=
"A space-separated list of classes to ignore. " 63 "Class names must include their full namespaces.",
65 arg_parser.add_argument(
"--template", type=str,
66 help=
"The module template file")
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
74 with open(args.src,
"r") as f: 77 module = parser.Module.parseString(content) 78 instantiator.instantiate_namespace_inplace(module) 80 with open(args.template, "r") as f: 81 template_content = f.read() 85 module_name=args.module_name, 86 use_boost=args.use_boost, 87 top_module_namespaces=top_module_namespaces, 88 ignore_classes=args.ignore, 89 module_template=template_content, 93 cc_content = wrapper.wrap()
96 with open(args.out,
"w")
as f:
100 if __name__ ==
"__main__":