pybind_wrap.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 """
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.
6 """
7 
8 # pylint: disable=import-error
9 
10 import argparse
11 
12 from gtwrap.pybind_wrapper import PybindWrapper
13 
14 
15 def main():
16  """Main runner."""
17  arg_parser = argparse.ArgumentParser(
18  formatter_class=argparse.ArgumentDefaultsHelpFormatter)
19  arg_parser.add_argument("--src",
20  type=str,
21  required=True,
22  help="Input interface .i/.h file(s)")
23  arg_parser.add_argument(
24  "--module_name",
25  type=str,
26  required=True,
27  help="Name of the Python module to be generated and "
28  "used in the Python `import` statement.",
29  )
30  arg_parser.add_argument(
31  "--out",
32  type=str,
33  required=True,
34  help="Name of the output pybind .cc file(s)",
35  )
36  arg_parser.add_argument(
37  "--use-boost-serialization",
38  action="store_true",
39  help="Allow boost based serialization methods",
40  )
41  arg_parser.add_argument(
42  "--top_module_namespaces",
43  type=str,
44  default="",
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`. ",
53  )
54  arg_parser.add_argument(
55  "--ignore",
56  nargs='*',
57  type=str,
58  help="A space-separated list of classes to ignore. "
59  "Class names must include their full namespaces.",
60  )
61  arg_parser.add_argument("--template",
62  type=str,
63  help="The module template file (e.g. module.tpl).")
64  arg_parser.add_argument("--is_submodule",
65  default=False,
66  action="store_true")
67  arg_parser.add_argument("--xml_source",
68  type=str,
69  default="",
70  help="The path to the Doxygen-generated XML documentation")
71  args = arg_parser.parse_args()
72 
73  top_module_namespaces = args.top_module_namespaces.split("::")
74  if top_module_namespaces[0]:
75  top_module_namespaces = [''] + top_module_namespaces
76 
77  with open(args.template, "r", encoding="UTF-8") as f:
78  template_content = f.read()
79 
80  wrapper = PybindWrapper(
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,
87  )
88 
89  if args.is_submodule:
90  wrapper.wrap_submodule(args.src)
91 
92  else:
93  # Wrap the code and get back the cpp/cc code.
94  sources = args.src.split(';')
95  wrapper.wrap(sources, args.out)
96 
97 
98 if __name__ == "__main__":
99  main()
gtwrap.pybind_wrapper.PybindWrapper
Definition: pybind_wrapper.py:24
pybind_wrap.main
def main()
Definition: pybind_wrap.py:15
gtwrap.pybind_wrapper
Definition: pybind_wrapper.py:1


gtsam
Author(s):
autogenerated on Fri Mar 28 2025 03:03:12