Files
revng-revng/scripts/nanobind_generate_stubs.py
Giacomo Vercesi 688b9fe111 Introduce compatibility with revng-pypeline
Add the necessary machinery to allow `Pipe`s, `Analysis`es,
`Container`s, `Model` and `ObjectID` to be implemented in C++ and used
by Python.
2025-09-17 14:02:40 +02:00

42 lines
933 B
Python
Executable File

#!/usr/bin/env python3
#
# This file is distributed under the MIT License. See LICENSE.md for details.
#
import argparse
import sys
from nanobind.stubgen import StubGen
from revng.internal.support import import_pipebox
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-o", "--output", help="Output file (stdout if omitted)")
parser.add_argument(
"-l",
"--library",
default=[],
action="append",
help="Shared library to preload before generating stubs",
)
args = parser.parse_args()
module, handles = import_pipebox(args.library)
stub_gen = StubGen(module, quiet=False)
stub_gen.put(module)
stub_text = stub_gen.get()
if args.output is None:
sys.stdout.write(stub_text)
sys.stdout.flush()
else:
with open(args.output, "w") as f:
f.write(stub_text)
if __name__ == "__main__":
main()