Reference for llmcode/utils/auxiliary.py
This module provides utilities for formatting and documenting code files.
It includes functions to format code files, apply documentation functions based on programming languages, and manage temporary file operations during the documentation process.
Functions: format_code: Formats and documents code files in the specified path. _apply_to_scripts: Applies a given function to scripts in a directory, handling temporary files.
Author: Francisco Javier Gañán License File: https://github.com/javierganan99/LLMCode/blob/main/LICENSE
llmcode.utils.auxiliary.format_code
format_code(path, exclude=custom_params.exclude, languages=custom_params.languages, elements2doc=custom_params.elements2doc, overwrite=custom_params.overwrite, stop_flag=Event())
Formats code files by applying specific documentation functions based on language.
This function processes either a directory or a specific code file, excluding specified files from documentation generation, and applies predefined functions according to the code's language. It validates the input path, checks supported languages, and logs relevant information during the process. If the path is a directory, it applies the functions to all relevant scripts within.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The path to the directory or file to be formatted. |
required |
exclude
|
list
|
List of filenames or folders to exclude from documentation (default is custom_params.exclude). |
exclude
|
languages
|
list
|
List of programming languages to apply for documentation (default is custom_params.languages). |
languages
|
elements2doc
|
list
|
List of specific elements to document (default is custom_params.elements2doc). |
elements2doc
|
overwrite
|
bool
|
Flag indicating whether to overwrite existing documentation (default is custom_params.overwrite). |
overwrite
|
stop_flag
|
Event
|
A threading event to signal when to stop the process (default is Event()). |
Event()
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the formatting process was successful, False otherwise. |
Source code in llmcode/utils/auxiliary.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
llmcode.utils.auxiliary._apply_to_scripts
_apply_to_scripts(root_path, function_to_execute, extension, exclude, stop_flag=Event(), *args, **kwargs)
Applies a specified function to all scripts in a given directory with a specified extension.
This function searches the provided directory (and its subdirectories) for files that match the given extension. It allows for exclusion of specific files and applies a provided function to each of the found files, handling temporary file creation and cleanup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root_path
|
str
|
The root directory path where the scripts are located. |
required |
function_to_execute
|
callable
|
The function to execute on each found script. |
required |
extension
|
str
|
The file extension of the scripts to process. |
required |
exclude
|
list
|
A list of substrings; files containing any of these will be excluded from processing. |
required |
stop_flag
|
Event
|
A flag to signal cessation of the function execution (default is Event()). |
Event()
|
*args
|
Additional positional arguments to be passed to the function. |
()
|
|
**kwargs
|
Additional keyword arguments to be passed to the function. |
{}
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the operation was successful, otherwise None. |
Source code in llmcode/utils/auxiliary.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |