Ctags parse header
So, I went down a rabbit hole...
parse_header.py was failing on some header files required for #25.
I tried upgrading it but didn't feel like handling a billion edge cases like manually parsing C++ seems to be like
I ended up relying on Universal Ctags which outputs a list of all the classes, methods, etc. that are in a given file.
It's not perfect but it works on all the files I've tested so far
Some things that are not supported yet:
- Functions declared out of the scope of a class
- Properties
- Nested classes
- Enums
I'll probably leave it at that for this PR though and we can improve on that as we need.
I've made a separate parse_header_ctags.py script in case parse_header.py still produces better results on some files
And of course, ctags needs to be installed and available in your path
ctags? Interesting. :) I might use this for other things too, didn't know this existed.
Can you give some examples of what it failed on before, and what it looks like now?
the current parse_header script fails to generate the inl file for MPxNode with this stack trace:
Traceback (most recent call last):
File "scripts\parse_header.py", line 534, in <module>
main()
File "scripts\parse_header.py", line 524, in main
parse_header(opts.header)
File "scripts\parse_header.py", line 181, in parse_header
arguments)
File "scripts\parse_header.py", line 325, in parse_method
raise RuntimeError("Cannot parse signature: {}".format(signature))
RuntimeError: Cannot parse signature: MDataBlock _forceCache () { return forceCache(); } void _setDoNotWrite ( bool flag ) { setDoNotWrite(flag); } bool _doNotWrite () { return doNotWrite
I won't paste the generated file of parse_header_ctags here because it's 650 lines long but it works.
The file won't compile out of the box though as some types like PostEvaluationType should be MPxNode::PostEvaluationType and possibly a few more things to clean up.
Running it against classes like MDagPath produces files that compile directly, however.
One thing to note: I'm only including methods that exist in maya.OpenMaya because ctags would list a lot more things including private methods. This felt like a sensible way to filter all that out but I'm not 100% sure if maya.OpenMaya has 100% parity with the C++ API.
I'm not 100% sure if maya.OpenMaya has 100% parity with the C++ API.
It's lacking a ton of stuff, so it won't get us all the way there. But if it helps.. But, why do we need to involve maya.OpenMaya here at all? :O Sorry I haven't looked more closely at the contents of this PR yet. But I would have thought all we need are the C++ headers? If we can use maya.OpenMaya, could we not fetch members and argument signatures directly from there via Python?
haha That was my quick way of filtering out some garbage that ctags was picking up on, I thought maya.OpenMaya was feature complete. I can definitely remove that filter and see where that takes us 👍 I know ctags was confused on things like the OPENMAYA_DEPRECATED statements and a few other things that are in the header files