numba: @vectorize-decorated functions are not found by sphinx
- I am using the latest released version of Numba (most recent is visible in the change log (https://github.com/numba/numba/blob/master/CHANGE_LOG).
- I have included below a minimal working reproducer (if you are unsure how to write one see http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports).
I use sphinx with the apidoc extension to have a reference documentation generated automatically.
For functions decorated with njit this works without any complications, for vectorize however, the function disappears from the docs, indicating that apidoc either cannot find it or decides not to include it. (Sorry for the lack of better info).
Since this is sphinx related I am not sure how to include a minimal example, but if it would help and I find some time I can try to set up a mini-repository.
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 28 (15 by maintainers)
Here’s my version of the extension that handles
@guvectorized functions, if anyone’s interested:https://github.com/legend-exp/pygama/blob/f980faa5322aac1de12b5817b1d33c3248e399b5/docs/source/extensions/numbadoc.py
At the moment we are satisfied with how it works. However, I would prefer to understand the flaky behavior, so I will probably bug the people on discourse 😛
Thank you for all your help 😃
Hi Stefano (and others)
I just wanted to give you a heads-up that I won’t be able to follow up on these issues myself for a while, unfortunately. I would like to offer more help, but time is limited at the moment.
I expect documentation to fail without the plugin (as you observed), since Sphinx gets confused by numba’s decorators. I don’t know why you see the flaky behviour in some cases though.
When I first looked into this, I really had to debug the Sphinx autodoc run to see why the documenters did not pick up on the decorated functions, and then I tried to come up with something that would be able to identify the decorated functions as more or less normally documentable objects. Then I used the chance to sprinkle in a few extras, maybe some of that broke over the last years. It is not particularly fun, but maybe a way for follow up investigations.
In the meantime I would encourage you to write on https://numba.discourse.group/ - there is a chance you will be able to get in touch with some knowledgable people who are not aware of this issue / disucussion. Judging by how lively this thread still is, this seems to affect a number of users. Maybe someone has the time and energy to really dive into this and come up with a good and maintainable lonterm solution 😃
Best of luck!
I am buried in other work at the moment, but with the collection as it is, this almost looks as if it might warrant releasing a micro-package that people can install or vendor directly into their codebase. If anyone feels the urge to create such a thing, I would certainly not hold a grudge 😛
Just had a brief look at the issue @gmarkall cross linked yesterday, seems like there are still issues linked to the missing magic wrapper information. Is there a dedicated issue for that?
@HPLegion, thanks for the sphinx extension for autodoc. I tried to change it to work with
autosummary+@intrinsic:Also, in order for this to work, one needs to update the intrinsic wrapper:
I tried adapting the jit-documenter stuff but I couldn’t get it to work. I adopted a solution that I am ashamed of but that works: running this before sphinx 😃
I had some time yesterday and found myself thinking that bending the inner workings of
numbafor the sake ofsphinxmay not be the way to go (even though there may or may not be other advantages to this). So I had a bit of a look for ways to fixing my problem and got inspired bycelery- they are offering a small sphinx extension as part of their package to allow auto-documentation of Celery (decorated) tasks.The advantage to such an approach could be that it actually offers the possibility to customise the documentation behaviour. I hacked together a proof of concept, and it is not too terrifying, luckily Sphinx has a fairly comfortable extension API (but debugging event-driven programs turns out to be a nightmare 😨).
Here is a plaintext example of what could be done in principle. The documenter (see below) adds a prefix (
@numba.vectorize) to the signature and injects information about the precompiled signature into the docstring.Is an extension like this something that could be interesting to feature in numba, or is it just too likely to become a maintenance liability? 😛 (The code as it is right now would likely need some bulletproofing.)
From my side this issue can be closed, since I found a solution that is working for me but if you want to keep this open to track the feature request, that’s fine.
Extension code
(ping @esc )