Files
rdkit/Scripts/patch_rdkit_docstrings/clang_worker.py
Paolo Tosco 2b4202867e Add Python modules to generate stubs and automatically patch docstrings (#6919)
* - added gen_rdkit_stubs Python module to generate rdkit-stubs
- added patch_rdkit_docstrings Python module to patch existing C++ sources to fix docstrings missing self parameter and add named parameters taken from C++ signatures where possible
- added rdkit-stubs/CMakeLists.txt to build rdkit-stubs as part of the RDKit build
- added an option to CMakeLists.txt to enable building rdkit-stubs as part of the RDKit build (defaults to OFF)

* fixed CMakeLists.txt, rdkit-stubs/CMakeLists.txt and a doctest

* - added missing cmp_func parameter
- fixed case with overloads with optional parameters
- do not trim params if expected_param_count == -1
- add dummy parameter names if we could not find any
- keep into account member functions when making up parameter names
- address __init__ and make_constructor __init__ functions
- fix incorrectly assigned staticmethods

* patched sources

* address residual few remarks

---------

Co-authored-by: ptosco <paolo.tosco@novartis.com>
2023-11-30 04:54:18 +01:00

46 lines
1.3 KiB
Python

#!/usr/bin/env python
"""
clang_worker script.
Each worker is a daemon listening for input on stdin
and generating output on stdout.
"""
import sys
import os
import importlib
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
patch_rdkit_docstrings = importlib.import_module("patch_rdkit_docstrings")
CppFile = patch_rdkit_docstrings.CppFile
ClangWorkerData = patch_rdkit_docstrings.ClangWorkerData
class MainLoop:
"""Main worker class.
The loop breaks once there is no more input to read from stdin.
"""
def __init__(self, clang_worker_data):
self.clang_worker_data = clang_worker_data
def run(self):
while 1:
line = sys.stdin.readline().strip()
if not line:
break
cpp_class_file_json = line.strip()
cpp_class_file = CppFile.from_json(cpp_class_file_json)
res = cpp_class_file.generate_ast(self.clang_worker_data.clang_flags)
if res:
cpp_class_file.parse_ast(self.clang_worker_data.arg1_func_byclass_dict)
sys.stdout.write(cpp_class_file.to_json() + "\n")
sys.stdout.flush()
sys.stdout.write("\n")
sys.stdout.flush()
if __name__ == "__main__":
clang_worker_data = ClangWorkerData.from_json(sys.argv[1])
main_loop = MainLoop(clang_worker_data)
main_loop.run()