NetLogo / Python-Extension

Python extension for NetLogo
26 stars 15 forks source link

Refactor to use lang-extension-lib #21

Closed JamesHovet closed 2 years ago

JamesHovet commented 2 years ago

In short, this PR:

Background: The python extension has and continues to work by passing messages to a python sub process over localhost network calls. It was identified that the logic for creating these subprocess and passing serialized messages between them was independent of anything Python Specific and could just as easily apply to other languages. In an effort to make developing language interoperability extensions for NetLogo easier, the decision was made to separate this plumbing code into a separate library.

What is included in this PR: I undertook this task and extracted much of the code that was originally in this repo into a new library https://github.com/NetLogo/NetLogoExtensionLanguageServerLibrary. In so doing, I refactored it significantly and added the two features mentioned above. Since these features are part of the library code, they can be utilized by other language extensions at basically no cost.

Division of responsability between the library and extension code proper: The extension has to provide the library with one main thing: an executable or a script that can listen for messages sent on a given port and translate them into eval-able statements. For the python extension, this script is pyext.py. That script listens on a localhost socket for messages that tell it what code to eval and then sends it back. Most everything else that the extension code itself has to do is boilerplate. Read the documentation of the library code for more.

qiemem commented 2 years ago

Hey just want say, as the original author of this extension, this looks super rad and I'm really excited this work happening. Feel free to reach out to me if you have any questions or anything, though glancing through the code, it looks like you've already figured it all out!