[Core] Add deprecation warnings about removal of shared libraries. (#3106)

* feat: add deprecation warning when importing shared libs

* enhance(downloader): add shared libs deprecation warns

* enhance: add deprecation warning when (re)loading cogs

* docs(downloader): add deprecation note about shared libs

* chore(changelog): add towncrier entries

* style: split long tuple unpacks in multiple lines

* fix: argument to `humanize_list` has to be a sequence
This commit is contained in:
jack1142
2019-12-20 08:06:53 +01:00
committed by Michael H
parent 9d027747d1
commit b457f8d1c1
10 changed files with 149 additions and 12 deletions

View File

@@ -27,6 +27,13 @@ from .repo_manager import RepoManager, Repo
_ = Translator("Downloader", __file__)
DEPRECATION_NOTICE = _(
"\n**WARNING:** The following repos are using shared libraries"
" which are marked for removal in Red 3.3: {repo_list}.\n"
" You should inform maintainers of these repos about this message."
)
@cog_i18n(_)
class Downloader(commands.Cog):
def __init__(self, bot: Red):
@@ -192,6 +199,16 @@ class Downloader(commands.Cog):
await self.conf.installed_cogs.set(installed_cogs)
await self.conf.installed_libraries.set(installed_libraries)
async def _shared_lib_load_check(self, cog_name: str) -> Optional[Repo]:
# remove in Red 3.3
is_installed, cog = await self.is_installed(cog_name)
# it's not gonna be None when `is_installed` is True
# if we'll use typing_extensions in future, `Literal` can solve this
cog = cast(InstalledModule, cog)
if is_installed and cog.repo is not None and cog.repo.available_libraries:
return cog.repo
return None
async def _available_updates(
self, cogs: Iterable[InstalledModule]
) -> Tuple[Tuple[Installable, ...], Tuple[Installable, ...]]:
@@ -584,6 +601,9 @@ class Downloader(commands.Cog):
installed_cogs, failed_cogs = await self._install_cogs(cogs)
deprecation_notice = ""
if repo.available_libraries:
deprecation_notice = DEPRECATION_NOTICE.format(repo_list=inline(repo.name))
installed_libs, failed_libs = await repo.install_libraries(
target_dir=self.SHAREDLIB_PATH, req_target_dir=self.LIB_PATH
)
@@ -622,7 +642,7 @@ class Downloader(commands.Cog):
+ message
)
# "---" added to separate cog install messages from Downloader's message
await ctx.send(f"{message}\n---")
await ctx.send(f"{message}{deprecation_notice}\n---")
for cog in installed_cogs:
if cog.install_msg:
await ctx.send(cog.install_msg.replace("[p]", ctx.prefix))
@@ -874,6 +894,14 @@ class Downloader(commands.Cog):
if failed_repos:
message += "\n" + self.format_failed_repos(failed_repos)
repos_with_libs = {
inline(module.repo.name)
for module in cogs_to_update + libs_to_update
if module.repo.available_libraries
}
if repos_with_libs:
message += DEPRECATION_NOTICE.format(repo_list=humanize_list(list(repos_with_libs)))
await ctx.send(message)
if updates_available and updated_cognames: