Commit graph

1219 commits

Author SHA1 Message Date
Paul Gauthier
43413654bd enable ctags if present 2023-05-26 16:03:24 -07:00
Paul Gauthier
ae087287c7 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`.
2023-05-26 15:57:31 -07:00
Paul Gauthier
711212ef3c refac 2023-05-26 15:52:35 -07:00
Paul Gauthier
32289bc40f fixed bug caught in tests 2023-05-26 15:50:35 -07:00
Paul Gauthier
7fe7f1e279 fix 2023-05-26 15:48:26 -07:00
Paul Gauthier
6b5c93f046 refac 2023-05-26 15:45:26 -07:00
Paul Gauthier
a7aa95b18c aider: Fixed indentation for get_git_root() function and following lines.
# Context:
USER: fix the indentation!
ASSISTANT: I apologize for the indentation issue. Here's the corrected version of the `aider/main.py` file:

```python
aider/main.py
<<<<<<< ORIGINAL
def main(args=None, input=None, output=None):
    if args is None:
        args = sys.argv[1:]

    load_dotenv()
    env_prefix = "AIDER_"
    def get_git_root():
    try:
        repo = git.Repo(search_parent_directories=True)
        return repo.working_tree_dir
    except git.InvalidGitRepositoryError:
        return None

default_config_files = [
    os.path.expanduser("~/.aider.conf.yml"),
]

git_root = get_git_root()
if git_root:
    default_config_files.insert(0, os.path.join(git_root, ".aider.conf.yml"))
=======
def main(args=None, input=None, output=None):
    if args is None:
        args = sys.argv[1:]

    load_dotenv()
    env_prefix = "AIDER_"

    def get_git_root():
        try:
            repo = git.Repo(search_parent_directories=True)
            return repo.working_tree_dir
        except git.InvalidGitRepositoryError:
            return None

    default_config_files = [
        os.path.expanduser("~/.aider.conf.yml"),
    ]

    git_root = get_git_root()
    if git_root:
        default_config_files.insert(0, os.path.join(git_root, ".aider.conf.yml"))
>>>>>>> UPDATED
```

This update fixes the indentation for the `get_git_root()` function and the following lines.
2023-05-26 15:44:49 -07:00
Paul Gauthier
05e976a2b6 aider: Set default configuration file path to prefer Git repository root and fallback to user's home directory.
# Context:
USER: give them both, preferring the git one
ASSISTANT: To set the default configuration file path to prefer the Git repository root and fallback to the user's home directory, update the `aider/main.py` file with the following changes:

```python
aider/main.py
<<<<<<< ORIGINAL
git_root = get_git_root()
if git_root:
    default_config_file = os.path.join(git_root, ".aider.conf.yml")
else:
    default_config_file = os.path.expanduser("~/.aider.conf.yml")
=======
default_config_files = [
    os.path.expanduser("~/.aider.conf.yml"),
]

git_root = get_git_root()
if git_root:
    default_config_files.insert(0, os.path.join(git_root, ".aider.conf.yml"))

>>>>>>> UPDATED
```

```python
aider/main.py
<<<<<<< ORIGINAL
parser = configargparse.ArgumentParser(
    description="aider - chat with GPT about your code",
    add_config_file_help=True,
    default_config_files=[default_config_file],
)
=======
parser = configargparse.ArgumentParser(
    description="aider - chat with GPT about your code",
    add_config_file_help=True,
    default_config_files=default_config_files,
)
>>>>>>> UPDATED
```

These changes will set the `default_config_files` list to include both the Git repository root and the user's home directory, with preference given to the Git repository root.
2023-05-26 15:43:49 -07:00
Paul Gauthier
e17265c998 aider: Set default config file path based on whether the current working directory is part of a Git repository or not.
# Context:
USER: where does configargparse look for the config file?
ASSISTANT: `configargparse` looks for the configuration file in the locations specified by the `add_config_file_help` and `default_config_files` arguments when creating an `ArgumentParser` instance. If these arguments are not provided, it does not look for a configuration file by default.

To specify the locations for the configuration file, you can do the following:

```python
parser = configargparse.ArgumentParser(
    description="aider - chat with GPT about your code",
    add_config_file_help=True,
    default_config_files=["./config.ini", "/etc/aider/config.ini"],
)
```

In this example, `configargparse` will look for the configuration file in the current directory with the name `config.ini` and in the `/etc/aider/` directory with the same name. If a configuration file is found, the values from the file will be used as default values for the arguments.
USER: can it search parent dirs for the conf file
ASSISTANT: Yes, `configargparse` can search parent directories for the configuration file. You can use a loop to generate a list of configuration file paths in parent directories and pass it to the `default_config_files` argument. Here's an example:

```python
import os

