IDE integration/autocompletion for embedded modules #4667
Replies: 1 comment
-
At least I have the same issue. import rlcompleter
import readline
import code
readline.parse_and_bind("tab: complete")
code.interact(local=dict(globals(), **locals())) Currently this works as a charm, but nevertheless the tab completion nor the code proposals work for PYBIND11_EMBEDDED_MODULE's. For the normal builtin modules or other modules they work properly. Digging around in the internet also didn't bring a solution sadly. |
Beta Was this translation helpful? Give feedback.
-
You could write, manually, a .pyi file (called stubs) that is essentially a file where you declare classes, methods etc... without the definition, and it acts as a "proxy" for the autocompletion in the IDE. They are used by many python packages which have their source as C/C++ code. In each function declaration, you need to add a triple dot after the colon so that python understand it is just a definition and it should only read it as is. One example: # mymodule.pyi
class MyClass():
def __init__(self, arg: str) -> None:...
def myMethod(self, arg1: int, arg2: int) -> int:... |
Beta Was this translation helpful? Give feedback.
-
Hi there. First of all, i really love this library, i am astonished about what you can do with it and how easy everything it!
But i have a question. I hope this is the right place to ask.
Consider following use case: I have a C++ program that is a solid application framework, and it uses python as a scripting language by the use of Embedded Modules, so you define variables and functions in C++ and then you can call them from a python script without recompiling the app.
Example module:
But there is a minor inconvenience: The IDE has no notion of the embedded module.
Is it somehow possible to "export" a definition of the embedded module such that an IDE like vscode or CLion knows what functions are available? In the best case you would write the C++ definition once and compile or run once, and then you have IDE suggestion.
Maybe some kind of configuration file that is written to the build folder at compile time or on first run, and is parsed by the IDE to give suggestions? Or if everything else fails, a custom vscode extension that runs the app and scans and exports the module? Is something like that a thing or is it insane to ask?
Thank you for any help!
Beta Was this translation helpful? Give feedback.
All reactions