Commit graph

28 commits

Author SHA1 Message Date
Paul Gauthier
9fb3a6f8e1 fix: Update string formatting in confirm_ask calls 2024-08-21 05:38:33 -07:00
Paul Gauthier
ba746dd211 fix: Improve confirm dialog messages 2024-08-21 05:38:13 -07:00
Paul Gauthier
ad16cc3c41 fix: Add verbose output for version check 2024-08-13 05:35:07 -07:00
Paul Gauthier (aider)
76a4b878b1 feat: Add verbose argument to check_version function 2024-08-13 05:31:04 -07:00
Paul Gauthier
3553e0af40 remove is_update_available = True debug 2024-08-06 15:33:50 -03:00
Paul Gauthier
14b26420b1 fix: Set is_update_available flag in versioncheck.py
build: Update AIDER_DOCKER_IMAGE environment variable in Dockerfile
2024-08-06 11:22:05 -03:00
Paul Gauthier (aider)
df5d5bdf78 style: Fix import order in versioncheck.py 2024-08-06 11:17:36 -03:00
Paul Gauthier (aider)
35593a1144 feat: Add Docker image update instructions when AIDER_DOCKER_IMAGE is set 2024-08-06 11:17:33 -03:00
Paul Gauthier
90f1ac2232 fix: Handle pip install failure in version check 2024-08-06 11:17:32 -03:00
Paul Gauthier
cd86354f12 check_version shows output for --just-check-update 2024-07-17 15:23:47 +01:00
Paul Gauthier
76dad84285 added [browser] extra; refac the pip install utils 2024-07-14 17:22:17 +01:00
Paul Gauthier
88749a8acb moved versioncheck touch into finally 2024-07-13 07:51:12 +01:00
Paul Gauthier
6c38306eab Automatically install the new aider version 2024-07-13 07:47:07 +01:00
Paul Gauthier
81195dad02 use ~/.aider/caches 2024-07-05 10:06:23 -03:00
Paul Gauthier
b3f7f0a250 Only check versions once per day 2024-07-03 13:44:26 -03:00
Paul Gauthier
4a0c0a3913 Recommend pipx upgrade command 2024-05-10 12:07:22 -07:00
Paul Gauthier
bd1c8b625d aider: Add --check-update to make aider check for update and return status in the exit code.
# Aider chat conversation:

USER: add --check-update to make aider check for update and return status in the exit code.

ASSISTANT: To implement the `--check-update` option, I will make the following changes:

1. Add the `--check-update` argument to the argument parser in `aider/main.py`.
2. Modify the `check_version` function in `aider/versioncheck.py` to return a boolean indicating whether an update is available.
3. Use the returned value from `check_version` in `aider/main.py` to set the exit status code when `--check-update` is used.

Here are the diffs for those changes:

```diff
--- aider/versioncheck.py
+++ aider/versioncheck.py
@@ ... @@
 def check_version(print_cmd):
     try:
         response = requests.get("https://pypi.org/pypi/aider-chat/json")
         data = response.json()
         latest_version = data["info"]["version"]
         current_version = aider.__version__

-        if packaging.version.parse(latest_version) <= packaging.version.parse(current_version):
-            return
+        is_update_available = packaging.version.parse(latest_version) > packaging.version.parse(current_version)

-        print_cmd(f"Newer version v{latest_version} is available. To upgrade, run:")
-        py = sys.executable
-        print_cmd(f"{py} -m pip install --upgrade aider-chat")
+        if is_update_available:
+            print_cmd(f"Newer version v{latest_version} is available. To upgrade, run:")
+            py = sys.executable
+            print_cmd(f"{py} -m pip install --upgrade aider-chat")
+
+        return is_update_available
     except Exception as err:
         print_cmd(f"Error checking pypi for new version: {err}")
+        return False

--- aider/main.py
+++ aider/main.py
@@ ... @@
     other_group.add_argument(
         "--version",
         action="version",
         version=f"%(prog)s {__version__}",
         help="Show the version number and exit",
     )
+    other_group.add_argument(
+        "--check-update",
+        action="store_true",
+        help="Check for updates and return status in the exit code",
+        default=False,
+    )
     other_group.add_argument(
         "--apply",
         metavar="FILE",
@@ ... @@
     check_version(io.tool_error)

+    if args.check_update:
+        update_available = check_version(lambda msg: None)
+        sys.exit(0 if not update_available else 1)
+
     if "VSCODE_GIT_IPC_HANDLE" in os.environ:
         args.pretty = False
         io.tool_output("VSCode terminal detected, pretty output has been disabled.")
```