def generate_config_paths(filename):
    config_paths = []
    current_dir = os.path.abspath(os.getcwd())

    while True:
        config_path = os.path.join(current_dir, filename)
        config_paths.append(config_path)

        parent_dir = os.path.dirname(current_dir)
        if parent_dir == current_dir:
            break

        current_dir = parent_dir

    return config_paths

config_file_name = "config.ini"
config_paths = generate_config_paths(config_file_name)

parser = configargparse.ArgumentParser(
    description="aider - chat with GPT about your code",
    add_config_file_help=True,
    default_config_files=config_paths,
)
```

This code will generate a list of configuration file paths in parent directories with the given `config_file_name` and pass it to the `default_config_files` argument. `configargparse` will search for the configuration file in the specified paths.
USER: nah. instead, see if cwd is part of a git repo. if so, make the default be the working dir of the repo/.aider.conf.yml, otherwise expand ~/.aider.conf.yml
ASSISTANT: To achieve this, you can use the `git` command to check if the current working directory is part of a Git repository and then set the default configuration file path accordingly. Here's how you can do it:

```python
import os
import subprocess

def get_git_root():
    try:
        git_root = subprocess.check_output(["git", "rev-parse", "--
^C KeyboardInterrupt
USER: use import git
ASSISTANT: To use the `git` Python library, first, make sure it's installed. You can install it using pip:

```
pip install GitPython
```

Then, you can modify the code to use the `git` library to check if the current working directory is part of a Git repository and set the default configuration file path accordingly:

```python
import os
import git
import configargparse

def get_git_root():
    try:
        repo = git.Repo(search_parent_directories=True)
        return repo.working_tree_dir
    except git.InvalidGitRepositoryError:

^C KeyboardInterrupt
USER: as an edit block
ASSISTANT: First, install the `GitPython` library if you haven't already:

```
pip install GitPython
```

Then, update the `aider/main.py` file with the following changes:

```python
aider/main.py
<<<<<<< ORIGINAL
import sys
import configargparse
from dotenv import load_dotenv
from aider.coder import Coder
from aider.io import InputOutput
=======
import os
import sys
import git
import configargparse
from dotenv import load_dotenv
from aider.coder import Coder
from aider.io import InputOutput
>>>>>>> UPDATED

```

```python
aider/main.py
<<<<<<< ORIGINAL
parser = configargparse.ArgumentParser(description="aider - chat with GPT about your code")
=======
def get_git_root():
    try:
        repo = git.Repo(search_parent_directories=True)
        return repo.working_tree_dir
    except git.InvalidGitRepositoryError:
        return None

git_root = get_git_root()
if git_root:
    default_config_file = os.path.join(git_root, ".aider.conf.yml")
else:
    default_config_file = os.path.expanduser("~/.aider.conf.yml")

parser = configargparse.ArgumentParser(
    description="aider - chat with GPT about your code",
    add_config_file_help=True,
    default_config_files=[default_config_file],
)
>>>>>>> UPDATED
```

These changes will import the `git` library and define a `get_git_root()` function to find the Git repository root. The default configuration file path will be set to either the repository root with `.aider.conf.yml` or the user's home directory with `.aider.conf.yml`.
2023-05-26 15:42:44 -07:00
Paul Gauthier
80c195b323 aider: Removed ${env_prefix}XXXX info from help strings in aider/main.py.
# Context:
USER: don't include the ${env_prefix}XXXX info in the help strings. configargparse adds that info to the help message automatically
ASSISTANT: I will remove the `${env_prefix}XXXX` info from the help strings in the `aider/main.py` file.

```python
aider/main.py
<<<<<<< ORIGINAL
        help=(
            "Specify the chat input history file (default: .aider.input.history,"
            f" ${env_prefix}INPUT_HISTORY_FILE)"
        ),
=======
        help="Specify the chat input history file (default: .aider.input.history)",
>>>>>>> UPDATED

```python
aider/main.py
<<<<<<< ORIGINAL
        help=(
            "Specify the chat history file (default: .aider.chat.history.md,"
            f" ${env_prefix}CHAT_HISTORY_FILE)"
        ),
=======
        help="Specify the chat history file (default: .aider.chat.history.md)",
>>>>>>> UPDATED

```python
aider/main.py
<<<<<<< ORIGINAL
        help=f"Specify the model to use for the main chat (default: gpt-4, ${env_prefix}MODEL)",
=======
        help="Specify the model to use for the main chat (default: gpt-4)",
>>>>>>> UPDATED

```python
aider/main.py
<<<<<<< ORIGINAL
        help=f"Disable pretty, colorized output (${env_prefix}PRETTY)",
=======
        help="Disable pretty, colorized output",
>>>>>>> UPDATED

```python
aider/main.py
<<<<<<< ORIGINAL
        help=f"Disable auto commit of changes (${env_prefix}AUTO_COMMITS)",
=======
        help="Disable auto commit of changes",
>>>>>>> UPDATED

```python
aider/main.py
<<<<<<< ORIGINAL
        help=f"Show diffs when committing changes (default: False, ${env_prefix}SHOW_DIFFS)",
=======
        help="Show diffs when committing changes (default: False)",
>>>>>>> UPDATED

```python
aider/main.py
<<<<<<< ORIGINAL
        help=(
            "Add ctags to the chat to help GPT understand the codebase (default: False,"
            f" ${env_prefix}CTAGS)"
        ),
=======
        help="Add ctags to the chat to help GPT understand the codebase (default: False)",
>>>>>>> UPDATED
2023-05-26 13:07:19 -07:00
Paul Gauthier
17184dd2df added configargparse 2023-05-26 13:04:48 -07:00
Paul Gauthier
a886ea472b Stronger prompting to only modify full files, not parts of the repo map 2023-05-26 12:59:08 -07:00
Paul Gauthier
4e557baad4 cleaned up /exit, normalized /help 2023-05-26 12:21:43 -07:00
Paul Gauthier
c40d763bce aider: Added /exit command to aider/commands.py.
# Context:
USER: add an /exit command which calls sys.exit
ASSISTANT: To add an `/exit` command, we need to modify the `commands.py` file to add a new command method and update the `is_command` and `run` methods to recognize and execute the new command. We also need to import `sys` to use `sys.exit()`.

Here are the changes:

```python
aider/commands.py
<<<<<<< ORIGINAL
from . import io
=======
import sys
from . import io
>>>>>>> UPDATED
```

```python
aider/commands
^C KeyboardInterrupt
USER: I added the content of these additional files: aider/commands.py
ASSISTANT: I apologize for the confusion. Here are the changes to add the `/exit` command to the `aider/commands.py` file:

```python
aider/commands.py
<<<<<<< ORIGINAL
import os
import git
import subprocess
import shlex
=======
import sys
import os
import git
import subprocess
import shlex
>>>>>>> UPDATED
```

```python
aider/commands.py
<<<<<<< ORIGINAL
        commands = ["/help"]
=======
        commands = ["/help", "/exit"]
>>>>>>> UPDATED
```

```python
aider/commands.py
<<<<<<< ORIGINAL
        else:
            self.io.tool_error(f"Error: {first_word} is not a valid command.")
=======
        elif first_word == "/exit":
            self.cmd_exit()
        else:
            self.io.tool_error(f"Error: {first_word} is not a valid command.")
>>>>>>> UPDATED
```

```python
aider/commands.py
<<<<<<< ORIGINAL
    def cmd_ls(self, args):
        "List all known files and those included in the chat session"
=======
    def cmd_exit(self):
        "Exit the application"
        sys.exit()

    def cmd_ls(self, args):
        "List all known files and those included in the chat session"
>>>>>>> UPDATED
```

These changes will add the `/exit` command to the list of commands, recognize it when entered, and call the `cmd_exit` method to exit the application using `sys.exit()`.
2023-05-26 12:16:59 -07:00
Paul Gauthier
7cc9cdfb21 Merge remote-tracking branch 'origin/main' 2023-05-26 07:11:55 -07:00
Paul Gauthier
38a49beea8 copy 2023-05-26 07:11:46 -07:00
paul-gauthier
ecea4aae35
Update ctags.md 2023-05-25 22:33:02 -07:00
Paul Gauthier
be8b9c1f52 Merge remote-tracking branch 'origin/main' 2023-05-25 21:47:06 -07:00
Paul Gauthier
34ac7bcf09 copy 2023-05-25 21:46:24 -07:00
paul-gauthier
b32dd26743
Update ctags.md 2023-05-25 21:01:41 -07:00
Paul Gauthier
436e15eab2 copy 2023-05-25 19:50:15 -07:00
Paul Gauthier
58ff867d1a copy 2023-05-25 19:36:48 -07:00
Paul Gauthier
0108c3c0f7 copy 2023-05-25 19:18:11 -07:00
Paul Gauthier
30eab47432 copy 2023-05-25 19:12:31 -07:00
Paul Gauthier
23c4e654e1 copy 2023-05-25 19:09:59 -07:00
Paul Gauthier
c3f8583220 copy 2023-05-25 13:27:55 -07:00
Paul Gauthier
28fd7b05b4 copy 2023-05-25 13:24:06 -07:00
Paul Gauthier
5cd4c1c41b copy 2023-05-25 13:23:43 -07:00
Paul Gauthier
f0c001f791 copy 2023-05-25 13:21:39 -07:00
Paul Gauthier
790a0cc3e3 copy 2023-05-25 11:58:15 -07:00
Paul Gauthier
3813e85fce copy 2023-05-25 11:39:54 -07:00
Paul Gauthier
0923f16044 copy 2023-05-25 11:33:26 -07:00
Paul Gauthier
023726db11 copy 2023-05-25 11:24:34 -07:00
Paul Gauthier
94b216ab0f copy 2023-05-25 10:52:33 -07:00
Paul Gauthier
ead85e8e96 copy 2023-05-25 10:46:26 -07:00
Paul Gauthier
96c63dfb66 copy 2023-05-25 09:02:45 -07:00
Paul Gauthier
4f1ec79220 Improved RateLimitError message 2023-05-25 08:53:55 -07:00
Paul Gauthier
61c0892f58 bumped version 2023-05-25 08:28:57 -07:00
Paul Gauthier
d13a794b8d Merge branch 'main' into dynamic-map 2023-05-25 08:27:42 -07:00
Paul Gauthier
e79b855ccf copy 2023-05-25 06:41:34 -07:00
Paul Gauthier
60031ecd29 fixed bug found by testing 2023-05-24 19:09:05 -07:00
Paul Gauthier
82804e2a6c aider: Updated test to check for correct format of file in result.
# Context:
USER: I ran this command:

 pytest tests/test_repomap.py

And got this output:

============================= test session starts ==============================
platform darwin -- Python 3.11.3, pytest-7.3.1, pluggy-1.0.0
rootdir: /Users/gauthier/Projects/aider
collected 3 items

tests/test_repomap.py ..F                                                [100%]

=================================== FAILURES ===================================
_________________ TestRepoMap.test_get_tags_map_without_ctags __________________

self = <tests.test_repomap.TestRepoMap testMethod=test_get_tags_map_without_ctags>

    def test_get_tags_map_without_ctags(self):
        # Create a temporary directory with a sample Python file containing identifiers
        test_files = [
            "test_file_without_ctags.py",
            "test_file1.txt",
            "test_file2.md",
            "test_file3.json",
            "test_file4.html",
            "test_file5.css",
            "test_file6.js",
        ]

        with tempfile.TemporaryDirectory() as temp_dir:
            for file in test_files:
                with open(os.path.join(temp_dir, file), "w") as f:
                    f.write("")

            repo_map = RepoMap(use_ctags=False, root=temp_dir)
            other_files = [os.path.join(temp_dir, file) for file in test_files]
            result = repo_map.get_tags_map(other_files)

            # Check if the result contains each specific file in the expected tags map without ctags
            for file in test_files:
>               self.assertIn(f"{os.path.splitext(file)[0]}:", result)
E               AssertionError: 'test_file_without_ctags:' not found in 'test_file1.txt:\ntest_file4.html:\ntest_file5.css:\ntest_file6.js:\ntest_file_without_ctags.py:\n'

tests/test_repomap.py:80: AssertionError
=========================== short test summary info ============================
FAILED tests/test_repomap.py::TestRepoMap::test_get_tags_map_without_ctags - ...
========================= 1 failed, 2 passed in 0.39s ==========================

ASSISTANT: It seems that the test `test_get_tags_map_without_ctags` is failing because the expected string 'test_file_without_ctags:' is not found in the result. The result contains 'test_file_without_ctags.py:', which is the correct format. I will update the test to fix this issue.

```python
tests/test_repomap.py
<<<<<<< ORIGINAL
            for file in test_files:
                self.assertIn(f"{os.path.splitext(file)[0]}:", result)
=======
            for file in test_files:
                self.assertIn(f"{os.path.splitext(file)[0]}.{os.path.splitext(file)[1][1:]}:", result)
>>>>>>> UPDATED
```

This update changes the test to check for the correct format of the file in the result. Now you can run the test again with the `pytest tests/test_repomap.py` command.
2023-05-24 19:06:39 -07:00
Paul Gauthier
0fa1345ed0 aider: Updated test_get_tags_map_without_ctags test in tests/test_repomap.py to check if each specific file is in the result.
# Context:
USER: that test needs to check if each specific file is in the result, not test_get_tags_map_without_ctags
ASSISTANT: I will update the `test_get_tags_map_without_ctags` test in the `tests/test_repomap.py` file to check if each specific file is in the result.

```python
tests/test_repomap.py
<<<<<<< ORIGINAL
            # Check if the result contains the expected tags map without ctags
            self.assertIn("test_file_without_ctags.py:", result)
=======
            # Check if the result contains each specific file in the expected tags map without ctags
            for file in test_files:
                self.assertIn(f"{os.path.splitext(file)[0]}:", result)
>>>>>>> UPDATED
```

This update checks if each specific file is in the result of the `get_tags_map` function when `ctags=False`.
2023-05-24 19:05:55 -07:00
Paul Gauthier
ec4b5dc2c3 aider: Updated test to not put anything in the file and add more files of various kinds.
# Context:
USER: update that test to not put anything in the file. add a bunch more files of various kinds. check them all.
ASSISTANT: I will update the `test_get_tags_map_without_ctags` test in the `tests/test_repomap.py` file to not put any content in the Python file and add more files of various kinds.

```python
tests/test_repomap.py
<<<<<<< ORIGINAL
        test_file = "test_file_without_ctags.py"
        file_content = """\
class MyClass:
    def my_method(self, arg1, arg2):
        return arg1 + arg2

def my_function(arg1, arg2):
    return arg1 * arg2
"""

        with tempfile.TemporaryDirectory() as temp_dir:
            with open(os.path.join(temp_dir, test_file), "w") as f:
                f.write(file_content)

            repo_map = RepoMap(use_ctags=False, root=temp_dir)
            other_files = [os.path.join(temp_dir, test_file)]
            result = repo_map.get_tags_map(other_files)
=======
        test_files = [
            "test_file_without_ctags.py",
            "test_file1.txt",
            "test_file2.md",
            "test_file3.json",
            "test_file4.html",
            "test_file5.css",
            "test_file6.js",
        ]

        with tempfile.TemporaryDirectory() as temp_dir:
            for file in test_files:
                with open(os.path.join(temp_dir, file), "w") as f:
                    f.write("")

            repo_map = RepoMap(use_ctags=False, root=temp_dir)
            other_files = [os.path.join(temp_dir, file) for file in test_files]
            result = repo_map.get_tags_map(other_files)
>>>>>>> UPDATED
```

This update removes the content from the Python file and adds more files of various kinds. The test checks if the `get_tags_map` function returns the expected tags map containing all the files when `ctags=False`.
2023-05-24 19:04:43 -07:00
Paul Gauthier
45442b99e1 aider: Added test to check if get_tags_map function returns the expected tags map containing the file when ctags=False.
# Context:
USER: add another like that, but with ctags=False. just make sure the file is in the result.
ASSISTANT: I will add a new test to the `tests/test_repomap.py` file that checks if the file is in the result when `ctags=False`.

```python
tests/test_repomap.py
<<<<<<< ORIGINAL
            self.assertIn("my_function", result)

if __name__ == "__main__":
    unittest.main()
=======
            self.assertIn("my_function", result)

    def test_get_tags_map_without_ctags(self):
        # Create a temporary directory with a sample Python file containing identifiers
        test_file = "test_file_without_ctags.py"
        file_content = """\
class MyClass:
    def my_method(self, arg1, arg2):
        return arg1 + arg2

def my_function(arg1, arg2):
    return arg1 * arg2
"""

        with tempfile.TemporaryDirectory() as temp_dir:
            with open(os.path.join(temp_dir, test_file), "w") as f:
                f.write(file_content)

            repo_map = RepoMap(use_ctags=False, root=temp_dir)
            other_files = [os.path.join(temp_dir, test_file)]
            result = repo_map.get_tags_map(other_files)

            # Check if the result contains the expected tags map without ctags
            self.assertIn("test_file_without_ctags.py:", result)

if __name__ == "__main__":
    unittest.main()
>>>>>>> UPDATED
```

This new test creates a temporary directory with a sample Python file containing a class, a method, and a function. It then checks if the `get_tags_map` function returns the expected tags map containing the file when `ctags=False`.
2023-05-24 19:02:37 -07:00
Paul Gauthier
8f2447078c aider: Added a new test to check if the get_tags_map function returns the expected tags map containing the identifiers from a Python file.
# Context:
USER: add another test. pass in a python file which defines a few identifiers. make sure they appear in the map.
ASSISTANT: I will add a new test to the `tests/test_repomap.py` file that checks if the identifiers from a Python file appear in the map.

```python
tests/test_repomap.py
<<<<<<< ORIGINAL
            self.assertNotIn("test_file4.json:", result)

if __name__ == "__main__":
    unittest.main()
=======
            self.assertNotIn("test_file4.json:", result)

    def test_get_tags_map_with_identifiers(self):
        # Create a temporary directory with a sample Python file containing identifiers
        test_file = "test_file_with_identifiers.py"
        file_content = """\
class MyClass:
    def my_method(self, arg1, arg2):
        return arg1 + arg2

def my_function(arg1, arg2):
    return arg1 * arg2
"""

        with tempfile.TemporaryDirectory() as temp_dir:
            with open(os.path.join(temp_dir, test_file), "w") as f:
                f.write(file_content)

            repo_map = RepoMap(root=temp_dir)
            other_files = [os.path.join(temp_dir, test_file)]
            result = repo_map.get_tags_map(other_files)

            # Check if the result contains the expected tags map with identifiers
            self.assertIn("test_file_with_identifiers.py:", result)
            self.assertIn("MyClass", result)
            self.assertIn("my_method", result)
            self.assertIn("my_function", result)

if __name__ == "__main__":
    unittest.main()
>>>>>>> UPDATED
```

This new test creates a temporary directory with a sample Python file containing a class, a method, and a function. It then checks if the `get_tags_map` function returns the expected tags map containing the identifiers from the Python file.
2023-05-24 19:01:02 -07:00
Paul Gauthier
c8c0e6232f aider: Added import statement for tempfile module in tests/test_repomap.py.
# Context:
USER: I ran this command:

 pytest tests/test_repomap.py

And got this output:

============================= test session starts ==============================
platform darwin -- Python 3.11.3, pytest-7.3.1, pluggy-1.0.0
rootdir: /Users/gauthier/Projects/aider
collected 1 item

tests/test_repomap.py F                                                  [100%]

=================================== FAILURES ===================================
________________________ TestRepoMap.test_get_tags_map _________________________

self = <tests.test_repomap.TestRepoMap testMethod=test_get_tags_map>

    def test_get_tags_map(self):
        # Create a temporary directory with sample files for testing
        test_files = [
            "test_file1.py",
            "test_file2.py",
            "test_file3.md",
            "test_file4.json",
        ]

>       with tempfile.TemporaryDirectory() as temp_dir:
E       NameError: name 'tempfile' is not defined

tests/test_repomap.py:15: NameError
=========================== short test summary info ============================
FAILED tests/test_repomap.py::TestRepoMap::test_get_tags_map - NameError: nam...
============================== 1 failed in 0.05s ===============================

ASSISTANT: It looks like the `tempfile` module is not imported in the `tests/test_repomap.py` file. I will add the import statement for you.

```python
tests/test_repomap.py
<<<<<<< ORIGINAL
import os
import unittest
from aider.repomap import RepoMap
=======
import os
import tempfile
import unittest
from aider.repomap import RepoMap
>>>>>>> UPDATED
```

Now, you can run the test again with the `pytest tests/test_repomap.py` command.
2023-05-24 18:59:12 -07:00
Paul Gauthier
452d31089b aider: Added a test for the get_tags_map function in the aider/repomap.py file.
# Context:
USER: write a test for get_tags_map
ASSISTANT: I need to know the expected behavior of the `get_tags_map` function in the `repomap.py` file. Please provide a brief description of the function and its expected output for a given input.
USER: I added the content of these additional files: aider/repomap.py
ASSISTANT: Thank you. I will now write a test for the `get_tags_map` function in the `aider/repomap.py` file.

```python
tests/test_repomap.py
<<<<<<< ORIGINAL
=======
import os
import unittest
from aider.repomap import RepoMap

class TestRepoMap(unittest.TestCase):
    def test_get_tags_map(self):
        # Create a temporary directory with sample files for testing
        test_files = [
            "test_file1.py",
            "test_file2.py",
            "test_file3.md",
            "test_file4.json",
        ]

        with tempfile.TemporaryDirectory() as temp_dir:
            for file in test_files:
                with open(os.path.join(temp_dir, file), "w") as f:
                    f.write("")

            repo_map = RepoMap(root=temp_dir)
            other_files = [os.path.join(temp_dir, file) for file in test_files]
            result = repo_map.get_tags_map(other_files)

            # Check if the result contains the expected tags map
            self.assertIn("test_file1.py:", result)
            self.assertIn("test_file2.py:", result)
            self.assertNotIn("test_file3.md:", result)
            self.assertNotIn("test_file4.json:", result)

if __name__ == "__main__":
    unittest.main()
>>>>>>> UPDATED
```

This test creates a temporary directory with sample files and checks if the `get_tags_map` function returns the expected tags map for the given input. The test checks if the result contains the tags map for `.py` files and does not contain the tags map for `.md` and `.json` files.
2023-05-24 18:58:29 -07:00
Paul Gauthier
507d7c0444 Added new files to the git repo: tests/test_repomap.py 2023-05-24 18:56:03 -07:00
Paul Gauthier
dcf1bbf20e renamed ctags->repomap 2023-05-24 18:55:47 -07:00