From 40dd695cf333d9ea913db60f487ff62f8eb9efc9 Mon Sep 17 00:00:00 2001 From: David Rotermund <54365609+davrot@users.noreply.github.com> Date: Mon, 2 May 2022 01:27:43 +0200 Subject: [PATCH] stub tool --- C++/tools/pybind11_auto_pyi.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 C++/tools/pybind11_auto_pyi.py diff --git a/C++/tools/pybind11_auto_pyi.py b/C++/tools/pybind11_auto_pyi.py new file mode 100644 index 0000000..f316485 --- /dev/null +++ b/C++/tools/pybind11_auto_pyi.py @@ -0,0 +1,27 @@ +# Derived from code by Aaron.Ma +# which was posted here: +# https://blog.csdn.net/sinat_40922660/article/details/123850832 + +# %% +# pip install pybind11-stubgen +from pybind11_stubgen import ModuleStubsGenerator # type: ignore +import glob + + +def process(module_name: str) -> None: + module = ModuleStubsGenerator(module_name) + module.parse() + module.write_setup_py = False + + with open(module_name + ".pyi", "w") as fp: + fp.write("#\n# AUTOMATICALLY GENERATED FILE, DO NOT EDIT!\n#\n\n") + fp.write("\n".join(module.to_lines())) + + +Files = glob.glob("*.so") + +for fid in Files: + Idx: int = fid.find(".") + module_name: str = fid[:Idx] + print("Processing: " + module_name) + process(module_name)