Skip to content

Commit

Permalink
Only enumerate extension entry points when required
Browse files Browse the repository at this point in the history
  • Loading branch information
akx authored May 24, 2022
1 parent 12c3378 commit e958ec4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 2 additions & 0 deletions docs/change_log/release-3.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
2 changes: 1 addition & 1 deletion markdown/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def build_extension(self, ext_name, configs):
"""
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)
Expand Down
20 changes: 11 additions & 9 deletions markdown/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,11 @@
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


Expand Down Expand Up @@ -84,8 +78,6 @@
-----------------------------------------------------------------------------
"""

# 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),
Expand All @@ -101,6 +93,16 @@
"""


@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.
Expand Down

0 comments on commit e958ec4

Please sign in to comment.