Auto-generating the Plasma Python stubs #1660
Replies: 2 comments 6 replies
-
I'm not aware of any code to do this, and even the random bits of PythonLib that were included in the original source release don't seem to have anything like that. Getting these to be autogenerated would be cool. I know in some cases we've added type annotations manually as well, but I'm not sure if those can be known by a runtime generator? It would be very cool if we had proper type annotations for everything. |
Beta Was this translation helpful? Give feedback.
-
Update: I had a go at writing a stub generator and it went quite well - I can now run a single call in the Python console to generate a Plasma.py that's pretty close to what we have currently in the repo. As expected, there are a number of missing/outdated declarations and lots of small inconsistencies that have accumulated over time. I'll make a PR to address those soon. I haven't yet looked into how we can handle type annotations. My current implementation loses them all, but that's because they're missing from the C++-defined docstrings. Once I fix that, type annotations should work too. |
Beta Was this translation helpful? Give feedback.
-
I'm talking about the .py files under Scripts/Python/plasma (Plasma.py, PlasmaConstants.py, etc.) that show which modules and APIs are defined by the engine in C++. These stubs look like they were automatically generated based on the C++ definitions at some point in the past, but now we seem to be updating them manually whenever the C++-defined APIs change.
Does anyone know if the code to automatically generate these stubs exists somewhere? Or was that lost to time and/or never open-sourced?
If we don't have anything like that yet/anymore, I might try to build a generator for the stubs. It seems like all the necessary information is available at runtime in the in-game Python environment, so it should be possible to write the generator as a script/function that can be run from an internal client's Python console.
Right now, the stubs have a few random mistakes/inconsistencies that I occasionally stumble across (whenever my IDE complains that the Python scripts are calling functions "incorrectly"). Auto-generating the stubs would hopefully help with that.
Beta Was this translation helpful? Give feedback.
All reactions