0

I am trying to genereate docs using Sphinx but I am guessing I have my path set incorrectly or something along those lines. My file structure is as follows:

project_name
    docs
        build
        source
            index.rst
            conf.py
    src
        classes
            book.py
            _init_.py
        app.py

Class book.py looks like:

class Book
  """ Class that describes a book.

  :param title: De pagina waarvan de review is gescraped.
  :type title: str
  :param publisher: De gebruiker die de review heeft geplaatst.
  :type publisher: str
  """
  def _init_(self):
    self._title = 'Unknown'
    self._publiser = 'Unknown'

The file init.py looks like:

from . import Book

I edited the conf.py file for Sphinx and uncommented: import os import sys

sys.path.insert(0, os.path.abspath('../../src/'))

And index.rst looks like:

.. review_scrapers documentation master file, created by
   sphinx-quickstart on Fri Mar 26 08:54:56 2021.
   You can adapt this file completely to your liking, but it should at least
   contain the root `toctree` directive.

Welcome to review_scrapers's documentation!
===========================================

.. toctree::
   :maxdepth: 2
   :caption: Contents:



Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

Now when I run the following command from my project root:

sphinx-build -b html docs/source/ docs/build/

Sphinx does not seem to find the class I added to my project.

What am I doing wrong here?

SomeDutchGuy
  • 2,249
  • 4
  • 16
  • 42
  • You path is correct so it's not a Sphinx issue. Unless the `__init__.py` should contain `from book import Book`. You also need an `.rst` file that actually uses the imported module, you didn't include an example of a `.rst` file or an error message. I think there is some info missing here. – bad_coder Mar 26 '21 at 09:24
  • @bad_coder as it's my first time using Sphinx I was not aware of the importance of index.rst. I have now added it to the question. I did not show all files as running quickstart generated quite a few. I doubt the import should change as I am able to implort the class into app.py. An error is not given when generating the docs. It just runs and outputs the HTML without the class. – SomeDutchGuy Mar 26 '21 at 10:04
  • OK, try adding `modules` as an entry under the `.. toctree::` (below the options). It corresponds to the `modules.rst` file sphinx-quickstart generated for you. It should work, if it doesn't edit the question to include the `classes.rst` file that should be inside the `sources` directory. – bad_coder Mar 26 '21 at 10:12
  • See [this post](https://stackoverflow.com/a/59951675) for how the toctree should be written in this case. – bad_coder Mar 26 '21 at 10:14

0 Answers0