Sphinx: Python code documentation tool
Table of Contents
- Sphinx Python Code Documentation Tool
- Basic setup of page
- Other general features/changes
- Some old stuff (Need to update below part…)
- Lxplus settings
Sphinx Python Code Documentation Tool
Reference: https://sphinx-rtd-tutorial.readthedocs.io/en/latest/sphinx-quickstart.html
Basic setup of page
-
Create a directory
mkdir docs cd docs -
Best to use the virtual environment
python -m venv .venvActivate the virtual environment, each time before the work
source .venv/bin/activate -
Install the necessary packages within the virtual environment
source .venv/bin/activate # first upgrade the pip pip install --upgrade pip pip install sphinx pip install myst-parser pip install sphinx_rtd_theme pip install sphinx-autobuildAlternatively, you can also create a
requirement.txtfile whose content will besphinx myst-parser sphinx_rtd_theme sphinx-autobuildThen, just install all these packages like
pip install -r requirement.txtAlso, the
requirement.txtfile is necessary when we upload this to the readthedocs to make our webpage live. So, its good to create this file. -
Basic setup:
cd docs sphinx-quickstart make htmlTo check the created webpage:
python -m http.serverIf this does not work try following (Reference: https://stackoverflow.com/a/69387071/2302094):
python -m http.server 8000 --bind 127.0.0.1 -
To view the live updates of your webpage:
sphinx-autobuild source build/htmlIf the
autobuildis not installed, then install it using:pip install sphinx-autobuild
Other general features/changes
-
Change the theme
To change the theme, one need to install the theme and update it in the
conf.pyfile.Install the theme:
pip install sphinx_rtd_themeUpdate the theme in
conf.pyhtml_theme = 'sphinx_rtd_theme' -
Add other file
```{include} ../../README.md ```
Some old stuff (Need to update below part…)
-
Also update path of source code, i.e, uncomment below patch
import os import sys sys.path.insert(0, os.path.abspath('../../simpleble/')) -
Generating document
sphinx-apidoc -o ./source ../simpleble make clean make html -
If command
make htmlcomplains about some module not found then skip them using command:autodoc_mock_imports = ["ROOT"]
Lxplus settings
To use sphinx on lxplus cluster:
source /cvmfs/sft.cern.ch/lcg/views/dev4cuda/latest/x86_64-centos7-gcc11-opt/setup.sh
Enjoy Reading This Article?
Here are some more articles you might like to read next: