[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

@@ -0,0 +1,29 @@
from importlib.abc import MetaPathFinder
import warnings
class SharedLibDeprecationWarning(DeprecationWarning):
pass
warnings.simplefilter("always", SharedLibDeprecationWarning)
class SharedLibImportWarner(MetaPathFinder):
"""
Deprecation warner for shared libraries. This class sits on `sys.meta_path`
and prints warning if imported module is a shared library
"""
def find_spec(self, fullname, path, target=None) -> None:
"""This is only supposed to print warnings, it won't ever return module spec."""
parts = fullname.split(".")
if parts[0] != "cog_shared" or len(parts) != 2:
return None
msg = (
"One of cogs uses shared libraries which are"
" deprecated and scheduled for removal in Red 3.3.\n"
"You should inform author of the cog about this message."
)
warnings.warn(msg, SharedLibDeprecationWarning, stacklevel=2)
return None