|
13 | 13 | import pymdownx
|
14 | 14 | from pymdownx.emoji import TWEMOJI_SVG_CDN, add_attriubtes
|
15 | 15 | import xml.etree.ElementTree as etree # noqa: N813
|
| 16 | +import warnings |
| 17 | +from functools import wraps |
| 18 | +import logging |
| 19 | + |
| 20 | +log = logging.getLogger('mkdocs') |
| 21 | + |
| 22 | +DEPRECATED = """\ |
| 23 | +Material emoji logic has been officially moved into mkdocs-material |
| 24 | +version 9.4. Please use Material's '{}' |
| 25 | +as mkdocs_material_extensions is deprecated and will no longer be |
| 26 | +supported moving forward. This is the last release. |
| 27 | +""" |
| 28 | + |
16 | 29 |
|
17 | 30 | OPTION_SUPPORT = pymdownx.__version_info__ >= (7, 1, 0)
|
18 | 31 | RESOURCES = os.path.dirname(inspect.getfile(material))
|
|
22 | 35 | RES_PATH = os.path.join(RESOURCES, '.icons')
|
23 | 36 |
|
24 | 37 |
|
| 38 | +@functools.lru_cache(maxsize=None) |
| 39 | +def log_msg(message): |
| 40 | + """Log message.""" |
| 41 | + |
| 42 | + log.warning(message) |
| 43 | + |
| 44 | + |
| 45 | +def deprecated(message, stacklevel=2, name=None): # pragma: no cover |
| 46 | + """ |
| 47 | + Raise a `DeprecationWarning` when wrapped function/method is called. |
| 48 | +
|
| 49 | + Usage: |
| 50 | +
|
| 51 | + @deprecated("This method will be removed in version X; use Y instead.") |
| 52 | + def some_method()" |
| 53 | + pass |
| 54 | + """ |
| 55 | + |
| 56 | + def _wrapper(func): |
| 57 | + @wraps(func) |
| 58 | + def _deprecated_func(*args, **kwargs): |
| 59 | + warnings.warn( |
| 60 | + f"'{func.__name__ if name is None else name}' is deprecated.\n{message}", |
| 61 | + category=DeprecationWarning, |
| 62 | + stacklevel=stacklevel |
| 63 | + ) |
| 64 | + |
| 65 | + log_msg(message) |
| 66 | + return func(*args, **kwargs) |
| 67 | + return _deprecated_func |
| 68 | + return _wrapper |
| 69 | + |
| 70 | + |
| 71 | +@deprecated(DEPRECATED.format('material.extensions.emoji.twemoji'), name='materialx.emoji.twemoji') |
25 | 72 | def _patch_index(options):
|
26 | 73 | """Patch the given index."""
|
27 | 74 |
|
@@ -65,6 +112,7 @@ def twemoji():
|
65 | 112 | return _patch_index({})
|
66 | 113 |
|
67 | 114 |
|
| 115 | +@deprecated(DEPRECATED.format('material.extensions.emoji.to_svg'), 1, name='materialx.emoji.to_svg') |
68 | 116 | def to_svg(index, shortname, alias, uc, alt, title, category, options, md):
|
69 | 117 | """Return SVG element."""
|
70 | 118 |
|
|
0 commit comments