This Python script processes all the files in a source directory, adds comments to the code using Google's Generative AI model (Gemini), and saves the processed files to a specified destination directory. It also supports excluding certain file types and directories, including hidden directories.
- Python 3.7 or higher: Ensure you have Python installed on your system.
- Google Generative AI SDK: Install the
google-generativeai
package. - GEMINI API Key: You need a GEMINI API key to use the Generative AI model if default one is unavailable.
You can get the script by going to Releases Section in the Github repositor
-
Install Required Packages:
pip install google-generativeai
-
Set GEMINI API Key: Replace
'your api'
with your actual GEMINI API key in the script. -
Exclusion Lists:
extension_exclusion_list.txt
: Contains file extensions to exclude.folder_exclusion_list.txt
: Contains folder names to exclude. If these files do not exist, the script will prompt you to create default lists.
pip install AutoNotater
The script can be run from the command line with various options:
[ If using the script ]
python WriteComments.py [--src SRC_DIRECTORY] [--out DST_DIRECTORY] [--excludeHiddenDirs true|false]
or
[ If installed by pip ]
AutoNotater [--src SRC_DIRECTORY] [--out DST_DIRECTORY] [--excludeHiddenDirs true|false]
Using it without any arguments will prompt you to generate exclusion lists if they aren't in current directory. It is recommended to generate them.
After that it will create a new "Generated" folder and start going through each file in the current directory and start putting modified files with comments in the Generated Folder.
--src
: Sets the source directory. Default is the current directory (./
).--out
: Sets the destination directory. Default is./Generated
.--excludeHiddenDirs
: Exclude hidden directories. Default istrue
.
To process files from a source directory (./source
) and save them to a destination directory (./output
) while excluding hidden directories:
[ If using the script ]
python script.py --src ./source --out ./output --excludeHiddenDirs true
or
[ If installed by pip ]
AutoNotater --src ./source --out ./output --excludeHiddenDirs true
The script supports exclusion lists for file extensions and folder names:
- File Extensions:
- Default list includes common binary and non-code file extensions such as
.ico
,.jpg
,.pdf
, etc.
- Default list includes common binary and non-code file extensions such as
- Folders:
- Default list includes common temporary and environment directories such as
__pycache__
,node_modules
,.git
, etc.
- Default list includes common temporary and environment directories such as
These lists are stored in extension_exclusion_list.txt
and folder_exclusion_list.txt
, respectively. If these files do not exist, the script will prompt to create them with default values.
- Ensure that the destination directory is different from the source directory to avoid infinite loops and potential data loss.
- The script assumes that the content in files is UTF-8 encoded.
It would be a great help if you contribute to the code of the script. It will also be helpful for everyone if you add folder names and file extensions in the exclusion list.
For issues, please open a ticket on the project's GitHub repository -