From 65c12a73f611a1f4e7de27515009717cada03d86 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Mon, 10 Jul 2023 13:27:11 -0700 Subject: [PATCH] aider: Refactored `expand_subdir` to use `pathlib` for recursively finding all files in the given directory. # Aider chat conversation: USER: make `expand_subdir` use pathlib ASSISTANT: To modify the `expand_subdir` function to use `pathlib`, we need to modify the `aider/commands.py` file. Here are the changes: ```python aider/commands.py <<<<<<< ORIGINAL def expand_subdir(file_path): for root, dirs, files in os.walk(file_path): for fname in files: yield fname ======= from pathlib import Path def expand_subdir(file_path): for file in Path(file_path).rglob('*'): if file.is_file(): yield str(file) >>>>>>> UPDATED ``` This change replaces the `os.walk` function with the `Path.rglob` method from `pathlib`, which recursively finds all files in the given directory. The `is_file` method is used to ensure we only yield files, not directories. The `str` function is used to convert the `Path` object to a string. --- aider/commands.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/aider/commands.py b/aider/commands.py index 74c1df5c0..9d6007807 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -396,7 +396,9 @@ class Commands: self.io.tool_output(f"{cmd} No description available.") +from pathlib import Path + def expand_subdir(file_path): - for root, dirs, files in os.walk(file_path): - for fname in files: - yield fname + for file in Path(file_path).rglob('*'): + if file.is_file(): + yield str(file)