Skip to content

Commit

Permalink
Merge pull request #466 from bluetech/defer-importlib-metadata
Browse files Browse the repository at this point in the history
Defer loading of importtlib.metadata
  • Loading branch information
bluetech committed Dec 26, 2023
2 parents e474438 + 59e0ca3 commit 3bdfcac
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/pluggy/_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import importlib.metadata
import inspect
import types
import warnings
Expand All @@ -11,6 +10,7 @@
from typing import Iterable
from typing import Mapping
from typing import Sequence
from typing import TYPE_CHECKING

from . import _tracing
from ._callers import _multicall
Expand All @@ -26,6 +26,10 @@
from ._hooks import normalize_hookimpl_opts
from ._result import Result

if TYPE_CHECKING:
# importtlib.metadata import is slow, defer it.
import importlib.metadata


_BeforeTrace = Callable[[str, Sequence[HookImpl], Mapping[str, Any]], None]
_AfterTrace = Callable[[Result[Any], str, Sequence[HookImpl], Mapping[str, Any]], None]
Expand Down Expand Up @@ -384,6 +388,8 @@ def load_setuptools_entrypoints(self, group: str, name: str | None = None) -> in
:return:
The number of plugins loaded by this call.
"""
import importlib.metadata

count = 0
for dist in list(importlib.metadata.distributions()):
for ep in dist.entry_points:
Expand Down

0 comments on commit 3bdfcac

Please sign in to comment.