Automatically build Python documentation with Sphinx

Introduction

Hello everyone! Are you writing Python? I'm currently creating a service using Python + django, but as you're familiar with Pythonista, you know that Python can have a docstring. For example, let's run a simple script like this:

# -*- coding: utf-8 -*-
from __future__ import print_function


def foobar():
    u"This is a meaningless function."
    pass


print(foobar.__doc__)

In Python, you can assign the first string literal that appears in a function, class, or method to __doc__ and later find out what that function means. This is a nice feature, but it's a waste if you can only quote from Python's interactive console screens, IDEs, or various plugins for Python.

So, if you use a document tool called Sphinx that Pythonista often uses, this Docstring will be put together into one. That command is sphinx-apidoc. For details on how to use this, please see the Official Document. Hopefully a Sphinx project will be launched.

Now, in doing test drive, test with watchdog or sniffer Many people will hook up and launch the test every time the file is updated. Therefore, I also use the document as a hook and automatically generate it.

Below is an example of a sniffer.

@runnable
def execute(*args):
    from subprocess import call
    call('cd ../docs;make html', shell=True)
    return call(
        'python manage.py test users --failfast',
        shell=True) == 0

For Linux, sphinx creates a Makefile and builds the documentation from the make command. By creating hooks like this, you'll always have the latest documentation at hand, and you'll be able to check for unintended reSt Syntax mistakes.

Just keep in mind that if you don't include the document directory as a .gitignore file in Git, it can be very annoying.

Of course, some people may be using it in a project in another language because Sphinx's document generation performance is so good, not in a Python project. Also, some people may use it to make materials normally. In such a case, the combination of sniffer + sphinx is very comfortable, so I recommend it. Of course, you can create other file update management tools.

Recommended Posts

Automatically build Python documentation with Sphinx
Write documentation in Sphinx with Python Livereload
Try to automatically generate Python documents with Sphinx
Build python3 environment with ubuntu 16.04
Build python environment with direnv
Let's build git-cat with Python
Compile Sphinx documentation with Wercker
Build python virtual environment with virtualenv
Build Mysql + Python environment with docker
Build mlpy with python3.3 (64bit) (windows 64bit)
Create Python project documentation in Sphinx
Build Vim with MinGW. (+ lua, + python)
Build python 1.0
Build Jupyter Lab (Python) environment with Docker
Build a blockchain with Python ① Create a class
HTML document your Python program with Sphinx
Automatically aggregate JCG deck distribution with Python
Get started with the documentation tool Sphinx
Build a python virtual environment with pyenv
[Python] Automatically operate the browser with Selenium
Build a modern Python environment with Neovim
Build AI / machine learning environment with Python
FizzBuzz with Python3
Scraping with Python
Statistics with python
Scraping with Python
Python with Go
Integrate with Python
AES256 with python
Tested with Python
python starts with ()
with syntax (Python)
Bingo with python
Zundokokiyoshi with python
Excel with Python
Microcomputer with Python
Cast with python
Automatically search and download YouTube videos with Python
Build python environment with pyenv on EC2 (ubuntu)
Build Python development environment with Visual Studio Code
Build a python environment with ansible on centos6
[Python] Build a Django development environment with Docker
Create a python3 build environment with Sublime Text3
Automatically format Python code into PEP8-compliant code with Emacs
Build a Python environment with OSX El capitan
Quickly build a Python Django environment with IntelliJ
Build PyPy and Python execution environment with Docker
Build a Python machine learning environment with a container
Build a python execution environment with VS Code
Serial communication with Python
Zip, unzip with python
Primality test with Python
Python with eclipse + PyDev.
Socket communication with Python
Data analysis with python 2
Scraping with Python (preparation)
Automatically paste images into PowerPoint materials with python + α
Try scraping with Python.
Sequential search with Python
"Object-oriented" learning with python
Run Python with VBA