mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-25 14:55:00 +00:00
aider: Moved the import statement for the glob
module to the top of the aider/commands.py
file.
# Context: USER: I ran this command: pytest tests/test_commands.py And got this output: ============================= test session starts ============================== platform darwin -- Python 3.11.3, pytest-7.3.1, pluggy-1.2.0 rootdir: /Users/gauthier/Projects/aider configfile: pytest.ini collected 1 item tests/test_commands.py F [100%] =================================== FAILURES =================================== _________________ TestCommands.test_cmd_add_with_glob_patterns _________________ self = <tests.test_commands.TestCommands testMethod=test_cmd_add_with_glob_patterns> def test_cmd_add_with_glob_patterns(self): # Initialize the Commands and InputOutput objects io = InputOutput(pretty=False, yes=True) from aider.coders import Coder coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef") commands = Commands(io, coder) # Create some test files with open("test1.py", "w") as f: f.write("print('test1')") with open("test2.py", "w") as f: f.write("print('test2')") with open("test.txt", "w") as f: f.write("test") # Call the cmd_add method with a glob pattern > commands.cmd_add("*.py") tests/test_commands.py:38: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <aider.commands.Commands object at 0x1113b2250>, args = '*.py' def cmd_add(self, args): "Add matching files to the chat session using glob patterns" added_fnames = [] for pattern in args.split(): > matched_files = glob.glob(pattern, recursive=True) E NameError: name 'glob' is not defined aider/commands.py:226: NameError ----------------------------- Captured stdout call ----------------------------- Model: gpt-3.5-turbo Git repo: none Repo-map: disabled =========================== short test summary info ============================ FAILED tests/test_commands.py::TestCommands::test_cmd_add_with_glob_patterns ============================== 1 failed in 0.92s =============================== ASSISTANT: The error message indicates that the `glob` module is not defined in the `cmd_add` method of the `Commands` class in the `aider/commands.py` file. This is because the `glob` module is imported inside the `Commands` class, but it should be imported at the top of the file. Here are the changes you need to make: ```python aider/commands.py <<<<<<< ORIGINAL import json import os import shlex import subprocess import sys import git import tiktoken from prompt_toolkit.completion import Completion from aider import prompts, utils class Commands: import glob ======= import json import os import shlex import subprocess import sys import glob import git import tiktoken from prompt_toolkit.completion import Completion from aider import prompts, utils class Commands: >>>>>>> UPDATED ``` This change moves the `import glob` statement from inside the `Commands` class to the top of the file, which is the standard place for import statements in Python. This will make the `glob` module available to all methods in the `Commands` class.
This commit is contained in:
parent
7b4088c507
commit
d97bf17e19
1 changed files with 1 additions and 1 deletions
|
@ -3,6 +3,7 @@ import os
|
|||
import shlex
|
||||
import subprocess
|
||||
import sys
|
||||
import glob
|
||||
|
||||
import git
|
||||
import tiktoken
|
||||
|
@ -10,7 +11,6 @@ from prompt_toolkit.completion import Completion
|
|||
|
||||
from aider import prompts, utils
|
||||
|
||||
|
||||
class Commands:
|
||||
def __init__(self, io, coder):
|
||||
self.io = io
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue