Python generate documentation using pydoc

54 Views Asked by At

I have nested folder structure library and the question is about generating documentation from the source-code files.

Folder Structure

  mylib
    ├── foo 
          ├── __init__.py
    │     ├── Foo.py
    ├── bar
    │     ├── __init__py
    │     ├── Bar.py
    ├── baz
    │   ├── qux
    │   │   ├── file1.py
    │   │   ├── file2.py
    │   │   ├── file3.py
    │   │   ├── file4.py
    │   │   ├── file5.py
    │   │   └── __init__.py

Documentation

I was looking for a built-in solution (without downloading 3rd party plugins) to generate documentation for the python library and came across pydoc

Documentation: https://docs.python.org/3/library/pydoc.html

from the documentation I rant this source file

python3 -m pydoc mylib

Issue:

I have only one file generated mylib that lists 3 sub-directories as links

Code

as per the request, here's a sample of code file.

class Foo:
    """
    :class: Foo

    A base `Foo` implementation.
    """

    def __init__(self, name: str = None, data: Any = None):
        """
        Constructor

        :param name: The name of the foo. Defaults to None.
        :type name: str
        :param data: The data. Defaults to None.
        :type data: Any
        """
        super().__init__()
        self.name = name
        self.data = data
1

There are 1 best solutions below

8
TheHungryCub On BEST ANSWER

pydoc will treat sub-directories within your module as sub-modules and create links to them.

If I understand question correctly, then I think you only want to generate documentation for specific module,

If yes, then you can run pydoc on those specific module like:

python3 -m pydoc mylib.module1