I am using sphinx reSt to write docstrings for functions and I have created a mustache setting to customize docstring automatic generation in VsCode as below:
{{! Sphinx Docstring Template }}
{{summaryPlaceholder}}
{{extendedSummaryPlaceholder}}
{{#args}}
:param {{var}} {{typePlaceholder}}: {{descriptionPlaceholder}}
{{/args}}
{{#kwargs}}
:param {{var}} {{typePlaceholder}}{{#default}}, optional defaults to {{/default}}{{&default}}: {{descriptionPlaceholder}}
{{/kwargs}}
{{#exceptionsExist}}
{{#exceptions}}
:raises {{type}}: {{descriptionPlaceholder}}
{{/exceptions}}
{{/exceptionsExist}}
{{#yieldsExist}}
{{#yields}}
:yield {{typePlaceholder}}: {{descriptionPlaceholder}}
{{/yields}}
{{/yieldsExist}}
{{#returnsExist}}
{{#returns}}
:return {{typePlaceholder}}: {{descriptionPlaceholder}}
{{/returns}}
{{/returnsExist}}
For example:
# myproject/src/foo.py
def my_func(arg1: int, arg2: int, arg3: str = "some_text") -> tuple[str, str, str]:
"""my summary
my extended_summary
:param arg1 int: arg1 my description
:param arg2 int: arg2 my description
:param arg3 str Default "some_text": arg3 my description
:return tuple[str, str, str]: return my description
"""
return "a", "b", "c"
Now I am going to use sphinx-apidoc
for generating documentation
I do sphinx-quickstart
in myproject/docs
. Then I run sphinx-apidoc -o ./docs/_modules ./src
and then change directory to docs
and run make html
However, the documentation that gets generated for me is as below:
If I modify the function's docstring to the standard format as below:
def my_func(arg1: int, arg2: int, arg3: str = "some_text") -> tuple[str, str, str]:
"""my summary
my extended_summary
:param arg1: arg1 my description
:type arg1: int
:param arg2: arg2 my description
:type arg2: int
:param arg3: arg3 my description, defaults to "some_text"
:type arg3: str, optional
:return: return my description
:rtype: tuple[str, str, str]
"""
return "a", "b", "c"
The the correct documentation gets generated.
As the template I have created for docstring is an standard alternative, how can adjust sphinx-apidoc to use my mustache template and generate correct documentation?
**Summery:
- I have customized autodoc extension with mustache
- I need sphinx-apidoc to understand the generated docstrings correctly**