Commit graph

2344 commits

Author SHA1 Message Date
Paul Gauthier
7542449629 refactor to use io.read_text 2023-07-05 20:49:04 -07:00
Paul Gauthier
d30fb94c72 refactor to use io.read_text 2023-07-05 20:48:09 -07:00
Paul Gauthier
60619f263c refactor to use io.read_text 2023-07-05 20:47:44 -07:00
Paul Gauthier
c8fb1ddaa7 refactor to use io.read_text 2023-07-05 20:46:15 -07:00
Paul Gauthier
413ddb84df refactor to use io.read_text 2023-07-05 20:33:46 -07:00
Paul Gauthier
4c220ff63f refactor to use io.read_text 2023-07-05 20:31:22 -07:00
Paul Gauthier
9cab570f87 refactor to use io.read_text 2023-07-05 20:21:32 -07:00
Paul Gauthier
5f9947a727 aider: Add read_text function to InputOutput class and --encoding command-line switch.
# Context:
USER: Add a read_text function to the InputOutput class. It takes the file name as argument, and returns the text for that file. Internally, if we get a Unicode error or a FileNotFound error, it prints ToolErrorOutput to notify the user, and then returns None. Add a command-line switch, and dash-dash encoding, which defaults to UTF-8. That's the encoding which will be used by the read_text function.

ASSISTANT: To implement the requested changes, we need to modify the following files:

1. `aider/io.py`: To add the `read_text` function to the `InputOutput` class.
2. `aider/main.py`: To add the `--encoding` command-line switch.

Let's start with the changes to `aider/io.py`:

```python
aider/io.py
<<<<<<< ORIGINAL
class InputOutput:
    num_error_outputs = 0
    num_user_asks = 0

    def __init__(
        self,
        pretty=True,
        yes=False,
        input_history_file=None,
        chat_history_file=None,
        input=None,
        output=None,
        user_input_color="blue",
        tool_output_color=None,
        tool_error_color="red",
    ):
        no_color = os.environ.get("NO_COLOR")
        if no_color is not None and no_color != "":
            pretty = False

        self.user_input_color = user_input_color if pretty else None
        self.tool_output_color = tool_output_color if pretty else None
        self.tool_error_color = tool_error_color if pretty else None

        self.input = input
        self.output = output

        self.pretty = pretty
        if self.output:
            self.pretty = False

        self.yes = yes

        self.input_history_file = input_history_file
        if chat_history_file is not None:
            self.chat_history_file = Path(chat_history_file)
        else:
            self.chat_history_file = None

        if pretty:
            self.console = Console()
        else:
            self.console = Console(force_terminal=False, no_color=True)

        current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        self.append_chat_history(f"\n# aider chat started at {current_time}\n\n")
=======
class InputOutput:
    num_error_outputs = 0
    num_user_asks = 0

    def __init__(
        self,
        pretty=True,
        yes=False,
        input_history_file=None,
        chat_history_file=None,
        input=None,
        output=None,
        user_input_color="blue",
        tool_output_color=None,
        tool_error_color="red",
        encoding="utf-8",
    ):
        no_color = os.environ.get("NO_COLOR")
        if no_color is not None and no_color != "":
            pretty = False

        self.user_input_color = user_input_color if pretty else None
        self.tool_output_color = tool_output_color if pretty else None
        self.tool_error_color = tool_error_color if pretty else None

        self.input = input
        self.output = output

        self.pretty = pretty
        if self.output:
            self.pretty = False

        self.yes = yes

        self.input_history_file = input_history_file
        if chat_history_file is not None:
            self.chat_history_file = Path(chat_history_file)
        else:
            self.chat_history_file = None

        self.encoding = encoding

        if pretty:
            self.console = Console()
        else:
            self.console = Console(force_terminal=False, no_color=True)

        current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        self.append_chat_history(f"\n# aider chat started at {current_time}\n\n")

    def read_text(self, filename):
        try:
            with open(filename, "r", encoding=self.encoding) as f:
                return f.read()
        except (FileNotFoundError, UnicodeError) as e:
            self.tool_error(str(e))
            return None
>>>>>>> UPDATED
```

Now, let's add the `--encoding` command-line switch to `aider/main.py`:

```python
aider/main.py
<<<<<<< ORIGINAL
    parser.add_argument(
        "--no-dirty-commits",
        action="store_false",
        dest="dirty_commits",
        help="Disable commits when repo is found dirty",
    )
    parser.add_argument(
        "--openai-api-key",
        metavar="OPENAI_API_KEY",
        help="Specify the OpenAI API key",
        env_var="OPENAI_API_KEY",
    )
    parser.add_argument(
        "--openai-api-base",
        metavar="OPENAI_API_BASE",
        default="https://api.openai.com/v1",
        help="Specify the OpenAI API base endpoint (default: https://api.openai.com/v1)",
    )
=======
    parser.add_argument(
        "--no-dirty-commits",
        action="store_false",
        dest="dirty_commits",
        help="Disable commits when repo is found dirty",
    )
    parser.add_argument(
        "--encoding",
        default="utf-8",
        help="Specify the encoding to use when reading files (default: utf-8)",
    )
    parser.add_argument(
        "--openai-api-key",
        metavar="OPENAI_API_KEY",
        help="Specify the OpenAI API key",
        env_var="OPENAI_API_KEY",
    )
    parser.add_argument(
        "--openai-api-base",
        metavar="OPENAI_API_BASE",
        default="https://api.openai.com/v1",
        help="Specify the OpenAI API base endpoint (default: https://api.openai.com/v1)",
    )
>>>>>>> UPDATED
```

These changes should implement the requested functionality. Please review and let me know if any further changes are needed.
2023-07-05 19:33:59 -07:00
Paul Gauthier
d9f2c32aa9 Merge branch 'main' into encodings 2023-07-05 17:16:36 -07:00
Paul Gauthier
9915261097 link to benchmark 2023-07-05 17:15:36 -07:00
Paul Gauthier
5dba1624c7 fix broken test 2023-07-05 17:11:39 -07:00
Paul Gauthier
e996c56a51 more robust get_tracked_files with pathlib 2023-07-05 16:55:37 -07:00
Paul Gauthier
c6696e7245 Added a test case to fail if git posix paths are not turned into windows paths 2023-07-05 16:53:43 -07:00
Paul Gauthier
bc60e7fd1c use Path.touch() to create new files 2023-07-05 15:44:12 -07:00
Paul Gauthier
b3d624b7cd Run windows tests on push 2023-07-05 15:26:06 -07:00
Paul Gauthier
decc0a15ff initial 2023-07-05 15:25:36 -07:00
Paul Gauthier
de40f77a4f turn all windows tests back on 2023-07-05 15:20:37 -07:00
Paul Gauthier
f2a814d536 be more careful about ensuring self.root is an abspath 2023-07-05 15:16:57 -07:00
Paul Gauthier
a0774bf46a resolve cmd line files to abs path 2023-07-05 15:14:09 -07:00
Paul Gauthier
55b1634811 added debug output 2023-07-05 15:08:11 -07:00
Paul Gauthier
f3af05f3ee simpler, faster run just failing test 2023-07-05 14:57:35 -07:00
Paul Gauthier
e107819085 chdir inside test 2023-07-05 14:48:46 -07:00
Paul Gauthier
43103978b5 cleanup 2023-07-05 14:44:45 -07:00
Paul Gauthier
640a463a9c no pretty when output 2023-07-05 14:42:42 -07:00
Paul Gauthier
0ff4e5362b just 3.11 for windows for now 2023-07-05 14:39:21 -07:00
Paul Gauthier
e34078da04 force_terminal=False 2023-07-05 14:38:35 -07:00
Paul Gauthier
e1e8e8e10a Turn off fancy Console if self.output 2023-07-05 14:36:13 -07:00
Paul Gauthier
08230a0262 undo PYTHONIOENCODING 2023-07-05 14:34:07 -07:00
Paul Gauthier
bfd363ffde rename 2023-07-05 14:31:15 -07:00
Paul Gauthier
eada60d169 renamed github actions 2023-07-05 14:30:58 -07:00
Paul Gauthier
6746da5539 try and stop rich.Console().rule() from throwing unicode errors in github ci 2023-07-05 14:27:41 -07:00
Paul Gauthier
b31dc2ac71 Use DummyInput in tests 2023-07-05 14:20:28 -07:00
Paul Gauthier
9aaee49c51 tests pass on windows 2023-07-05 14:09:31 -07:00
Paul Gauthier
76eb9e020f more windows test improvements 2023-07-05 14:01:59 -07:00
Paul Gauthier
bbd68097bd tests run on windows now 2023-07-05 13:59:31 -07:00
Paul Gauthier
ae5b4057e8 Merge remote-tracking branch 'origin/main' 2023-07-05 13:39:49 -07:00
Paul Gauthier
9ed19e63d0 bugfix 2023-07-05 13:36:00 -07:00
Paul Gauthier
21efc8d59e convert git.ls_files() to appropriate os.sep, since git always normalizes to / 2023-07-05 13:29:13 -07:00
Paul Gauthier
83887070f4 copy 2023-07-05 13:26:07 -07:00
Paul Gauthier
77a230f005 improved windows instructions, error message 2023-07-05 10:27:07 -07:00
Paul Gauthier
4317a41cd2 copy 2023-07-05 10:00:26 -07:00
Paul Gauthier
b54fc10ee0 Explain -m aider.main in README 2023-07-05 09:59:22 -07:00
paul-gauthier
cdf8f9a4b2
Merge pull request #49 from kwmiebach/main
Add program argument for syntax highlighting theme.
2023-07-05 06:46:04 -07:00
kwmiebach
b80c83c6cb Add program argument for syntax highlighting theme.
The source code output in the chat will be colored in the given
color scheme. Syntax highlighting is powered by pygments, which
supports many styles out of the box. For example:

- default (the default)
- dracula
- emacs
- github-dark
- monokai
- vim
- solarized-dark
- solarized-light

See https://pygments.org/styles/
2023-07-05 00:29:40 +02:00
Paul Gauthier
bc6e958d7e aider: Remove push and pull_request triggers, add workflow_dispatch trigger to make the GitHub action only run when manually initiated.
# Context:
USER: can you stop this action from running on pushes/merges and make it so that it only runs when manually initiated?
ASSISTANT: Sure, to make the GitHub action only run when manually initiated, we need to modify the `.github/workflows/windows-tests.yml` file. We will remove the `push` and `pull_request` triggers and add a `workflow_dispatch` trigger.

Here is the change:

```yaml
.github/workflows/windows-tests.yml
<<<<<<< ORIGINAL
name: Windows Tests

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main
=======
name: Windows Tests

on:
  workflow_dispatch:
>>>>>>> UPDATED
```

This change will make the workflow only run when manually triggered from the GitHub Actions UI.
2023-07-04 14:49:16 -07:00
Paul Gauthier
37e8c49f7a aider: Added step to install universal ctags using Chocolatey before installing Python dependencies.
# Context:
USER: we do need to install universal ctags on windows too
ASSISTANT: To install universal ctags on Windows, we need to modify the `windows-tests.yml` file. However, universal ctags is not available in the standard repositories used by GitHub Actions' Windows environment. We can use Chocolatey, a package manager for Windows, to install universal ctags.

Here are the changes:

```yaml
.github/workflows/windows-tests.yml
<<<<<<< ORIGINAL
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt
=======
    - name: Install universal ctags
      run: |
        choco install universal-ctags

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt
>>>>>>> UPDATED
```

This adds a new step to the workflow to install universal ctags using Chocolatey before installing the Python dependencies.
2023-07-04 14:43:34 -07:00
Paul Gauthier
2cdeae8fdd aider: Create a Windows workflow for running tests based on the existing Python workflow.
# Context:
USER: make a windows workflow to run the tests, based on the existing python workflow
ASSISTANT: To create a Windows workflow for running tests, we can use the existing Python workflow as a base. We will need to modify the `runs-on` field to specify a Windows environment, and adjust the commands for installing dependencies and running tests to be compatible with Windows.

Here are the changes:

```yaml
.github/workflows/windows-tests.yml
<<<<<<< ORIGINAL

=======
name: Windows Tests

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  build:
    runs-on: windows-latest
    strategy:
      matrix:
        python-version: ["3.8", "3.9", "3.10", "3.11"]

    steps:
    - name: Check out repository
      uses: actions/checkout@v3

    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v4
      with:
        python-version: ${{ matrix.python-version }}

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt

    - name: Run tests
      run: |
        python -m unittest discover -s tests
>>>>>>> UPDATED
```

This creates a new file `.github/workflows/windows-tests.yml` with the necessary configuration for running tests on a Windows environment. The Python version matrix, checkout, setup, and test steps are the same as in the original Python workflow. The command to install dependencies has been simplified, as the `universal-ctags` package is not required or available on Windows.
2023-07-04 14:42:53 -07:00
Paul Gauthier
8596a5725f Added new files to the git repo: .github/workflows/windows-tests.yml 2023-07-04 14:42:11 -07:00
Paul Gauthier
9c45e01354 restore ubuntu 2023-07-04 14:41:40 -07:00
Paul Gauthier
6d70e3aa57 Just windows 2023-07-04 14:40:09 -07:00