These changes will add the `--check-update` option to the command-line interface and use the `check_version` function to determine if an update is available, exiting with status code `0` if no update is available and `1` if an update is available.

USER: UnifiedDiffNoMatch: hunk failed to apply!

aider/versioncheck.py does not contain lines that match the diff you provided!
Try again.
DO NOT skip blank lines, comments, docstrings, etc!
The diff needs to apply cleanly to the lines in aider/versioncheck.py!

aider/versioncheck.py does not contain these 17 exact lines in a row:
```
def check_version(print_cmd):
    try:
        response = requests.get("https://pypi.org/pypi/aider-chat/json")
        data = response.json()
        latest_version = data["info"]["version"]
        current_version = aider.__version__

        if packaging.version.parse(latest_version) <= packaging.version.parse(current_version):
            return

        print_cmd(f"Newer version v{latest_version} is available. To upgrade, run:")
        py = sys.executable
        print_cmd(f"{py} -m pip install --upgrade aider-chat")
    except Exception as err:
        print_cmd(f"Error checking pypi for new version: {err}")

-- aider/main.py
```

UnifiedDiffNoMatch: hunk failed to apply!

aider/versioncheck.py does not contain lines that match the diff you provided!
Try again.
DO NOT skip blank lines, comments, docstrings, etc!
The diff needs to apply cleanly to the lines in aider/versioncheck.py!

aider/versioncheck.py does not contain these 9 exact lines in a row:
```
    other_group.add_argument(
        "--version",
        action="version",
        version=f"%(prog)s {__version__}",
        help="Show the version number and exit",
    )
    other_group.add_argument(
        "--apply",
        metavar="FILE",
```

UnifiedDiffNoMatch: hunk failed to apply!

aider/versioncheck.py does not contain lines that match the diff you provided!
Try again.
DO NOT skip blank lines, comments, docstrings, etc!
The diff needs to apply cleanly to the lines in aider/versioncheck.py!

aider/versioncheck.py does not contain these 5 exact lines in a row:
```
    check_version(io.tool_error)

    if "VSCODE_GIT_IPC_HANDLE" in os.environ:
        args.pretty = False
        io.tool_output("VSCode terminal detected, pretty output has been disabled.")
```

ASSISTANT: I apologize for the confusion. Let's try again with the correct diffs.

Here are the diffs for the changes to `aider/versioncheck.py` and `aider/main.py`:

```diff
--- aider/versioncheck.py
+++ aider/versioncheck.py
@@ ... @@
 import sys

 import packaging.version
 import requests

 import aider

 def check_version(print_cmd):
     try:
         response = requests.get("https://pypi.org/pypi/aider-chat/json")
         data = response.json()
         latest_version = data["info"]["version"]
         current_version = aider.__version__

-        if packaging.version.parse(latest_version) <= packaging.version.parse(current_version):
-            return
+        is_update_available = packaging.version.parse(latest_version) > packaging.version.parse(current_version)

-        print_cmd(f"Newer version v{latest_version} is available. To upgrade, run:")
-        py = sys.executable
-        print_cmd(f"{py} -m pip install --upgrade aider-chat")
+        if is_update_available:
+            print_cmd(f"Newer version v{latest_version} is available. To upgrade, run:")
+            py = sys.executable
+            print_cmd(f"{py} -m pip install --upgrade aider-chat")
+
+        return is_update_available
     except Exception as err:
         print_cmd(f"Error checking pypi for new version: {err}")
+        return False
```

