Who has never been too lazy to document their code?
Auto Codebase Documenter is a tool you’ll love as it leverages the power of OpenAI’s GPT-3.5-turbo or GPT-4 to automatically evaluate and document the code you’ve written!
Great, right?
Basically, instead of spending hours documenting the structure and functionalities of your project, you will be able to take advantage of the last sunny days of the year since the tool takes care of everything for you. To paraphrase Sun Tzu in The Art of War: “The best documentation is that which generates itself.”
To start using Auto Codebase Documenter, simply install the package from PyPI via the pip
command like this:
pip install auto-codebase-documenter
You will also need to set up a suitable Python environment. I strongly suggest using a virtual environment (venv). Here’s how to do it:
- Install Python 3.9.16 or higher.
- Check your Python version by running
python --version
orpython3 --version
. - Create a virtual environment in the root directory using the command
python -m venv venv
. - Activate this environment with “source venv/bin/activate” (Unix or MacOS) or “venv\Scripts\activate” (Windows).
- Install the necessary dependencies via the command “pip install -r requirements.txt”.
Don’t forget, you’ll also need an OpenAI API key to run queries on their AI model.
Once you have installed and configured everything you need, it will then be time to let Auto Codebase Documenter do its magic! You can use it from the command line or directly as a lib for your project. Simply import the class AutoCodebaseDocumenter
and run it with the method process_all_files
.
import os
from dotenv import load_dotenv
from auto_codebase_documenter.AutoCodebaseDocumenter import AutoCodebaseDocumenter
load_dotenv()
openai_api_key = os.getenv("OPENAI_KEY")
documenter = AutoCodebaseDocumenter(openai_api_key)
documenter.process_all_files()
And that’s it, the tool will take care of the rest!
You can customize the documentation process by editing the documenter_config.yaml file and change different settings there such as code path, folders to ignore, file types to include, and much more.
One of the best things about this tool is how it organizes and structures generated Markdown (.md) files into a dedicated directory called docs. The structure of the “docs” directory exactly reflects that of your project. So each processed file corresponds to a specific Markdown file! This saves a lot of time and obviously makes your project easier to read and understand.
So, with such clear and well-organized documentation, any new developers joining your project will be able to get to work much faster. And for seasoned developers who want to get started with a code review or refactoring process, this will make things a lot easier to understand.
Finally, for those who like working with Docker, simply use the provided Dockerfile and docker-compose.yml files, and build the container using the command bash build_docker.sh
. You can then run it with the command bash run_docker.sh
.