CLI
docugenius.cli.main
RunArgs
Bases: BaseModel
A class to hold the arguments for running the docstring generation.
Attributes:
| Name | Type | Description |
|---|---|---|
input_path |
str
|
The path to the input file or directory. |
model |
str
|
The model to use for generating docstrings. Must be one of ["openai:gpt-4o", "openai:gpt-4o-mini"]. |
docstring_format |
str
|
The format of the generated docstrings. Must be one of ["google", "numpy", "sprinx"]. |
skip_raises |
bool
|
Whether to include information about exceptions raised by the code. |
skip_returns |
bool
|
Whether to include information about the return value of the code. |
skip_examples |
bool
|
Whether to include examples of how to use the code. |
output_path |
str
|
The path to the output file/destination. If not provided, the output will overwrite the input file. If a directory is passed as input, this should be a directory. |
Raises: ValueError: If the model or docstring_format is not one of the specified literals.
is_recursive()
Check if the input path is a directory or a file.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the input path is a directory, False if it is a file. |
run(args)
Run the docstring generation process based on the provided arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
RunArgs
|
The arguments for running the docstring generation. |
required |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the input file/directory does not exist. |
Exception
|
If there is an error during docstring generation. |
Returns:
| Name | Type | Description |
|---|---|---|
None |
This function does not return a value. |
Example
run(RunArgs(input_path='example.py', model='openai:gpt-4o'))
Source code in docugenius/cli/main.py
run_on_file(input_file, model, output_file=None)
Generate docstrings for the code in the specified input file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_file
|
str
|
The path to the input file. |
required |
model
|
str
|
The model to use for generating docstrings. |
required |
output_file
|
str
|
The path to the output file. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the input file does not exist. |
Exception
|
If there is an error during docstring generation. |
Returns:
| Name | Type | Description |
|---|---|---|
None |
This function does not return a value. |
Example
run_on_file('example.py', 'openai:gpt-4o')