```diff
--- aider/main.py
+++ aider/main.py
@@ ... @@
     other_group.add_argument(
         "--version",
         action="version",
         version=f"%(prog)s {__version__}",
         help="Show the version number and exit",
     )
+    other_group.add_argument(
+        "--check-update",
+        action="store_true",
+        help="Check for updates and return status in the exit code",
+        default=False,
+    )
     other_group.add_argument(
         "--apply",
         metavar="FILE",
@@ ... @@
     check_version(io.tool_error)

+    if args.check_update:
+        update_available = check_version(lambda msg: None)
+        sys.exit(0 if not update_available else 1)
+
     if "VSCODE_GIT_IPC_HANDLE" in os.environ:
         args.pretty = False
         io.tool_output("VSCode terminal detected, pretty output has been disabled.")
```

These diffs should apply cleanly to the current contents of the files. The `check_version` function in `aider/versioncheck.py` now returns a boolean indicating whether an update is available, and `aider/main.py` has been updated to include the `--check-update` argument and to use the return value from `check_version` to set the exit status code.
2024-01-04 12:27:31 -08:00
Paul Gauthier
46083802c7 cleanup 2023-07-20 09:49:40 -03:00
Paul Gauthier
2d0f789cb9 aider: Increment the version by 0.0.1 and add "-dev" after the version bump.
# Aider chat conversation:

USER: why is it thinking that 0.9.0 is newer than 0.9.0-dev

ASSISTANT: The version comparison is being done using the `packaging.version.parse` function. This function follows the PEP 440 version identification and comparison rules. According to PEP 440, a version like "0.9.0-dev" is considered a pre-release of "0.9.0", and therefore "0.9.0" is considered newer.

If you want "0.9.0-dev" to be considered newer than "0.9.0", you would need to change the version comparison logic. However, this would be against the standard Python versioning rules and is not recommended.

If you still want to proceed with this, please confirm and I will provide the necessary changes.

USER: I added these *read-write* files: scripts/versionbump.py

ASSISTANT: I understand that you want to modify the version comparison logic in your scripts. However, I would like to clarify where exactly you want this change to be made.

The file `scripts/versionbump.py` does not seem to have any version comparison logic that would consider "0.9.0
^C KeyboardInterrupt

USER: instead of adding -dev into the version after the bump, can you instead increment the version by 0.0.1 and then add dev

ASSISTANT: Sure, we can modify the `scripts/versionbump.py` script to increment the version by 0.0.1 and then add "-dev" to it. Here's how we can do it:

1. After the new version is parsed, we can increment the patch version by 1.
2. Then, we can add "-dev" to this incremented version.

Here's the change:

```python
scripts/versionbump.py
<<<<<<< ORIGINAL
    new_version = version.parse(new_version_str)

    with open("aider/__init__.py", "r") as f:
        content = f.read()
=======
    new_version = version.parse(new_version_str)
    incremented_version = version.Version(f"{new_version.major}.{new_version.minor}.{new_version.micro + 1}")

    with open("aider/__init__.py", "r") as f:
        content = f.read()
>>>>>>> UPDATED
```

```python
scripts/versionbump.py
<<<<<<< ORIGINAL
    updated_dev_content = re.sub(
        r'__version__ = ".+?"', f'__version__ = "{new_version}-dev"', content
    )
=======
    updated_dev_content = re.sub(
        r'__version__ = ".+?"', f'__version__ = "{incremented_version}-dev"', content
    )
>>>>>>> UPDATED
```

This will increment the patch version by 0.0.1 and then add "-dev" to it after the version bump.
2023-07-20 09:48:11 -03:00
Paul Gauthier
25c03535cc aider: Replace deprecated pkg_resources.parse_version with packaging.version.parse for version comparison in aider/versioncheck.py.
# Aider chat conversation:

USER:     warnings.warn("pkg_resources is deprecated as an API", DeprecationWarning)

