Home > Mobile >  Insert an image and preserve the default order of members
Insert an image and preserve the default order of members

Time:02-18

I want to have images after certain methods in Sphinx, what I have:

Foo
============

.. autoclass:: Bar.foo
    :exclude-members: baz

    .. automethod:: baz
    .. image:: ./images/baz_graph.png

The problem is that the order of methods gets mixed up and method baz is now the first one to appear even before __init__ (default order is bysource).

What I want is to insert an image after a method and have that method and the image to go in the bysource order.

CodePudding user response:

There's no way to solve this like you want. Using any .. automethod:: directive inside an .. autoclass:: directive (any directive declared for a member inside the containing outer directive) automatically places that declaration ahead of the remaining automated order options for any of the ordering options and members :member:, undoc-member, :private-members:, etc...

You have to define order somehow, and the :bysource: option imposes one ordering; explicit directive declarations impose an additional ordering that supersedes the former. To order individual members you can mix the former two orderings, but if together the two orderings don't work like you want the only possible ordering that's left is the ordered declaration of directives in the .rst file for each member.

Of course it's convenient to explicitly declare as few members as possible and let the automated options fill in the remaining members... But if you also want to include an image beneath each member your only choice is declaring the inner directives explicitly with an .. image:: directive.

  • Related