|
10 | 10 | from gitingest.repository_clone import CloneConfig, clone_repo
|
11 | 11 |
|
12 | 12 |
|
13 |
| -async def ingest( |
| 13 | +async def ingest_async( |
14 | 14 | source: str,
|
15 | 15 | max_file_size: int = 10 * 1024 * 1024, # 10 MB
|
16 | 16 | include_patterns: set[str] | str | None = None,
|
@@ -96,3 +96,58 @@ async def ingest(
|
96 | 96 | if parsed_query.url:
|
97 | 97 | # Clean up the temporary directory
|
98 | 98 | shutil.rmtree(TMP_BASE_PATH, ignore_errors=True)
|
| 99 | + |
| 100 | + |
| 101 | +def ingest( |
| 102 | + source: str, |
| 103 | + max_file_size: int = 10 * 1024 * 1024, # 10 MB |
| 104 | + include_patterns: set[str] | str | None = None, |
| 105 | + exclude_patterns: set[str] | str | None = None, |
| 106 | + branch: str | None = None, |
| 107 | + output: str | None = None, |
| 108 | +) -> tuple[str, str, str]: |
| 109 | + """ |
| 110 | + Synchronous version of ingest_async. |
| 111 | +
|
| 112 | + This function analyzes a source (URL or local path), clones the corresponding repository (if applicable), |
| 113 | + and processes its files according to the specified query parameters. It returns a summary, a tree-like |
| 114 | + structure of the files, and the content of the files. The results can optionally be written to an output file. |
| 115 | +
|
| 116 | + Parameters |
| 117 | + ---------- |
| 118 | + source : str |
| 119 | + The source to analyze, which can be a URL (for a Git repository) or a local directory path. |
| 120 | + max_file_size : int |
| 121 | + Maximum allowed file size for file ingestion. Files larger than this size are ignored, by default |
| 122 | + 10*1024*1024 (10 MB). |
| 123 | + include_patterns : set[str] | str | None, optional |
| 124 | + Pattern or set of patterns specifying which files to include. If `None`, all files are included. |
| 125 | + exclude_patterns : set[str] | str | None, optional |
| 126 | + Pattern or set of patterns specifying which files to exclude. If `None`, no files are excluded. |
| 127 | + branch : str | None, optional |
| 128 | + The branch to clone and ingest. If `None`, the default branch is used. |
| 129 | + output : str | None, optional |
| 130 | + File path where the summary and content should be written. If `None`, the results are not written to a file. |
| 131 | +
|
| 132 | + Returns |
| 133 | + ------- |
| 134 | + tuple[str, str, str] |
| 135 | + A tuple containing: |
| 136 | + - A summary string of the analyzed repository or directory. |
| 137 | + - A tree-like string representation of the file structure. |
| 138 | + - The content of the files in the repository or directory. |
| 139 | +
|
| 140 | + See Also |
| 141 | + -------- |
| 142 | + ingest_async : The asynchronous version of this function. |
| 143 | + """ |
| 144 | + return asyncio.run( |
| 145 | + ingest_async( |
| 146 | + source=source, |
| 147 | + max_file_size=max_file_size, |
| 148 | + include_patterns=include_patterns, |
| 149 | + exclude_patterns=exclude_patterns, |
| 150 | + branch=branch, |
| 151 | + output=output, |
| 152 | + ) |
| 153 | + ) |
0 commit comments