updates
This commit is contained in:
@@ -1,16 +1,10 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
import importlib.metadata as importlib_metadata
|
||||
import os
|
||||
import warnings
|
||||
from typing import TYPE_CHECKING, Iterable
|
||||
|
||||
from typing_extensions import Final
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
import importlib.metadata as importlib_metadata
|
||||
else:
|
||||
import importlib_metadata
|
||||
|
||||
from collections.abc import Iterable
|
||||
from typing import TYPE_CHECKING, Final
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from . import PydanticPluginProtocol
|
||||
@@ -30,10 +24,13 @@ def get_plugins() -> Iterable[PydanticPluginProtocol]:
|
||||
|
||||
Inspired by: https://github.com/pytest-dev/pluggy/blob/1.3.0/src/pluggy/_manager.py#L376-L402
|
||||
"""
|
||||
disabled_plugins = os.getenv('PYDANTIC_DISABLE_PLUGINS')
|
||||
global _plugins, _loading_plugins
|
||||
if _loading_plugins:
|
||||
# this happens when plugins themselves use pydantic, we return no plugins
|
||||
return ()
|
||||
elif disabled_plugins in ('__all__', '1', 'true'):
|
||||
return ()
|
||||
elif _plugins is None:
|
||||
_plugins = {}
|
||||
# set _loading_plugins so any plugins that use pydantic don't themselves use plugins
|
||||
@@ -45,12 +42,15 @@ def get_plugins() -> Iterable[PydanticPluginProtocol]:
|
||||
continue
|
||||
if entry_point.value in _plugins:
|
||||
continue
|
||||
if disabled_plugins is not None and entry_point.name in disabled_plugins.split(','):
|
||||
continue
|
||||
try:
|
||||
_plugins[entry_point.value] = entry_point.load()
|
||||
except (ImportError, AttributeError) as e:
|
||||
warnings.warn(
|
||||
f'{e.__class__.__name__} while loading the `{entry_point.name}` Pydantic plugin, '
|
||||
f'this plugin will not be installed.\n\n{e!r}'
|
||||
f'this plugin will not be installed.\n\n{e!r}',
|
||||
stacklevel=2,
|
||||
)
|
||||
finally:
|
||||
_loading_plugins = False
|
||||
|
||||
Reference in New Issue
Block a user