From 51943b68e24291f0868c6aed5f20b6c1b0133baa Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 20 Jul 2023 08:24:11 -0300 Subject: [PATCH] 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 ``` --- aider/versioncheck.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/aider/versioncheck.py b/aider/versioncheck.py index e69de29bb..96963581c 100644 --- a/aider/versioncheck.py +++ b/aider/versioncheck.py @@ -0,0 +1,17 @@ +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()