forked from raphaelmansuy/code2prompt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Modify the
process_files
function to handle processing of a singl…
…e file or a directory - Update the `should_process_file` function to simplify and clarify the criteria for processing a file - Remove unnecessary comments from the code - Improve code readability and maintainability
- Loading branch information
1 parent
76db915
commit 30480bc
Showing
3 changed files
with
102 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,34 @@ | ||
from pathlib import Path | ||
from code2prompt.get_gitignore_patterns import get_gitignore_patterns | ||
from code2prompt.process_file import process_file | ||
from code2prompt.should_process_file import should_process_file | ||
|
||
|
||
from pathlib import Path | ||
|
||
|
||
def process_files(options): | ||
""" | ||
Processes files within a specified directory, applying filters and transformations | ||
based on the provided options. | ||
Processes files or a single file based on the provided path. | ||
Args: | ||
options (dict): A dictionary containing options such as path, gitignore patterns, | ||
and flags for processing files. | ||
options (dict): A dictionary containing options such as path, gitignore patterns, and flags for processing files. | ||
Returns: | ||
list: A list of dictionaries containing processed file data. | ||
list: A list of dictionaries containing processed file data. | ||
""" | ||
path = Path(options['path']) | ||
gitignore_patterns = get_gitignore_patterns(path, options['gitignore']) | ||
gitignore_patterns = get_gitignore_patterns(path.parent if path.is_file() else path, options['gitignore']) | ||
files_data = [] | ||
for file_path in path.rglob("*"): | ||
if should_process_file(file_path, gitignore_patterns, path, options): | ||
result = process_file(file_path, options['suppress_comments'], options['line_number'], options['no_codeblock']) | ||
|
||
if path.is_file(): | ||
# Process single file | ||
if should_process_file(path, gitignore_patterns, path.parent, options): | ||
result = process_file(path, options['suppress_comments'], options['line_number'], options['no_codeblock']) | ||
if result: | ||
files_data.append(result) | ||
else: | ||
# Process directory | ||
for file_path in path.rglob("*"): | ||
if should_process_file(file_path, gitignore_patterns, path, options): | ||
result = process_file(file_path, options['suppress_comments'], options['line_number'], options['no_codeblock']) | ||
if result: | ||
files_data.append(result) | ||
|
||
return files_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters