utility to suggest code refactoring
Project description
Code Improver Tool
Overview
The Code Improver Tool is a Python application that leverages OpenAI's language models to enhance code quality.
It can perform various actions such as cleaning code, adding docstrings, generating tests, and creating README files based on the provided source code. This tool is designed for developers who want to automate the improvement of their codebases efficiently.
Features
- Code Cleaning: Automatically refines the code for better readability and performance.
- Docstring Generation: Adds meaningful docstrings to functions and classes for improved documentation.
- Test Generation: Creates unit tests to ensure code reliability.
- README Generation: Generates a README file to provide an overview of the project.
Requirements
- Python 3.11 or higher
langchain_corelangchain_openai- Access to OpenAI API
Installation
-
Clone the repository:
git clone <repository-url> cd <repository-directory>
-
Install the required packages:
pip3 install -r requirements.txt
-
Set your OpenAI API key in your environment variables:
export OPEN_AI_API_KEY='your_openai_api_key'
Usage
To use the Code Improver Tool, run the script from the command line with the required arguments:
python3 cli.py --file <path_to_your_code_file> --action <action_type>
Arguments
--fileor-f: The path to the code file that you want to process (required).--actionor-a: The action you want to perform. Options include:clean: Clean the code.docstrings: Add docstrings to the code.tests: Generate tests for the code.readme: Create a README file for the project.
--openai-api-keyor-k: OpenAI API key to use
Example
To clean a Python file named example.py, you would run:
python3 cli.py --file example.py --action clean
CLI
It is possible to install:
pip3 install py_code_improver
and run as cli:
py_code_improver --file example.py --action docstrings
poetry run py_code_improver --file example.py --action readme
Output
The tool generates a new file with the same name as the input file, appended with a timestamp and the extension .llm. For example, if you process example.py, the output file will be named example.py.llm<timestamp>.
Logging
The application logs its activities to the console. You can adjust the logging level in the code if you want more or less verbosity.
Error Handling
The tool includes error handling for the following scenarios:
- If the specified file exceeds the character limit (9999 characters).
- If an unrecognized action is provided.
Contributing
Contributions are welcome! Feel free to submit a pull request or open an issue for any bugs or feature requests.
License
This project is licensed under the MIT License. See the LICENSE file for more details.
Contact
For questions or feedback, please reach out to [alex.polovinko+git@gmail.com].
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_code_improver-0.2.1.tar.gz.
File metadata
- Download URL: py_code_improver-0.2.1.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.5 Darwin/23.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0428fd2ca12759c5ca7a716cefa1c1600cbd8d1869a83eab0b25119e1eaed49a
|
|
| MD5 |
ffabbd5dd2940298e31065f3c51a876e
|
|
| BLAKE2b-256 |
33ee1304812ad1bcd62d8ef5d5ef339b1144d501e0fa917b90636cdb193edeba
|
File details
Details for the file py_code_improver-0.2.1-py2.py3-none-any.whl.
File metadata
- Download URL: py_code_improver-0.2.1-py2.py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.5 Darwin/23.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e3a0f8c88a31e9b73736104b483538dcf3db13218f209b487f0ee5369c1d5f9
|
|
| MD5 |
53b31a4757c562544aff4e8d779d05e4
|
|
| BLAKE2b-256 |
9a7b2cf89915503e41d9140a58c66dcb0c0c4ef4f35ea03a37647f87e25af290
|