|
3 | 3 | from typing import Optional
|
4 | 4 |
|
5 | 5 | import requests
|
6 |
| -from packaging.version import Version |
| 6 | +from packaging.version import Version, InvalidVersion |
7 | 7 |
|
| 8 | +from bittensor import __name__ |
8 | 9 | from bittensor.core.settings import __version__, PIPADDRESS
|
9 | 10 | from bittensor.utils.btlogging import logging
|
10 | 11 |
|
@@ -115,3 +116,27 @@ def version_checking(timeout: int = 15):
|
115 | 116 | check_version(timeout)
|
116 | 117 | except VersionCheckError:
|
117 | 118 | logging.exception("Version check failed")
|
| 119 | + |
| 120 | + |
| 121 | +def check_latest_version_in_pypi(): |
| 122 | + """Check for the latest version of the package on PyPI.""" |
| 123 | + package_name = __name__ |
| 124 | + url = f"https://pypi.org/pypi/{package_name}/json" |
| 125 | + |
| 126 | + try: |
| 127 | + response = requests.get(url, timeout=5) |
| 128 | + response.raise_for_status() |
| 129 | + latest_version = response.json()["info"]["version"] |
| 130 | + installed_version = __version__ |
| 131 | + try: |
| 132 | + if Version(installed_version) < Version(latest_version): |
| 133 | + print( |
| 134 | + f"\n🔔 New version is available `{package_name} v.{latest_version}`" |
| 135 | + ) |
| 136 | + print("📦 Use command `pip install --upgrade bittensor` to update.") |
| 137 | + except InvalidVersion: |
| 138 | + # stay silent if InvalidVersion |
| 139 | + pass |
| 140 | + except (requests.RequestException, KeyError) as e: |
| 141 | + # stay silent if not internet connection or pypi.org issue |
| 142 | + pass |
0 commit comments