ASSISTANT: It seems like you're concerned about the deprecation warning from the `pkg_resources` module. We can replace the usage of `pkg_resources` with `packaging.version` for version comparison.

Here are the changes needed in the `aider/versioncheck.py` file:

```python
aider/versioncheck.py
<<<<<<< ORIGINAL
import pkg_resources

...

if pkg_resources.parse_version(latest_version) <= pkg_resources.parse_version(
    current_version
):
    return
=======
import packaging.version

...

if packaging.version.parse(latest_version) <= packaging.version.parse(
    current_version
):
    return
>>>>>>> UPDATED
```

This change replaces the deprecated `pkg_resources.parse_version` with `packaging.version.parse` for version comparison.

USER: InvalidEditBlock: edit failed!

aider/versioncheck.py does not contain the *exact sequence* of ORIGINAL lines you specified.
Try again.
DO NOT skip blank lines, comments, docstrings, etc!
The ORIGINAL block needs to be EXACTLY the same as the lines in aider/versioncheck.py with nothing missing!

aider/versioncheck.py does not contain these 8 exact lines in a row:
```
import pkg_resources

...

if pkg_resources.parse_version(latest_version) <= pkg_resources.parse_version(
    current_version
):
    return
```

ASSISTANT: I apologize for the confusion. Let's try again with the correct sequence of lines from the `aider/versioncheck.py` file:

```python
aider/versioncheck.py
<<<<<<< ORIGINAL
import pkg_resources

...

        if pkg_resources.parse_version(latest_version) <= pkg_resources.parse_version(
            current_version
        ):
            return
=======
import packaging.version

...

        if packaging.version.parse(latest_version) <= packaging.version.parse(
            current_version
        ):
            return
>>>>>>> UPDATED
```

This change replaces the deprecated `pkg_resources.parse_version` with `packaging.version.parse` for version comparison.
2023-07-20 08:45:58 -03:00
Paul Gauthier
cc59b10a73 wire into main 2023-07-20 08:43:03 -03:00
Paul Gauthier
12cf19010f Refactor check_version function to accept a print_cmd argument and update print statements accordingly.
# Aider chat conversation:
2023-07-20 08:37:44 -03:00
Paul Gauthier
fe9bcef676 Add support for printing the Python executable name in the upgrade message.
# Aider chat conversation:
2023-07-20 08:36:26 -03:00
Paul Gauthier
4b133929c8 aider: Add print statement with upgrade command in check_version function.
# Aider chat conversation:

USER: also print the command the user should use to upgrade

ASSISTANT: To print the command the user should use to upgrade, we can add a print statement in the `check_version` function in the `aider/versioncheck.py` file. This print statement will provide the command to upgrade the `aider-chat` package using pip.

Here is the code:

```python
aider/versioncheck.py
<<<<<<< ORIGINAL
import requests
import pkg_resources
import aider

from aider.dump import dump

def check_version():
    response = requests.get('https://pypi.org/pypi/aider-chat/json')
    data = response.json()
    latest_version = data['info']['version']
    current_version = pkg_resources.get_distribution('aider-chat').version

    if pkg_resources.parse_version(latest_version) <= pkg_resources.parse_version(current_version):
        return

    print(f"Running aider version {current_version}, newer version available: {latest_version}")

if __name__ == "__main__":
    check_version()
=======
import requests
import pkg_resources
import aider

from aider.dump import dump

def check_version():
    response = requests.get('https://pypi.org/pypi/aider-chat/json')
    data = response.json()
    latest_version = data['info']['version']
    current_version = pkg_resources.get_distribution('aider-chat').version

    if pkg_resources.parse_version(latest_version) <= pkg_resources.parse_version(current_version):
        return

    print(f"Running aider version {current_version}, newer version available: {latest_version}")
    print("To upgrade, run: pip install --upgrade aider-chat")

if __name__ == "__main__":
    check_version()
>>>>>>> UPDATED
```

