From 5801bd9ca49976faca4e5ac027a5cd9276820fe4 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 30 May 2023 13:53:31 -0700 Subject: [PATCH 1/3] aider: Moved `TAGS_CACHE` into the `RepoMap` class. # Context: USER: move `TAGS_CACHE` into the class ASSISTANT: To move the `TAGS_CACHE` into the `RepoMap` class, I will make the following changes: ```python aider/repomap.py <<<<<<< ORIGINAL # Global cache for tags TAGS_CACHE = {} ======= >>>>>>> UPDATED ``` ```python aider/repomap.py <<<<<<< ORIGINAL class RepoMap: ctags_cmd = ["ctags", "--fields=+S", "--extras=-F", "--output-format=json"] def __init__(self, use_ctags=None, root=None, main_model="gpt-4"): ======= class RepoMap: ctags_cmd = ["ctags", "--fields=+S", "--extras=-F", "--output-format=json"] TAGS_CACHE = {} def __init__(self, use_ctags=None, root=None, main_model="gpt-4"): >>>>>>> UPDATED ``` Now, the `TAGS_CACHE` is a class attribute of the `RepoMap` class. --- aider/repomap.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/aider/repomap.py b/aider/repomap.py index 510a075fb..8e51cc8e9 100644 --- a/aider/repomap.py +++ b/aider/repomap.py @@ -8,8 +8,6 @@ import tiktoken from aider import prompts -# Global cache for tags -TAGS_CACHE = {} # from aider.dump import dump @@ -48,10 +46,11 @@ def fname_to_components(fname, with_colon): return res -class RepoMap: - ctags_cmd = ["ctags", "--fields=+S", "--extras=-F", "--output-format=json"] + class RepoMap: + ctags_cmd = ["ctags", "--fields=+S", "--extras=-F", "--output-format=json"] + TAGS_CACHE = {} - def __init__(self, use_ctags=None, root=None, main_model="gpt-4"): + def __init__(self, use_ctags=None, root=None, main_model="gpt-4"): if not root: root = os.getcwd() self.root = root From 77d20b68193faa5ea78776f769013cb7ae668b84 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 30 May 2023 13:54:56 -0700 Subject: [PATCH 2/3] Fixed TAGS_CACHE --- aider/repomap.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/aider/repomap.py b/aider/repomap.py index 8e51cc8e9..19ae127b7 100644 --- a/aider/repomap.py +++ b/aider/repomap.py @@ -8,7 +8,6 @@ import tiktoken from aider import prompts - # from aider.dump import dump @@ -46,15 +45,17 @@ def fname_to_components(fname, with_colon): return res - class RepoMap: - ctags_cmd = ["ctags", "--fields=+S", "--extras=-F", "--output-format=json"] - TAGS_CACHE = {} +class RepoMap: + ctags_cmd = ["ctags", "--fields=+S", "--extras=-F", "--output-format=json"] + TAGS_CACHE = None - def __init__(self, use_ctags=None, root=None, main_model="gpt-4"): + def __init__(self, use_ctags=None, root=None, main_model="gpt-4"): if not root: root = os.getcwd() self.root = root + self.TAGS_CACHE = dict() + if use_ctags is None: self.use_ctags = self.check_for_ctags() else: @@ -135,8 +136,8 @@ def fname_to_components(fname, with_colon): # Check if the file is in the cache and if the modification time has not changed file_mtime = os.path.getmtime(filename) cache_key = filename - if cache_key in TAGS_CACHE and TAGS_CACHE[cache_key]["mtime"] == file_mtime: - return TAGS_CACHE[cache_key]["tags"] + if cache_key in self.TAGS_CACHE and self.TAGS_CACHE[cache_key]["mtime"] == file_mtime: + return self.TAGS_CACHE[cache_key]["tags"] cmd = self.ctags_cmd + [filename] output = subprocess.check_output(cmd).decode("utf-8") @@ -165,7 +166,7 @@ def fname_to_components(fname, with_colon): tags.append(res) # Update the cache - TAGS_CACHE[cache_key] = {"mtime": file_mtime, "tags": tags} + self.TAGS_CACHE[cache_key] = {"mtime": file_mtime, "tags": tags} return tags def check_for_ctags(self): From 5d4fd15a218a281abbf7471d821538425e09e026 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 30 May 2023 13:55:28 -0700 Subject: [PATCH 3/3] do isort first --- .pre-commit-config.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 068be9acd..95b449726 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,9 @@ repos: + - repo: https://github.com/pycqa/isort + rev: 5.12.0 + hooks: + - id: isort + args: ["--profile", "black"] - repo: https://github.com/psf/black rev: 23.3.0 hooks: @@ -9,8 +14,3 @@ repos: hooks: - id: flake8 args: ["--show-source"] - - repo: https://github.com/pycqa/isort - rev: 5.12.0 - hooks: - - id: isort - args: ["--profile", "black"]