Sphinx: Documentation Generator Tool
First install
Sphinx&sphinx-rtd-themewithpip install -r requirements.txt
-
Create directory
docs(adjacent to yourapp), open it & run:sphinx-quickstart -
Go one directory up from
docs(back to parent directory) & run:sphinx-apidoc -o docs app -
Changes in file
docs/conf.py- [line 6]
import os, sys sys.path.insert(0, os.path.abspath('..'))
- [line 20]
extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.duration', 'sphinx.ext.todo', 'sphinx.ext.viewcode' ]
- [line 33]
html_theme = 'sphinx_rtd_theme'
-
Changes in file
docs/index.rst- [line 10] Change the
:maxdepth:number to0(it won't crawl sub-modules, we'll add them manually) - [line 13] Add only
modulestext (it callsdocs/modules.rston build)
- [line 10] Change the
-
Changes in file
docs/modules.rst- [line 7+] Add your module names (example:
app.module_name) to include them in the docs generation
- [line 7+] Add your module names (example:
-
Open
docsdirectory again and run:make.bat html -
Open
docs/_build/index.htmlin a web-browser.
- Run
run.pywhich runsapppackage and doesn't callapp.__main__
python -B run.py- Run
app.__main__file
python -m app- Run
app.__main__file without caching the bytecode
python -B -m app- Argument
-Bskips writing compiled bytecode (no__pycache__folders are created) - Argument
-mruns as a module
-
In the context of
from . import file, the.ispackage_name, so importing.importspackage_name, which runspackage_name/__init__.py. -
__init__.pyis run when you import a package into a running python program, which does not do anything as its only purpose is to mark the directory as a package. It contains most of the code and defines all the classes. -
__main__.pyis run as'__main__'when you run a package as the main program. For instance,python -m package_nameat a command line runspackage_name/__main__.py, which starts the package.