This will print the command `pip install --upgrade aider-chat` when a newer version is available. The user can then copy this command and run it in their terminal to upgrade the `aider-chat` package.
2023-07-20 08:34:54 -03:00
Paul Gauthier
e94f85b61e Refactor version check to include the package name in the URL and print the current version.
# Aider chat conversation:
2023-07-20 08:33:18 -03:00
Paul Gauthier
cf8f76533d aider: Refactored versioncheck.py to use the PyPI JSON API instead of web scraping.
# Aider chat conversation:

USER: can we use a json api not scrape?

ASSISTANT: Yes, we can use the PyPI JSON API to get the information about the latest version of the package.

We will modify the `aider/versioncheck.py` file.

Here are the steps:

1. Send a GET request to the PyPI JSON API for the `aider` package.
2. Parse the JSON response to find the latest version number.
3. Compare this version number with the current version of `aider` installed in the system.
4. Print a message indicating whether a newer version is available.

Here is the code:

```python
aider/versioncheck.py
<<<<<<< ORIGINAL
import requests
from bs4 import BeautifulSoup
import pkg_resources

def check_version():
    response = requests.get('https://pypi.org/project/aider/')
    soup = BeautifulSoup(response.text, 'html.parser')
    latest_version = soup.find('h1', {'class': 'package-header__name'}).text.split()[-1]
    current_version = pkg_resources.get_distribution('aider').version

    if pkg_resources.parse_version(latest_version) > pkg_resources.parse_version(current_version):
        print(f"A newer version of 'aider' is available: {latest_version}")
    else:
        print("You are using the latest version of 'aider'.")

if __name__ == "__main__":
    check_version()
=======
import requests
import pkg_resources

def check_version():
    response = requests.get('https://pypi.org/pypi/aider/json')
    data = response.json()
    latest_version = data['info']['version']
    current_version = pkg_resources.get_distribution('aider').version

    if pkg_resources.parse_version(latest_version) > pkg_resources.parse_version(current_version):
        print(f"A newer version of 'aider' is available: {latest_version}")
    else:
        print("You are using the latest version of 'aider'.")

if __name__ == "__main__":
    check_version()
>>>>>>> UPDATED
```

This version of the script uses the PyPI JSON API, which is more reliable and faster than web scraping.
2023-07-20 08:24:46 -03:00
Paul Gauthier
51943b68e2 aider: Added a script to check the latest version of the 'aider' package on PyPI and compare it with the current installed version.
# Aider chat conversation:

USER: write a script that checks pypi to see if a newer version of aider is available

ASSISTANT: To accomplish this, we will use the `requests` and `bs4` (BeautifulSoup) libraries in Python to scrape the PyPI website for the latest version of the `aider` package.

We will add this script to the `aider/versioncheck.py` file.

Here are the steps:

1. Import the necessary libraries.
2. Define a function that sends a GET request to the PyPI page for the `aider` package.
3. Parse the HTML response to find the latest version number.
4. Compare this version number with the current version of `aider` installed in the system.
5. Print a message indicating whether a newer version is available.

Here is the code:

```python
aider/versioncheck.py
<<<<<<< ORIGINAL

=======
import requests
from bs4 import BeautifulSoup
import pkg_resources

def check_version():
    response = requests.get('https://pypi.org/project/aider/')
    soup = BeautifulSoup(response.text, 'html.parser')
    latest_version = soup.find('h1', {'class': 'package-header__name'}).text.split()[-1]
    current_version = pkg_resources.get_distribution('aider').version

    if pkg_resources.parse_version(latest_version) > pkg_resources.parse_version(current_version):
        print(f"A newer version of 'aider' is available: {latest_version}")
    else:
        print("You are using the latest version of 'aider'.")

if __name__ == "__main__":
    check_version()
>>>>>>> UPDATED
```

Please note that this script assumes that `requests`, `bs4`, and `pkg_resources` are installed in your Python environment. If not, you can install them using pip:

```bash
pip install requests beautifulsoup4 setuptools
```
2023-07-20 08:24:11 -03:00
Paul Gauthier
7d9d163561 Added new files to the git repo: aider/versioncheck.py 2023-07-20 08:22:05 -03:00