[V3 Downloader] Allow to specify minimum and maximum bot version in info.json (#2605)

* feat(downloader): add `min_bot_version` and `max_bot_version`

Adds actually working way of specifying minimum and maximum bot version and removes not working
`bot_version`

BREAKING CHANGE: - removal of `bot_version` attribute in `Installable`

* test(downloader): `Installable` tests fix for new bot version attributes

* docs(changelog): added changelog entries for this PR
This commit is contained in:
jack1142
2019-04-29 18:33:49 +02:00
committed by Michael H
parent 07f127ffe4
commit 24ac111782
7 changed files with 70 additions and 10 deletions

View File

@@ -8,7 +8,7 @@ from sys import path as syspath
from typing import Tuple, Union, Iterable
import discord
from redbot.core import checks, commands, Config
from redbot.core import checks, commands, Config, version_info as red_version_info
from redbot.core.bot import Red
from redbot.core.data_manager import cog_data_path
from redbot.core.i18n import Translator, cog_i18n
@@ -303,6 +303,26 @@ class Downloader(commands.Cog):
)
)
return
ignore_max = cog.min_bot_version > cog.max_bot_version
if (
cog.min_bot_version > red_version_info
or not ignore_max
and cog.max_bot_version < red_version_info
):
await ctx.send(
_("This cog requires at least Red version {min_version}").format(
min_version=cog.min_bot_version
)
+ (
""
if ignore_max
else _(" and at most {max_version}").format(max_version=cog.max_bot_version)
)
+ _(", but you have {current_version}, aborting install.").format(
current_version=red_version_info
)
)
return
if not await repo.install_requirements(cog, self.LIB_PATH):
libraries = humanize_list(tuple(map(inline, cog.requirements)))

View File

@@ -8,6 +8,8 @@ from typing import MutableMapping, Any, TYPE_CHECKING
from .log import log
from .json_mixins import RepoJSONMixin
from redbot.core import __version__, version_info as red_version_info, VersionInfo
if TYPE_CHECKING:
from .repo_manager import RepoManager
@@ -72,7 +74,8 @@ class Installable(RepoJSONMixin):
self.repo_name = self._location.parent.stem
self.author = ()
self.bot_version = (3, 0, 0)
self.min_bot_version = red_version_info
self.max_bot_version = red_version_info
self.min_python_version = (3, 5, 1)
self.hidden = False
self.disabled = False
@@ -157,10 +160,16 @@ class Installable(RepoJSONMixin):
self.author = author
try:
bot_version = tuple(info.get("bot_version", [3, 0, 0]))
min_bot_version = VersionInfo.from_str(str(info.get("min_bot_version", __version__)))
except ValueError:
bot_version = self.bot_version
self.bot_version = bot_version
min_bot_version = self.min_bot_version
self.min_bot_version = min_bot_version
try:
max_bot_version = VersionInfo.from_str(str(info.get("max_bot_version", __version__)))
except ValueError:
max_bot_version = self.max_bot_version
self.max_bot_version = max_bot_version
try:
min_python_version = tuple(info.get("min_python_version", [3, 5, 1]))