3

I have python classes and some of them are in their own files

i.e. userdata.py:

class userdata:
    """User input class for reading..."""

    def __init__(self, fname):
        self.fname = fname        


    def trykey(self,name,injson):
....

I have tried multiple methods to be able to refer to a specific method in that class in the documentation, but it did not work.

I am generating autodoc via command

sphinx-apidoc 

It only generates modules for the code above

_lib.io package
=====================

Submodules
----------

.. toctree::

   lib.io.userdata

Module contents
---------------

.. automodule:: lib.io
    :members:
    :undoc-members:
    :show-inheritance:

Similar problem for modules with multiple classes i.e. ad1.py

class inner1(inherited)
....
class inner2(inherited)
....def
....

autodoc:

_lib.ad.ad1 module
===========================================

.. automodule:: lib.ad.ad1
    :members:
    :undoc-members:
    :show-inheritance:

Is there a way to get autoclass and automethod automatically generated as well.

mzjn
  • 48,958
  • 13
  • 128
  • 248
user2375049
  • 350
  • 2
  • 15
  • Note that sphinx-apidoc only generates `automodule` directives. If you want to use `autoclass` or `autofunction`, you have to add these directives by hand. In order to understand exactly what your problem is, we need more details (preferably in the form of a [mcve]). – mzjn Nov 18 '18 at 08:42
  • ok then the answer is no as far as i understand. thank you – user2375049 Nov 18 '18 at 08:55
  • You don't *have* to use `autoclass` or `automethod`. Using only `automodule` should work. – mzjn Nov 18 '18 at 15:49
  • @mzjn Do you say it is possible to use `automodule` only, to show the class docstrings of every class within a module? And the same for the functions defined in the module? – Ecuashungo Mar 18 '20 at 16:13
  • @Ecuashungo: Yes, that is what I mean. But there are cases when `autoclass` or `autofunction` are needed. – mzjn Mar 18 '20 at 19:14
  • @mzjn Interesting! I haven't figured out how to do that yet. Do I have to use a specific option below `.. automodule:: module_name`? Or how would that be done? – Ecuashungo Mar 19 '20 at 08:10
  • 1
    @Ecuashungo You should add the `:members:` option. https://www.sphinx-doc.org/en/stable/usage/extensions/autodoc.html?highlight=autodoc#directive-automodule – mzjn Mar 19 '20 at 08:20
  • I tried to follow this thread but I still don't understand how to automatically document all classes without explicitly specifying them in the `index.rst` file with the `autoclass` directive. I tried without but that gives no class documentation at all. And the Sphinx documentation says autodoc is only semi-automatic. So it seems to me @mzjn is wrong about that it "should work". – Christian Brolin Sep 15 '20 at 11:42
  • @ChristianBrolin: To document all members in a module, use `automodule`. To document all classes in a module using `autoclass`, you need one `autoclass` directive per class. – mzjn Sep 17 '20 at 06:56

0 Answers0