mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-30 17:24:59 +00:00
aider: Added check_for_ctags
method to RepoMap
class and updated __init__
method to set use_ctags
to False
if check_for_ctags
returns False
.
# Context: USER: add a check_for_ctags method that: makes a tempdir with hello.py that defines a hello func. call get_tags on that and catch any error and return false. otherwise true. ASSISTANT: I will add a `check_for_ctags` method to the `RepoMap` class in the `aider/repomap.py` file. This method will create a temporary directory with a `hello.py` file that defines a `hello` function. It will then call the `get_tags` method on that file, catch any errors, and return `False` if there's an error or `True` otherwise. Here's the change: ```python aider/repomap.py <<<<<<< ORIGINAL import os import json import sys import subprocess import tiktoken ======= import os import json import sys import subprocess import tiktoken import tempfile >>>>>>> UPDATED ``` ```python aider/repomap.py <<<<<<< ORIGINAL class RepoMap: ctags_cmd = ["ctags", "--fields=+S", "--extras=-F", "--output-format=json"] def __init__(self, use_ctags=True, root=None, main_model="gpt-4"): ======= class RepoMap: ctags_cmd = ["ctags", "--fields=+S", "--extras=-F", "--output-format=json"] def __init__(self, use_ctags=True, root=None, main_model="gpt-4"): if not self.check_for_ctags(): use_ctags = False >>>>>>> UPDATED ``` ```python aider/repomap.py <<<<<<< ORIGINAL return tags if __name__ == "__main__": rm = RepoMap() res = rm.get_tags_map(sys.argv[1:]) print(res) ======= def check_for_ctags(self): try: with tempfile.TemporaryDirectory() as tempdir: hello_py = os.path.join(tempdir, "hello.py") with open(hello_py, "w") as f: f.write("def hello():\n print('Hello, world!')\n") self.get_tags(hello_py) except Exception: return False return True if __name__ == "__main__": rm = RepoMap() res = rm.get_tags_map(sys.argv[1:]) print(res) >>>>>>> UPDATED ``` This adds the `check_for_ctags` method to the `RepoMap` class and updates the `__init__` method to set `use_ctags` to `False` if `check_for_ctags` returns `False`.
This commit is contained in:
parent
711212ef3c
commit
ae087287c7
1 changed files with 14 additions and 2 deletions
|
@ -3,6 +3,7 @@ import json
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
import tiktoken
|
import tiktoken
|
||||||
|
import tempfile
|
||||||
|
|
||||||
from aider import prompts
|
from aider import prompts
|
||||||
|
|
||||||
|
@ -50,6 +51,8 @@ class RepoMap:
|
||||||
ctags_cmd = ["ctags", "--fields=+S", "--extras=-F", "--output-format=json"]
|
ctags_cmd = ["ctags", "--fields=+S", "--extras=-F", "--output-format=json"]
|
||||||
|
|
||||||
def __init__(self, use_ctags=True, root=None, main_model="gpt-4"):
|
def __init__(self, use_ctags=True, root=None, main_model="gpt-4"):
|
||||||
|
if not self.check_for_ctags():
|
||||||
|
use_ctags = False
|
||||||
if not root:
|
if not root:
|
||||||
root = os.getcwd()
|
root = os.getcwd()
|
||||||
|
|
||||||
|
@ -162,10 +165,19 @@ class RepoMap:
|
||||||
# Update the cache
|
# Update the cache
|
||||||
TAGS_CACHE[cache_key] = {"mtime": file_mtime, "tags": tags}
|
TAGS_CACHE[cache_key] = {"mtime": file_mtime, "tags": tags}
|
||||||
|
|
||||||
return tags
|
def check_for_ctags(self):
|
||||||
|
try:
|
||||||
|
with tempfile.TemporaryDirectory() as tempdir:
|
||||||
|
hello_py = os.path.join(tempdir, "hello.py")
|
||||||
|
with open(hello_py, "w") as f:
|
||||||
|
f.write("def hello():\n print('Hello, world!')\n")
|
||||||
|
self.get_tags(hello_py)
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
rm = RepoMap()
|
rm = RepoMap()
|
||||||
res = rm.get_tags_map(sys.argv[1:])
|
res = rm.get_tags_map(sys.argv[1:])
|
||||||
print(res)
|
print(res)
|
||||||
|
print(res)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue