Personal notes to doc Python code in Sphinx

This article

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

create

#Virtual environment name sphinx_I will proceed with test
conda create -n sphinx_test python=3.6

activate

conda activate sphinx_test

Install sphinx package

pip install sphinx

document project initialization

#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 []"

document creation configuration

--Open docs / conf.py --Uncommented the following parts

import 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('../')

extension settings

extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.napoleon'
]

Let's make the document once here

.\docs\make singlehtml

Generate rst file from py file

# "."Don't overlook it. The meaning of all the files in the directory.
sphinx-apidoc -f -o .\docs .

Change index.rst

.. toctree::
   :maxdepth: 2
   :caption: Contents:

   TestClass # <-The python file you want to add

Put the python file

- 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

Document make

--Same as before

.\docs\make singlehtml

Recommended Posts

Personal notes to doc Python code in Sphinx
python personal notes
Notes on using code formatter in Python
missingintegers python personal notes
Rewrite Python2 code to Python3 (2to3)
[Personal notes] Python, Django
Convert cubic mesh code to WKT in Python
A collection of code often used in personal Python
To flush stdout in Python
Web scraping notes in python3
Python notes to forget soon
Login to website in Python
Speech to speech in python [text to speech]
Generate QR code in Python
How to develop in Python
Get Evernote notes in Python
Character code learned in Python
Convert python 3.x code to python 2.x
Post to Slack in Python
I want to be able to run Python in VS Code
[Python] How to do PCA in Python
[Python] Generate QR code in memory
How to collect images in Python
Automatically format Python code in Vim
How to use SQLite in Python
In the python command python points to python3.8
Personal notes for python image processing
Try to calculate Trace in Python
Python Pandas Data Preprocessing Personal Notes
Write selenium test code in python
How to use Mysql in python
Create Python project documentation in Sphinx
How to wrap C in Python
How to use ChemSpider in Python
To maintain code quality in PyCharm
6 ways to string objects in Python
How to use PubChem in Python
(Personal notes) Python metaclasses and metaprogramming
How to run TensorFlow 1.0 code in 2.0
Code tests around time in Python
How to handle Japanese in Python
An alternative to `pause` in Python
I wrote the code to write the code of Brainf * ck in python
Articles to read when Blender Python script code doesn't work in 2.80
Write documentation in Sphinx with Python Livereload
I tried to implement PLSA in Python
Fourier series verification code written in Python
[Introduction to Python] How to use class in Python?
Try logging in to qiita with Python
WEB scraping with Python (for personal notes)
Install Pyaudio to play wave in python
How to access environment variables in Python
I tried to implement permutation in Python
Method to build Python environment in Xcode 6
How to dynamically define variables in Python
How to do R chartr () in Python
python notes: Modularization: __name__ == How to use'__main__'
Notes on nfc.ContactlessFrontend () for nfcpy in python
Pin current directory to script directory in Python
[Itertools.permutations] How to put permutations in Python
PUT gzip directly to S3 in Python