diff options
-rw-r--r-- | docs/change_log/release-3.4.md | 2 | ||||
-rw-r--r-- | markdown/core.py | 2 | ||||
-rw-r--r-- | markdown/util.py | 20 |
3 files changed, 14 insertions, 10 deletions
diff --git a/docs/change_log/release-3.4.md b/docs/change_log/release-3.4.md index 7a30de5..7abdf5d 100644 --- a/docs/change_log/release-3.4.md +++ b/docs/change_log/release-3.4.md @@ -66,3 +66,5 @@ The following new features have been included in the 3.4 release: ## Bug fixes The following bug fixes are included in the 3.4 release: + +* Extension entry-points are only loaded if needed (#1216). diff --git a/markdown/core.py b/markdown/core.py index d8c8196..3ed674a 100644 --- a/markdown/core.py +++ b/markdown/core.py @@ -150,7 +150,7 @@ class Markdown: """ configs = dict(configs) - entry_points = [ep for ep in util.INSTALLED_EXTENSIONS if ep.name == ext_name] + entry_points = [ep for ep in util.get_installed_extensions() if ep.name == ext_name] if entry_points: ext = entry_points[0].load() return ext(**configs) diff --git a/markdown/util.py b/markdown/util.py index 4c690c0..a6a32bf 100644 --- a/markdown/util.py +++ b/markdown/util.py @@ -24,17 +24,11 @@ import sys import warnings import xml.etree.ElementTree from collections import namedtuple -from functools import wraps +from functools import wraps, lru_cache from itertools import count from .pep562 import Pep562 -if sys.version_info >= (3, 10): - from importlib import metadata -else: - # <PY310 use backport - import importlib_metadata as metadata - PY37 = (3, 7) <= sys.version_info @@ -84,8 +78,6 @@ Constants you probably do not need to change ----------------------------------------------------------------------------- """ -# Only load extension entry_points once. -INSTALLED_EXTENSIONS = metadata.entry_points(group='markdown.extensions') RTL_BIDI_RANGES = ( ('\u0590', '\u07FF'), # Hebrew (0590-05FF), Arabic (0600-06FF), @@ -101,6 +93,16 @@ AUXILIARY GLOBAL FUNCTIONS """ +@lru_cache(maxsize=None) +def get_installed_extensions(): + if sys.version_info >= (3, 10): + from importlib import metadata + else: # <PY310 use backport + import importlib_metadata as metadata + # Only load extension entry_points once. + return metadata.entry_points(group='markdown.extensions') + + def deprecated(message, stacklevel=2): """ Raise a DeprecationWarning when wrapped function/method is called. |