-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from hrshdhgd/documenter
Add `documenter` feature
- Loading branch information
Showing
18 changed files
with
758 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
Command line interface for CoderGPT | ||
==================================== | ||
|
||
This module provides a command line interface (CLI) for CoderGPT, a powerful code generation tool designed to assist in various coding tasks, including inspection, explanation, commenting, optimization, test writing, and documentation of code files. | ||
|
||
.. moduleauthor:: Harshad Hegde | ||
|
||
Usage | ||
----- | ||
|
||
To use this CLI, run the following command in your terminal: | ||
|
||
.. code-block:: shell | ||
python codergpt_cli.py [OPTIONS] COMMAND [ARGS]... | ||
Options | ||
------- | ||
|
||
-v, --verbose INTEGER | ||
Verbosity level, which can be set to 0, 1, or 2. | ||
|
||
-q, --quiet | ||
Activate quiet mode, limiting output messages. | ||
|
||
--version | ||
Display the current version of CoderGPT and exit. | ||
|
||
Commands | ||
-------- | ||
|
||
**inspect** | ||
Inspect a package to show a file-language map. Requires a path to the package as an argument. | ||
|
||
**explain** | ||
Provide explanations for a specified function or class within a file. This command requires a path and can optionally include a function name and a class name. | ||
|
||
**comment** | ||
Add comments to a code file. This command requires a path to the file and accepts an overwrite flag to indicate whether existing files should be overwritten. | ||
|
||
**optimize** | ||
Optimize a code file by improving its performance or code quality. This command requires a path to the file and can optionally include a function name, a class name, and an overwrite flag. | ||
|
||
**write-tests** | ||
Generate test cases for a specified function or class within a file. This command requires a path and can optionally include a function name and a class name. | ||
|
||
**document** | ||
Write documentation files for a code file. This command requires a path to the file. | ||
|
||
.. note:: All path arguments can be a string path, a :class:`pathlib.Path` object, or a file object. | ||
|
||
Examples | ||
-------- | ||
|
||
Inspect a package: | ||
|
||
.. code-block:: shell | ||
python codergpt_cli.py inspect /path/to/package | ||
Explain a function in a file: | ||
|
||
.. code-block:: shell | ||
python codergpt_cli.py explain -f my_function /path/to/file.py | ||
Add comments to a file with overwrite enabled: | ||
|
||
.. code-block:: shell | ||
python codergpt_cli.py comment --overwrite /path/to/file.py | ||
Optimize a class within a file without overwriting: | ||
|
||
.. code-block:: shell | ||
python codergpt_cli.py optimize -c MyClass /path/to/file.py | ||
Write tests for a function: | ||
|
||
.. code-block:: shell | ||
python codergpt_cli.py write-tests -f my_function /path/to/file.py | ||
Write documentation for a file: | ||
|
||
.. code-block:: shell | ||
python codergpt_cli.py document /path/to/file.py | ||
Parameters and Options | ||
---------------------- | ||
|
||
-path | ||
The path to the code file, package, or directory. This is a required argument for all commands. | ||
|
||
-f, --function | ||
The name of the function to explain, optimize, or write tests for. This is an optional argument for the ``explain``, ``optimize``, and ``write-tests`` commands. | ||
|
||
-c, --classname | ||
The name of the class to explain, optimize, or write tests for. This is an optional argument for the ``explain``, ``optimize``, and ``write-tests`` commands. | ||
|
||
--overwrite/--no-overwrite | ||
A flag indicating whether to overwrite the existing file. This is an optional argument for the ``comment`` and ``optimize`` commands. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
Commenter Module | ||
================ | ||
|
||
This module contains the CodeCommenter class, which is designed to enhance code readability by automatically adding comments and Sphinx-compatible docstrings to a given piece of code. | ||
|
||
Classes | ||
------- | ||
|
||
CodeCommenter | ||
^^^^^^^^^^^^^ | ||
|
||
.. autoclass:: CodeCommenter | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
The CodeCommenter class leverages a runnable chain to analyze code and generate explanatory comments and docstrings. | ||
|
||
.. automethod:: __init__ | ||
.. automethod:: comment | ||
|
||
Methods | ||
------- | ||
|
||
__init__(self, chain) | ||
~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Initializes the CodeCommenter class with a specified runnable chain. | ||
|
||
:parameter chain: A ``RunnableSerializable`` object that is capable of executing defined tasks. This chain is responsible for the primary operation of analyzing and generating comments for the provided code. | ||
:type chain: RunnableSerializable[Dict, Any] | ||
|
||
comment(self, code, filename, overwrite=False, language=None) | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Generates comments for the given code and writes the commented code to a file. | ||
|
||
:parameter code: The code for which comments are to be generated. This should be a string containing the source code. | ||
:type code: str | ||
|
||
:parameter filename: The name of the original file from which the code was extracted. This filename is used to generate a new filename for the commented code unless ``overwrite`` is set to True. | ||
:type filename: str | ||
|
||
:parameter overwrite: Determines whether the original file should be overwritten with the commented code. By default, this is set to False, and the commented code is written to a new file with an "_updated" suffix. | ||
:type overwrite: bool, optional | ||
|
||
:parameter language: The programming language of the code. This is an optional parameter that can be used to specify the language if it cannot be inferred from the code or filename. Providing this information can help the runnable chain to generate more accurate and language-appropriate comments. | ||
:type language: Optional[str], optional | ||
|
||
This method first invokes the runnable chain with the provided code and an instruction to add comments and Sphinx-compatible docstrings in a specific format. The response from the chain is expected to contain the commented code, which is then written to either a new file or the original file based on the ``overwrite`` parameter. | ||
|
||
Dependencies | ||
------------ | ||
|
||
- os: Used for file path manipulation and generating new filenames. | ||
- typing: Provides support for type hints. | ||
|
Oops, something went wrong.