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.
This commit is contained in:
Paul Gauthier 2023-07-10 13:27:11 -07:00
parent f48aeac88b
commit 65c12a73f6

View file

@ -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)