Skip to content

Instantly share code, notes, and snippets.

@Vincent-CIRCL
Last active March 22, 2021 20:15
Show Gist options
  • Save Vincent-CIRCL/c43687d13914d51870d104a714150f72 to your computer and use it in GitHub Desktop.
Save Vincent-CIRCL/c43687d13914d51870d104a714150f72 to your computer and use it in GitHub Desktop.
For-Dummy tutorial for Sphinx documentation of a Python project
# Sources :
https://goldilocks.readthedocs.io/en/latest/source/goldilocks.html#module-goldilocks.strategies
https://samnicholls.net/2016/06/15/how-to-sphinx-readthedocs/
https://gisellezeno.com/tutorials/sphinx-for-python-documentation.html
http://www.sphinx-doc.org/en/master/man/sphinx-apidoc.html
https://stackoverflow.com/questions/2701998/sphinx-autodoc-is-not-automatic-enough
https://github.com/MISP/PyMISP/blob/master/docs/source/conf.py
https://raw.githubusercontent.com/MISP/PyMISP/master/docs/source/index.rst
https://raw.githubusercontent.com/MISP/PyMISP/master/docs/source/modules.rst
https://stackoverflow.com/questions/13516404/sphinx-error-unknown-directive-type-automodule-or-autoclass/17004855
https://sphinx-tutorial.readthedocs.io/start/
https://docs.readthedocs.io/en/stable/intro/getting-started-with-sphinx.html
https://www.sphinx-doc.org/en/1.2/tutorial.html
https://realpython.com/documenting-python-code/
# My tutorial :
# Hypothesis : You have a __init__.py in each of the folder you want sphinx to go in and document
# Aller dans le pipenv
pipenv shell
# Eventuellement setup le path
# export XXX_HOME = “/home/user/Desktop/douglas-quaid”
# aller dans le dossier “doc”
cd ./docs
# en admettant que le dossier soit VIDE
sphinx-quickstart
> Selected root path: .
> Separate source and build directories (y/n) [n]: y
> Project name: YYYYYYYYYYYY
> Author name(s): XXXXXXXXXXX
> Project release []: 0.0.4
> Project language [en]:
Creating file ./source/conf.py.
Creating file ./source/index.rst.
Creating file ./Makefile.
Creating file ./make.bat.
# Dans le fichier conf.py
# Mettre au début :
import os
import sys
sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath('../'))
sys.path.insert(0, os.path.abspath('../../'))
# Activer ces extensions :
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.coverage',
'sphinx.ext.mathjax',
'sphinx.ext.ifconfig',
'sphinx.ext.viewcode',
'sphinx.ext.napoleon',
'sphinx.ext.imgconverter',
]
# Créer automatiquement les fichiers qu'il faut
sphinx-apidoc -o source/ ../ -f -d 10
# Avec :
# -o = Le chemin où seront stockés les fichiers (c'est bien de les mettre dans source)
# -f = forcer l'overwrite
# -d = profondeur de recherche
# Créer le site
make html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment