The run
command is the main entry point for the code generation and analysis process. It orchestrates the entire workflow, from processing the source files to generating documentation and analyzing the differences between the original and generated code.
Usage:
python -m code_diff_doc_gen run <source_dir> [--round <round_num>]
Arguments:
source_dir
(required): The path to the directory containing the source code files. This directory will be recursively searched for files.
Options:
--round <round_num>
(optional): Specifies the generation round number. Defaults to 0. This number is used to organize the output files in the.codescribe
directory.
Functionality:
The run
command performs the following steps:
-
Workspace Initialization: Ensures that the necessary workspace directories (
.codescribe/descriptions
,.codescribe/generated
,.codescribe/analysis
) exist. If not, they are created. -
File Processing: Calls the
process_files
function (fromsrc/code_diff_doc_gen/processor.py
) to extract descriptions from the source code files in the specifiedsource_dir
. These descriptions are stored in the.codescribe/descriptions
directory. -
Code Generation: Calls the
generate_code
function (fromsrc/code_diff_doc_gen/generator.py
) to generate code based on the extracted descriptions. The generated code is stored in the.codescribe/generated/round_<round_num>
directory. -
Difference Analysis: Calls the
compare_files
function (fromsrc/code_diff_doc_gen/diff.py
) to compare the original source files with the generated code. The analysis of the differences is stored in the.codescribe/analysis/round_<round_num>
directory. -
System Prompt Generation: Calls the
generate_system_prompt_from_analyses
function (fromsrc/code_diff_doc_gen/llm.py
) to create a system prompt for the next round of code generation, based on the analysis of the differences. This prompt is saved in the.codescribe/prompts
directory. -
Error Handling: Catches any exceptions that occur during the process and logs them using Loguru. If an exception occurs, the program exits with a non-zero exit code.
Example:
To process the source code in the my_project
directory and perform the first round of generation (round 0), you would use the following command:
python -m code_diff_doc_gen run my_project
To perform the second round of generation (round 1), you would use:
python -m code_diff_doc_gen run my_project --round 1