0

I am trying to build docs for my python project with sphinx but I haven't understood how to do it.

At first my project is in this folder:

(scientific_python_2_7) lpuggini@lpuggini-T3420:~/docs$ ls ~/mlp/trunk/
applearning                  clean_only.sh  mlearncnepack     SecurityReport
build_only_docker.sh         collection     mlearn.egg-info   setup.py
build_only.sh                common         peers_peak        transaction_tracking
build.sh                     iplearning     requirements.txt  uba_sam_integration
clean_checkout_and_build.sh  jenkins        scripts           user_behaviour
(scientific_python_2_7) lpuggini@lpuggini-T3420:~/docs$ 

most of the files here are folders that contain python code. The project is quite big.

Following some tutorials I have installed sphinx using the default settings. As :

(scientific_python_2_7) lpuggini@lpuggini-T3420:~/docs$ sphinx-quickstart 
Welcome to the Sphinx 1.7.2 quickstart utility.

Please enter values for the following settings (just press Enter to
accept a default value, if one is given in brackets).

Selected root path: .

You have two options for placing the build directory for Sphinx output.
Either, you use a directory "_build" within the root path, or you separate
"source" and "build" directories within the root path.
> Separate source and build directories (y/n) [n]: 

Inside the root directory, two more directories will be created; "_templates"
for custom HTML templates and "_static" for custom stylesheets and other static
files. You can enter another prefix (such as ".") to replace the underscore.
> Name prefix for templates and static dir [_]: 

The project name will occur in several places in the built documentation.
> Project name: mlp
> Author name(s): luca
> Project release []: 

If the documents are to be written in a language other than English,
you can select a language here by its language code. Sphinx will then
translate text that it generates into that language.

For a list of supported codes, see
http://sphinx-doc.org/config.html#confval-language.
> Project language [en]: 

The file name suffix for source files. Commonly, this is either ".txt"
or ".rst".  Only files with this suffix are considered documents.
> Source file suffix [.rst]: 

One document is special in that it is considered the top node of the
"contents tree", that is, it is the root of the hierarchical structure
of the documents. Normally, this is "index", but if your "index"
document is a custom template, you can also set this to another filename.
> Name of your master document (without suffix) [index]: 

Sphinx can also add configuration for epub output:
> Do you want to use the epub builder (y/n) [n]: 
Indicate which of the following Sphinx extensions should be enabled:
> autodoc: automatically insert docstrings from modules (y/n) [n]: 
> doctest: automatically test code snippets in doctest blocks (y/n) [n]: 
> intersphinx: link between Sphinx documentation of different projects (y/n) [n]: 
> todo: write "todo" entries that can be shown or hidden on build (y/n) [n]: 
> coverage: checks for documentation coverage (y/n) [n]: 
> imgmath: include math, rendered as PNG or SVG images (y/n) [n]: 
> mathjax: include math, rendered in the browser by MathJax (y/n) [n]: 
> ifconfig: conditional inclusion of content based on config values (y/n) [n]: 
> viewcode: include links to the source code of documented Python objects (y/n) [n]: 
> githubpages: create .nojekyll file to publish the document on GitHub pages (y/n) [n]: 

A Makefile and a Windows command file can be generated for you so that you
only have to run e.g. `make html' instead of invoking sphinx-build
directly.
> Create Makefile? (y/n) [y]: 
> Create Windows command file? (y/n) [y]: 

Creating file ./conf.py.
Creating file ./index.rst.
Creating file ./Makefile.
Creating file ./make.bat.

Finished: An initial directory structure has been created.

You should now populate your master file ./index.rst and create other documentation
source files. Use the Makefile to build the docs, like so:
   make builder
where "builder" is one of the supported builders, e.g. html, latex or linkcheck.

(scientific_python_2_7) lpuggini@lpuggini-T3420:~/docs$ 

After that I have edited the first lines of the conf.py file as

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
sys.path.insert(0, os.path.abspath('/home/local/CORVIL/lpuggini/mlp/trunk/'))


# -- Project information -----------------------------------------------------

project = u'mlp'
copyright = u'2018, luca'
author = u'luca'

and then:

(scientific_python_2_7) lpuggini@lpuggini-T3420:~/docs$ make html
Running Sphinx v1.7.2
making output directory...
loading pickled environment... not yet created
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 1 source files that are out of date
updating environment: 1 added, 0 changed, 0 removed
reading sources... [100%] index                                                                          
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] index                                                                           
generating indices... genindex
writing additional pages... search
copying static files... done
copying extra files... done
dumping search index in English (code: en) ... done
dumping object inventory... done
build succeeded.

The HTML pages are in _build/html.

After that if I open the htmls file in _build they do not contain any reference to my trunk code.

I am wondering what step I am missing or what I should do.

mzjn
  • 48,958
  • 13
  • 128
  • 248
Donbeo
  • 17,067
  • 37
  • 114
  • 188
  • Similar question: https://stackoverflow.com/q/25549321/407651 – mzjn Apr 05 '18 at 15:29
  • It seems like you are missing the step that involves creating the *.rst files that contain `automodule` directives. You can do this "by hand" or use the sphinx-apidoc script. – mzjn Apr 05 '18 at 16:05

1 Answers1

0

Sphinx doesn't work like i.e. JavaDoc. You have to actually write the documentation. There is support for extracting documentation from source code with the autodoc extension, but even then I would not try to use it like JavaDoc but write documentation and selectively pull documentation from the source code to avoid duplicating text in Python source and documentation source.

BlackJack
  • 4,476
  • 1
  • 20
  • 25