This guide gives instruction on hwo to set up and building Sphinx documentation, especially when .rst (reStructuredText) files are already created.
- Introduction
- Requirements
- Installation
- How to Use the Makefile
- Using Sphinx with Existing
.rstFiles - Editing
.rstFiles
Sphinx is a tool for creating intelligent auto-documentation for Python projects. Sphinx uses reStructuredText (.rst) files to create documentation. This guide will walk you through the basics of setting up Sphinx, especially when you already have .rst files.
- Ensure that Sphinx is installed on your system.
- The
sphinx-buildcommand should either be available in your PATH or theSPHINXBUILDenvironment variable should point to its location.
To set up Sphinx and the required extensions for this porject use the following commands:
```bash
pip install sphinx sphinx_rtd_theme myst-parser autodocsumm sphinxcontrib-bibtex sphinx-needs sphinxcontrib-plantuml
```
-
Navigate to the Directory: Open a command prompt or terminal and navigate to the directory containing the make file and the .rst files, in our case:
docs -
Build Documentation:
.\make <command> # for Windows: .\make (makefile_name) html
-
View Documentation: The built html will be in
_builddirectory. Navigate to_build/htmland openindex.htmlin a web browser.
-
Edit the
conf.pyfile: You can editconf.pyfile - which should be in the same directory as the.rstfiles. This file will contain the configuration for the Sphinx documentation builder. -
Working with the
index.rstfile: This file will contain the table of contents for the documentation. It will also contain the names of the.rstfiles that will be included in the documentation. -
Changing
.rstfiles: You can edit the.rstfiles to add content to the documentation. You can also add new.rstfiles to the directory and include them in theindex.rstfile.
It is important that the .rst files are formatted correctly. Here are some tips for editing .rst files:
-
Using
.. toctree::directive: This directive is used to create a table of contents for the documentation. It should be used inindex.rstfile to list the.rstfiles that will be included in the documentation. It can also be used in other.rstfiles to create sub-tables of contents. It is also recursively used to create sub-tables of contents within sub-tables of contents. -
Headings:
=and-symbols create headings. The=symbol creates a top-level heading and the-symbol creates a second-level heading. -
Links:
.. _<link_name>: <link>directive to create a link. To use the link, use the:ref:directive. For example, if the link name islink_name, then use:ref:link_name`` to create a link to the URL. -
Emphasis: Use the
*symbol to create emphasis. For example,*emphasis*will create emphasis. -
Images:
.. image:: <image_path>to add an image. Theimage_pathis the path to the image file. For example,.. image:: images/image.pngwill add the imageimage.pngto the documentation. -
Include Files:
.. include:: <file_path>directive to include file. For example,.. include:: file.rstwill include the filefile.rstin the documentation.