A personal note for documenting Python code using Sphinx. Below is a very nice article. -How to use Sphinx. Read docstring and generate specifications
#Virtual environment name sphinx_I will proceed with test
conda create -n sphinx_test python=3.6
conda activate sphinx_test
pip install sphinx
#Make the docs folder your workspace
sphinx-quickstart docs
--You will be asked some settings questions, but if you want to keep the default values, just press Enter --The following settings are optional - "project name:" - "Author name(s):" - "Project release []"
docs / conf.py
--Uncommented the following partsimport os
import sys
sys.path.insert(0, os.path.abspath('../'))
#I want to refer to the py file placed in the above directory, so do this
# os.path.abspath('./') => os.path.abspath('../')
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon'
]
.\docs\make singlehtml
# "."Don't overlook it. The meaning of all the files in the directory.
sphinx-apidoc -f -o .\docs .
.. toctree::
:maxdepth: 2
:caption: Contents:
TestClass # <-The python file you want to add
- sphinx_test
- docs
- TestClass.py <--Put here
--Write the comment you want to document in docstring format
class TestClass:
"""Summary line.
"""
def testfunc(self, x, y):
"""sum
Args:
x (int): 1st argument
y (int): 2nd argument
Returns:
int: sum result
Examples:
>>> print(testfunc(2,5))
7
"""
return x + y
--Same as before
.\docs\make singlehtml
Recommended Posts