Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defer loading of importtlib.metadata #466

Merged
merged 1 commit into from
Dec 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Check warning on line 31 in src/pluggy/_manager.py

View check run for this annotation

Codecov / codecov/patch

src/pluggy/_manager.py#L30-L31

Added lines #L30 - L31 were not covered by tests


_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 @@
: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
Loading