Is there a program to help you document Python functions?
What are your preferred conventions for documenting python code?
python - How to document a method with parameter(s)? - Stack Overflow
Deploy Python Azure Function with Code from GitHub Repo using Terraform
I'm assuming you're running your TF locally. If so - https://www.terraform.io/docs/provisioners/local-exec.html should do whatever you need if you're also cloning and publishing locally. If you're using something like Azure Devops or Jenkins, it'll probably still work, but you might have a hoop or two to jump through.
More on reddit.comI just finished a Python project and now want to go back and document each function while it is still fresh in my head. Is there a program that will scan your code for functions that don't have a doc-string and then interactively ask you to:
-
describe the function
-
document each parameter
-
document the return value
It would then create a doc-string for you that you could simply copy/paste into your code.
Thanks.
The method of documentation I learned in school is to list a function name, description, parameters, return type, and exceptions. It's serviceable, but a tad verbose and prone to redundancy. What do you recommend?
I am documenting the code for my new password manager. Here is the source on Github.
Since docstrings are free-form, it really depends on what you use to parse code to generate API documentation.
I would recommend getting familiar with the Sphinx markup, since it is widely used and is becoming the de-facto standard for documenting Python projects, in part because of the excellent readthedocs.org service. To paraphrase an example from the Sphinx documentation as a Python snippet:
def send_message(sender, recipient, message_body, priority=1) -> int:
"""
Send a message to a recipient.
:param str sender: The person sending the message
:param str recipient: The recipient of the message
:param str message_body: The body of the message
:param priority: The priority of the message, can be a number 1-5
:type priority: integer or None
:return: the message id
:rtype: int
:raises ValueError: if the message_body exceeds 160 characters
:raises TypeError: if the message_body is not a basestring
"""
This markup supports cross-referencing between documents and more. Note that the Sphinx documentation uses (e.g.) :py:attr: whereas you can just use :attr: when documenting from the source code.
Naturally, there are other tools to document APIs. There's the more classic Doxygen which uses \param commands but those are not specifically designed to document Python code like Sphinx is.
Note that there is a similar question with a similar answer in here...
Based on my experience, the numpy docstring conventions (PEP257 superset) are the most widely-spread followed conventions that are also supported by tools, such as Sphinx.
One example:
Parameters
----------
x : type
Description of parameter `x`.