Artificial Intelligence-based code documentation assistant
Artificial Intelligence is extensively used for developing models to help developers write better source code. Various AI models are used to accelerate the work of developers, such as code autocompletion, autosuggestions, unit test assistance, bug detection, code summarization, etc.
Documentation of code is essential while delivering the project. For large code snippets having thousands of lines of code, it’s very difficult to understand the code functionality for the next set of developers, testers, or clients, and hence code documentation of comments is essential. Most of the developers find it difficult or forget to write documentation or comments.
It is a big challenge for the developers to cope up with writing code, testing the code, and keeping up with its documentation. Docly comes to the rescue, as it automatically generates documentation for python code using state-of-the-art natural language processing.
Docly is a python package by Codist.AI that can automatically generate documentation for your python code. It extensively used natural language processing to go through all the functions in the code snippet and generate docstring or comments automatically and can also update any missing or outdated docstring.
Docly is provided in the command-line interface and can review or complete the documentation in one-line command in few seconds.
Pypl installation for the required packages.
pip install -U PyYAML
pip install docly
To generate documentation of a given python code snippet, use a single line of the command-line statement:
After the docly engine is loaded and the docstring is generated, it will seek permission to show the suggestions.
Taking input as ‘y’, it generates all the function names in the code snippets along with the generated docstring for each function.
If you want to edit and add these suggested docstrings to the original python file, return input with ‘y’. It adds the suggested docstring to each of the functions with the arguments in the first line of each function.
Initial python file with no documentation:
Final output file with added docstring generated using Docly:
In the modified python script, the generated docstring is edited and added inside each function.
Format of docstring (Inside
‘‘‘ --- ’’’):
- Each of the docstring contains a comment that signifies what that function holistically.
- It also specifies the input arguments (parameters) for their respective functions.
- In the last, it generates its credit statement: (Generated by docly)
To revert back to the applied changes then below-mentioned command line statement: