RBA-stub for external Macro development / "include RBA" in external IDE


I want to write the main parts of my macros with an external IDE (RubyMine in my case), as all the features available there would help make the programming easier.

Is is possible to download "something" such that the IDE can automatically resolve references (include RBA, class Device < PCellDeclarationHelper, param(:var_name, TypeDouble, 'Info Text', default: 1.5, unit: 'µm'))? The code would obviously not be functional when run in the IDE, but I could profit from the integrated functions like bringing up the documentation in the IDE, style tips, auto completion, jump to source of my own methods, etc.

I found the /src/rba/ and /src/rbastub/ sources on Github, but no *.rb files that the IDE would automatically recognize and resolve if placed in the same directory. Unfortunately I don't know much Ruby and C++ to know if or how that could be useful. Any leads are welcome. (I inherited a large Macro file and deciphering spaghetti code is no fun without IDE support)


  • No, you cannot have RBA as external module.

    RBA is not the same as a Ruby module. RBA is an extension of the application and Ruby runs inside the application. The Ruby calls are routed into the application. All RBA functions are coded in C++ and there are no .rb files RubyMine could parse. For the same reason, debugging probably will not be work. I have heard of users however who managed to configure PyCharm to use KLayout as script execution host and who could debug code with PyCharm. The technical details are a miracle, I do not fully understand even having digged deeply into Python's source code.

    KLayout's setup is basically the opposite of what a Ruby module does. For a Ruby module, the Ruby interpreter is the host and the module is sitting inside this process. There can be only one application, and as Qt mandates control over the main process this can only be KLayout's UI application.

    For Python I have separated the application-independent part (at the expense of having to substitute Qt in many places) and published a module on PyPI. But that's just a subset covering database and a few utilities.

    I'm aware of this issue, but there is no common infrastructure which I could use to plug the application in. This is different in a homogenous world like .NET.


  • Hi, Matthias!

    Visual Studio Code allows to specify Python interpreter, so we make our application to behave like Python (supporting -c command-line option to return version information and module execution to run VS Code Python debugger), so it's possible to debug application with built-in Python extensions. Probably same thing could be done for Ruby.

  • Ok, Thank you very much for this detailed answer :)

  • @EugeneZelenko Yes, I'm aware of this option. But how is VS Code attaching the debugger to the application? I mean it needs to be able to tell the Python inside your app to stop at a breakpoint, to fetch stack traces, variable values etc. In some way the IDE needs to attach to the Python process - maybe through sockets or other ways. I'm fairly sure, the application has to be built in a specific way to support this. I'd like to understand these requirements.


  • edited February 23

    Hi, Matthias!

    VS Code run python module that establish connection between IDE and Python process. This is why I wrote about VS Code requirements to Python (or pseudo-Python application). -c is needed to extract Python version and platform (VS Code need to know about that). Running module is to run remote debugger. Server, port and application-specific command-line parameters are passed as command-line parameters to that module.

    See also this discussion, but it is not up-to-date. Major change since that was moving debugger from Python script to module.

    VS Code prints Python command line when launching debug session. So try to debug simple Python script to see what it looks like.

  • edited February 23

    So that's TCP then.

    I wonder if that goes with Qt which runs it's own event loop. Is your own application Qt based as well?

    I have checked with PyCharm and it sends something like "--port ...". I assume VC Studio and PyCharm use the same technology here.

    Anyway, this means I'd need to emulate a Python command line for KLayout. What a fun ...



  • Hi, Matthias!

    We debug Python code in our application only in script mode, so GUI is not initialized.

    You could create wrapper for KLayout that would behave like Python (this would also solve possible conflicting switches), but KLayout still need to support additional command-line parameters. -c and parameter to suppress application's standard output header were necessary development in our case.

Sign In or Register to comment.