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.
This commit is contained in:
Paul Gauthier 2023-07-20 08:45:58 -03:00
parent 8627b39c97
commit 25c03535cc

View file

@ -1,6 +1,6 @@
import sys
import pkg_resources
import packaging.version
import requests
import aider
@ -13,7 +13,7 @@ def check_version(print_cmd):
latest_version = data["info"]["version"]
current_version = aider.__version__
if pkg_resources.parse_version(latest_version) <= pkg_resources.parse_version(
if packaging.version.parse(latest_version) <= packaging.version.parse(
current_version
):
return