Use Simple Repository API for fetching latest version (#6704)

This commit is contained in:
Jakub Kuczys
2026-05-14 00:03:20 +02:00
committed by GitHub
parent a234fc1e02
commit 13f45f69ac
3 changed files with 212 additions and 29 deletions
+12 -11
View File
@@ -11,6 +11,8 @@ import aiohttp
import discord
import importlib.metadata
from packaging.requirements import Requirement
from packaging.specifiers import SpecifierSet
from packaging.version import Version
from redbot.core import data_manager
from redbot.core.bot import ExitCodes
@@ -19,14 +21,13 @@ from redbot.core.i18n import (
Translator,
set_contextual_locales_from_guild,
)
from .. import __version__ as red_version, version_info as red_version_info
from .. import __version__ as red_version
from . import commands
from ._config import get_latest_confs
from .utils._internal_utils import (
fuzzy_command_search,
format_fuzzy_results,
expected_version,
fetch_latest_red_version_info,
fetch_latest_red_version,
send_to_owners_with_prefix_replaced,
)
from .utils.chat_formatting import inline, format_perms_list
@@ -52,7 +53,7 @@ ______ _ ______ _ _ ______ _
_ = Translator(__name__, __file__)
def get_outdated_red_messages(pypi_version: str, py_version_req: str) -> Tuple[str, str]:
def get_outdated_red_messages(pypi_version: str, requires_python: SpecifierSet) -> Tuple[str, str]:
outdated_red_message = _(
"Your Red instance is out of date! {} is the current version, however you are using {}!"
).format(pypi_version, red_version)
@@ -61,7 +62,7 @@ def get_outdated_red_messages(pypi_version: str, py_version_req: str) -> Tuple[s
f"[red]!!![/red]Version [cyan]{pypi_version}[/] is available, "
f"but you're using [cyan]{red_version}[/][red]!!![/red]"
)
current_python = platform.python_version()
current_python = Version(platform.python_version())
extra_update = _(
"\n\nWhile the following command should work in most scenarios as it is "
"based on your current OS, environment, and Python version, "
@@ -70,14 +71,14 @@ def get_outdated_red_messages(pypi_version: str, py_version_req: str) -> Tuple[s
"needs to be done during the update.**"
).format(docs="https://docs.discord.red/en/stable/update_red.html")
if not expected_version(current_python, py_version_req):
if current_python not in requires_python:
extra_update += _(
"\n\nYou have Python `{py_version}` and this update "
"requires `{req_py}`; you cannot simply run the update command.\n\n"
"You will need to follow the update instructions in our docs above, "
"if you still need help updating after following the docs go to our "
"#support channel in <https://discord.gg/red>"
).format(py_version=current_python, req_py=py_version_req)
).format(py_version=current_python, req_py=requires_python)
outdated_red_message += extra_update
return outdated_red_message, rich_outdated_message
@@ -176,7 +177,7 @@ def init_events(bot, cli_flags):
if bot.intents.members: # Lets avoid 0 Unique Users
table_counts.add_row("Unique Users", str(users))
fetch_version_task = asyncio.create_task(fetch_latest_red_version_info())
fetch_version_task = asyncio.create_task(fetch_latest_red_version())
log.info("Fetching information about latest Red version...")
try:
await asyncio.wait_for(asyncio.shield(fetch_version_task), timeout=5)
@@ -214,16 +215,16 @@ def init_events(bot, cli_flags):
bot._red_ready.set()
try:
pypi_version, py_version_req = await fetch_version_task
latest = await fetch_version_task
except (aiohttp.ClientError, asyncio.TimeoutError) as exc:
log.error("Failed to fetch latest version information from PyPI.", exc_info=exc)
except (KeyError, ValueError) as exc:
log.error("Failed to parse version metadata received from PyPI.", exc_info=exc)
else:
outdated = pypi_version and pypi_version > red_version_info
outdated = latest.version > Version(red_version)
if outdated:
outdated_red_message, rich_outdated_message = get_outdated_red_messages(
pypi_version, py_version_req
latest.version, latest.requires_python
)
rich_console.print(rich_outdated_message)
await send_to_owners_with_prefix_replaced(bot, outdated_red_message)