I made "sphinx-quickstart-plus" which makes document creation of Sphinx convenient

Said thing: I want everyone to use Sphinx conveniently

Sphinx is very convenient, but the documentation process was very cumbersome. Therefore, I made a module "sphinx-quickstart-plus" that extends Sphinx.

https://github.com/pashango2/sphinx-qsp

Installation method

Easy to install with pip. It depends on the Sphinx module, so please install Sphinx in advance.

$ pip install sphinx-quickstart-plus

How to use

Until now, document creation was typed as sphinx-quickstart, but just type sphinx-quickstart-plus.

$ sphinx-quickstart-plus

Then, the following message will be played.

output


Welcome to the Sphinx 1.5.1 quickstart utility.

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

Enter the root path for documentation.
> Root path for the documentation [.]: document_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]: y

...

The output is exactly the same as the previous sphinx-quickstart. You might think, "Nothing has changed," but please keep in touch.

output


...
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]: 

> ext_commonmark:use CommonMark and AutoStructify (y/n) [n]: y
> ext_nbshpinx:provides a source parser for *.ipynb files (y/n) [n]: y
> ext_blockdiag:Sphinx extension for embedding blockdiag diagrams (y/n) [n]: y
> ext_fontawesome:use font awesome (y/n) [n]: y
> ext_rtd_theme:use Read the Doc theme (y/n) [n]: y
> ext_autobuild:autobuild: Watch a directory and rebuild the documentation (y/n) [n]: y

Finally, there are questions that weren't in sphinx-quickstart. The current extensions and descriptions are as follows:

Extension name Description
ext_commonmark .rstnot only.md(CommonMark)Will be available
ext_nbshpinx You will be able to import Jupyter Notebook
ext_blockdiag You will be able to draw block diagrams
ext_fontawesome Font Awesome will be available from reST
ext_rtd_theme You will be able to use the Read the Docs theme
ext_autobuild You will be able to use auto build

These Sphinx extensions will be available without editing conf.py.

Not only that, when you start sphinx-quickstart-plus again, the question at the beginning changes.

output


> Use latest setting? (y/n) [y]: y

If you type'y', just answer the 5 items Path, Project name, ʻAuthor, Version, and Release, and a document with the same settings as the previous document will be created. It remembers the document settings created in the previous sphinx-quickstart-plus`.

By the way, if you type'n', the usual sphinx-quickstart question will be played, but since the default setting is the last setting, it is easy because you can press the ʻEnter` key repeatedly except for the changed part. is.

$ sphinx-quickstart-plus

> Use latest setting? (y/n) [y]: n

...

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) [y]: <-The default is the last input

Code added to conf.py on each extension selection

ext_commonmark

conf.py


# ----- CommonMark
source_suffix = [source_suffix, '.md']

from recommonmark.parser import CommonMarkParser
source_parsers = {
    '.md': CommonMarkParser,
}

from recommonmark.transform import AutoStructify

github_doc_root = 'https://github.com/rtfd/recommonmark/tree/master/doc/'
def setup(app):
    app.add_config_value('recommonmark_config', {
            'url_resolver': lambda url: github_doc_root + url,
            'auto_toc_tree_section': 'Contents',
            }, True)
    app.add_transform(AutoStructify)

ext_nbshpinx

conf.py


# ----- Jupyter Notebook nbsphinx
extensions.append('nbsphinx')
exclude_patterns.append('**.ipynb_checkpoints')

ext_blockdiag

conf.py


# ----- blockdiag settings
extensions.extend([
    'sphinxcontrib.blockdiag',
    'sphinxcontrib.seqdiag',
    'sphinxcontrib.actdiag',
    'sphinxcontrib.nwdiag',
    'sphinxcontrib.rackdiag',
    'sphinxcontrib.packetdiag',
])
blockdiag_html_image_format = 'SVG'
seqdiag_html_image_format = 'SVG'
actdiag_html_image_format = 'SVG'
nwdiag_html_image_format = 'SVG'
rackiag_html_image_format = 'SVG'
packetdiag_html_image_format = 'SVG'

ext_fontawesome

conf.py


# ----- sphinx-fontawesome
import sphinx_fontawesome
extensions.append('sphinx_fontawesome')

ext_rtd_theme

conf.py


# ----- Read the Docs Theme
html_theme = "sphinx_rtd_theme"

ext_autobuild

auto_build does not rewrite conf.py, but rewrites the Makefile.

$ make livehtml

If you type, auto build will start. For Windows people, ʻauto_build.bat` will be generated, so please run it.

$ auto_build.bat

If you edit .md such as PyCharm, a temporary file will be created and it will also be built, so there is also a setting to ignore the build of some temporary files.

About license

"Sphinx-quickstart-plus" is license-free, please feel free to use it. Please understand that we are not responsible for any disadvantages caused by using this module.

https://github.com/pashango2/sphinx-qsp

Also, since my environment is Ubuntu, I haven't been able to test it on Windows and Mac. I think there are bugs. If you have any problems, please let us know in the issues or comments on GitHub.

Code commentary

This module itself is a small module with less than 400 lines including comments, it takes about 6 hours to create, and most of it is debugging work. However, it fully supports the rich arguments and features of sphinx-quickstart.

The reason why you can do this is because you are using a technology called ** Monkey Patch **.

What is a monkey patch?

A monkey patch is a patch that hijacks the behavior of an existing library and dynamically rewrites it. This is a feat that takes advantage of the characteristics of dynamic languages and is a technique that cannot be imitated by compiled languages. [^ 1]

[^ 1]: I did a monkey patch of the compilation language at http://postd.cc/monkey-patching-in-go/, it's a pretty black magic using assembler.