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
Automatically generate typing stubs #16
Conversation
Oh wow, very nice.
I think that's sensible, obvious what it is without making noise.
Everything you need should be in the existing powershell file, most of it is pretty printing things to make the logs more approachable.
If it remains a mystery, just leave it and I'll take a look at it.
In order to use them, they'll need to eventually end up on PYTHONPATH right? I haven't used .pyi files before, but that would make sense. In that case, building them alongside the Here's where files are extracted from each build: cmdc/.github/workflows/main.yml Line 77 in edca428
Not sure, maybe @yantor3d knows more? |
Yeah, they're only relevant in your editor, they don't get use at runtime at all as far as I know. |
I just added the stubs generation in The checks currently fail for windows because we need to install |
The docstrings in the *.inl files are scraped from the devkit headers, so any type declarations in them may not agree with the Python binding method signatures. |
So nothing relies on them right? |
Nothing relies on them. Will the stubs provide docstrings instead? |
Ah sorry I meant removing the function signature out of the docstrings, not completely removing the docstrings. The stubs generation relies on what's in the The issue I'm having is that if a signature is specified in the docstring, it takes over the actual signature and ends up being the one in the stubs which might lead to inconsistent and outdated signatures. The stubs file contains 2 things:
|
Ah, I see what you mean. MSelectionList has some methods signatures baked into its docstrings. Only 22 though, so I feel like we can remove then by hand, and then update the |
Yeah that sounds like a plan, I'll do that sometime this week |
@mottosso I feel like we're getting there, I'm just not sure how to make the CICD work now |
Maya isn't available to CI at the moment, only regular Python with the Maya devkit. Do we need it? We'll need it to run the tests and I've been meaning to add it anyway. Could get that underway this weekend. |
Ah I assumed it was, that tracks. Pybind11-stubgen needs to import cmdc and as far as I know that can only work from mayapy |
Cool, I'll add it to CI this weekend, then you can merge that into here to test it out. |
Done. It's all yours. |
d491969
to
aa969ff
Compare
I've just added Edit: Looks like it worked on Linux, I haven't added the stubs generation there so that makes sense. Edit 2: Oooh and the bindings get built before the test environment is setup, I didn't consider that. |
A Linux user could be forgiven for not having access to Windows, but Windows users these days have no excuse haha. xD You've got both WSL, Docker, Virtual Box and VMWare Player. All free options. In my case, I do this on Windows. # From PowerShell
cd cmdc
docker run -ti --rm -v ${pwd}:/workdir mottosso/maya:2020
cd /workdir From there you could literally run what the CI is running to recreate it verbatim. # Setup Build Environment
yum install centos-release-scl -y
yum install devtoolset-7 bc -y
# Build
export DEVKIT_LOCATION=$(pwd)/devkitBase
. scl_source enable devtoolset-7 || true
g++ --version
chmod +x ./build_linux.sh
./build_linux.sh 2020 When you cd mycontainer
echo "My Container" > Dockerfile
docker build -t mycontainer .
docker run -ti --rm -v ${pwd}/workdir mycontainer
$ # Same environment each time Alternatively, you could keep updating that |
For completeness, anything under |
Haha I haven't thought of that. I've been meaning to learn Docker for a while, that's a good opportunity to do that Thanks for all the info, that'll be helpful 👍 |
Once you pop, you can't stop. :) Docker is a game changer. That command for mayapy above can also be used to spawn any of the last releases of Maya of the past 8 years. Try some more "tags" from here: https://github.com/mottosso/docker-maya |
So I looked a bit more into this today, I'm not 100% when we should generate the stubs in the process. I have two questions:
One note on the generated stubs: |
I should think so. Maya 2022 would have everything past versions have, so if anything 2022 is the ideal choice. Although, maybe it would also give you hints about arguments that only exists since 2022, such as If Python 3 is what it needs, then it is how it is. Unless it doesn't need mayapy at all?
I would have thought they could run right after the Python tests, like just another set of commands? The trouble with giving them their own job is that we then need to pass the build artifacts from one job to another along with setting up the dependency. Jobs are basically running on different machines. How about just another block following this one? cmdc/.github/workflows/main.yml Lines 165 to 171 in 8345f79
Sounds bad, but maybe it's good enough for a first pass? This kind of thing doesn't seem to care much for backwards compatibility. Would like to merge this PR to take many small steps soon in favour of one large perfect step later. |
Wouldn't that make it run on every maya version in the
Yeah agreed. I should have something ready by next weekend I think. |
There is yeah, there's another step with one you can look at for reference. Next step is looking at the GitHub Actions docs.
I'm not sure. :S It's perfectly capable of building cmdc without mayapy, so it seems logical that we'd be able to inspect the results without it. But what it's asking for are some of the DLLs that ship with Maya.. So then at least, if necessary, we could just bundle these with this repo and avoid having to call into Maya at all. |
Ah, looks like I didn't write the condition to generate the stubs properly haha There's one very annoying with pybind11-stubgen, it can completely freeze in some cases Some function stubs result in something like: This happens when pybind11 generates a docstring with a syntax error in the signature
In most this is because the return (or argument) type is not declared as a binding before. Declaring it in There's also this issue :
In this case On a final note, specifying the arguments with Also, I have absolutely no idea why the tests failed on Maya 2018 there. |
Sigh, sadly no. This is typical CI. I've stopped worrying about it, just keep pushing commits. If you're feeling self-concious, I've found that you can overwrite a commit and force-push to trigger a new build without making a mark in git history.
This, my friend, is why cmdc needs to exist. This is a crash. From not doing anything in particular. The API is riddled with these, exactly what we need to protect against, and you've just found the first one for cmdc. Congratulations! 🥳 How?
|
I'll have a look at the crash yeah I'm surprised it doesn't crash in master though, I don't think I've touched the implementation of anything, unless I've messed up the merge somehow, will dig more tonight 👍 |
Cool so this seems to work so far, I've uploaded the stubs along with the Maya 2022 module, meaning in the release they'll only be in the There's a lot that can be done to improve the quality of the stubs, mainly adding Lines 221 to 222 in 86cc176
That's probably better suited for a second PR though so I'm happy to merge this one now That Maya 2018 crash is also just gone and I haven't managed to reproduce it on my end |
Where do they need to be? Is it also on PYTHONPATH? Simplest thing you can try is downloading the latest release and putting your stubs wherever they belong and make sure it works wherever it needs to work. I've never used stubs so I'm not too familiar with what goes into it. Come to think of it, they should appear in the next release too so let me merge and then you can continue experimenting with the real thing. Do we want these in any way related to Maya? Like, in Maya's PYTHONPATH too? Or are they completely separate from the cmdc
But that would only make sense if Maya is consuming them. Anyway, I'll leave this to you! |
Looks like they made it. https://github.com/mottosso/cmdc/releases/tag/v0.1.4 One option is simply copying the single cmdc/.github/workflows/main.yml Lines 250 to 253 in 86cc176
|
The stubs are never really useful in maya, they're meant for your editor to give you nice autocompletion, typing information, etc. Once generated the stubs don't need the .pyd files at all, I think some libraries even just publish their stubs independently on pypi. In our case, I feel like something along those lines would make sense
I'll start another PR that tackles all the ugly |
Sounds good! |
This PR enables generating typing stubs for cmdc automatically.
This is still WIP and I'm not really happy with the organization of everything yet, I'm open to any ideas there.
To generate the stubs:
mayapy scripts/generate_typing_stubs.py
PYTHONPATH
pybind11-stubgen
needs to be installed in mayapySome notes:
I've put that the forward declarations in
ForwardDeclarations.inl
. I don't know if there's a better way to do that.build
directory, not sure if that's where they should be saved.pybind11-stubgen does take those into account and some weren't valid (
(string, string, ...)
instead ofList[str]
) so I've updated those.