-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate the Python stubs automatically #1661
base: master
Are you sure you want to change the base?
Generate the Python stubs automatically #1661
Conversation
44284b9
to
c4766ec
Compare
The generated signature for |
I think |
c4766ec
to
e76a5a8
Compare
Type annotations are now supported by the stub generator. I've introduced a new I've also brought all of the C++-defined docstrings up-to-date with the manual changes and type annotations in the stubs. This should resolve all of the spurious changes. This PR is basically finished now. I'll un-draft it once #1662 is merged and I've rebased this PR onto that (so that this PR's diff is more readable for reviewing). |
Not quite finished yet, but it can generate a Plasma.py that's relatively close to what we currently have in the repo.
Fixes CI errors because of the stub incorrectly indicating that these keyword arguments are required.
7e9ba51
to
a5e144f
Compare
@@ -54,11 +63,11 @@ class PtGameJoinError: | |||
kGameJoinErrAlreadyJoined = 6 | |||
kGameJoinErrNoInvite = 7 | |||
kNumGameJoinErrors = 8 | |||
|
|||
kGameJoinPending = 4294967295 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously this was -1, but I'm guessing it's handled as a uint internally so it keeps the positive value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess a good question is whether a comparison against -1 would ever work in Python, maybe this MAX_UINT32 is the only correct option
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's declared in C++ as kGameJoinPending = (uint32_t)-1
, so it gets output as unsigned.
Also worth noting that I used a 64-bit client to generate the stubs. Plasma's custom EnumValue
s store the numeric value as Py_ssize_t
, so it's possible that a 32-bit client would see this constant as -1
on the Python side. That seems like something we should fix...
Closes #1660. Adds a script to automatically generate the Python "stub" files under Scripts/Python/plasma. The script must be run from the in-game Python console:
This will generate stubs for all Plasma built-in modules into a subfolder "plasma_stubs_generated" under the game folder.
Everything happens fully automatically using runtime introspection. Only one part is "semi-manual": because Python cannot introspect the signatures of C-defined functions, all function parameters must be specified manually in the C++-defined function docstrings, on a line starting with
Params:
. This convention was apparently used by Cyan originally, so most function docstrings already follow this format.The generator itself is almost completely finished, but this PR still needs a bit of work:
Params:
lines in the C++-defined docstrings.Returns:
.With those things in mind, early feedback is welcome. I'm particularly interested in the opinion of @Hoikas, who has recently hand-written some stubs that will be overwritten by this script.