mirror of
https://github.com/certbot/certbot.git
synced 2026-08-03 00:22:04 +02:00
plugins: remove support for dist:plugin plugin names (#9359)
* plugins: remove support for dist:plugin plugin names * address feedback
This commit is contained in:
@@ -51,32 +51,23 @@ class PluginEntryPoint:
|
|||||||
# this object is mutable, don't allow it to be hashed!
|
# this object is mutable, don't allow it to be hashed!
|
||||||
__hash__ = None # type: ignore
|
__hash__ = None # type: ignore
|
||||||
|
|
||||||
def __init__(self, entry_point: pkg_resources.EntryPoint, with_prefix: bool = False) -> None:
|
def __init__(self, entry_point: pkg_resources.EntryPoint) -> None:
|
||||||
self.name = self.entry_point_to_plugin_name(entry_point, with_prefix)
|
self.name = self.entry_point_to_plugin_name(entry_point)
|
||||||
self.plugin_cls: Type[interfaces.Plugin] = entry_point.load()
|
self.plugin_cls: Type[interfaces.Plugin] = entry_point.load()
|
||||||
self.entry_point = entry_point
|
self.entry_point = entry_point
|
||||||
self.warning_message: Optional[str] = None
|
self.warning_message: Optional[str] = None
|
||||||
self._initialized: Optional[interfaces.Plugin] = None
|
self._initialized: Optional[interfaces.Plugin] = None
|
||||||
self._prepared: Optional[Union[bool, Error]] = None
|
self._prepared: Optional[Union[bool, Error]] = None
|
||||||
self._hidden = False
|
|
||||||
self._long_description: Optional[str] = None
|
|
||||||
|
|
||||||
def check_name(self, name: Optional[str]) -> bool:
|
def check_name(self, name: Optional[str]) -> bool:
|
||||||
"""Check if the name refers to this plugin."""
|
"""Check if the name refers to this plugin."""
|
||||||
if name == self.name:
|
if name == self.name:
|
||||||
if self.warning_message:
|
|
||||||
logger.warning(self.warning_message)
|
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def entry_point_to_plugin_name(cls, entry_point: pkg_resources.EntryPoint,
|
def entry_point_to_plugin_name(cls, entry_point: pkg_resources.EntryPoint) -> str:
|
||||||
with_prefix: bool) -> str:
|
|
||||||
"""Unique plugin name for an ``entry_point``"""
|
"""Unique plugin name for an ``entry_point``"""
|
||||||
if with_prefix:
|
|
||||||
if not entry_point.dist:
|
|
||||||
raise errors.Error(f"Entrypoint {entry_point.name} has no distribution!")
|
|
||||||
return entry_point.dist.key + ":" + entry_point.name
|
|
||||||
return entry_point.name
|
return entry_point.name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -92,22 +83,12 @@ class PluginEntryPoint:
|
|||||||
@property
|
@property
|
||||||
def long_description(self) -> str:
|
def long_description(self) -> str:
|
||||||
"""Long description of the plugin."""
|
"""Long description of the plugin."""
|
||||||
if self._long_description:
|
|
||||||
return self._long_description
|
|
||||||
return getattr(self.plugin_cls, "long_description", self.description)
|
return getattr(self.plugin_cls, "long_description", self.description)
|
||||||
|
|
||||||
@long_description.setter
|
|
||||||
def long_description(self, description: str) -> None:
|
|
||||||
self._long_description = description
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hidden(self) -> bool:
|
def hidden(self) -> bool:
|
||||||
"""Should this plugin be hidden from UI?"""
|
"""Should this plugin be hidden from UI?"""
|
||||||
return self._hidden or getattr(self.plugin_cls, "hidden", False)
|
return getattr(self.plugin_cls, "hidden", False)
|
||||||
|
|
||||||
@hidden.setter
|
|
||||||
def hidden(self, hide: bool) -> None:
|
|
||||||
self._hidden = hide
|
|
||||||
|
|
||||||
def ifaces(self, *ifaces_groups: Iterable[Type]) -> bool:
|
def ifaces(self, *ifaces_groups: Iterable[Type]) -> bool:
|
||||||
"""Does plugin implements specified interface groups?"""
|
"""Does plugin implements specified interface groups?"""
|
||||||
@@ -224,27 +205,14 @@ class PluginsRegistry(Mapping):
|
|||||||
pkg_resources.iter_entry_points(
|
pkg_resources.iter_entry_points(
|
||||||
constants.OLD_SETUPTOOLS_PLUGINS_ENTRY_POINT),)
|
constants.OLD_SETUPTOOLS_PLUGINS_ENTRY_POINT),)
|
||||||
for entry_point in entry_points:
|
for entry_point in entry_points:
|
||||||
plugin_ep = cls._load_entry_point(entry_point, plugins, with_prefix=False)
|
cls._load_entry_point(entry_point, plugins)
|
||||||
# entry_point.dist cannot be None here, we would have blown up
|
|
||||||
# earlier, however, this assertion is needed for mypy.
|
|
||||||
assert entry_point.dist is not None
|
|
||||||
if entry_point.dist.key not in PREFIX_FREE_DISTRIBUTIONS:
|
|
||||||
prefixed_plugin_ep = cls._load_entry_point(entry_point, plugins, with_prefix=True)
|
|
||||||
prefixed_plugin_ep.hidden = True
|
|
||||||
message = (
|
|
||||||
"Plugin legacy name {0} may be removed in a future version. "
|
|
||||||
"Please use {1} instead.").format(prefixed_plugin_ep.name, plugin_ep.name)
|
|
||||||
prefixed_plugin_ep.warning_message = message
|
|
||||||
prefixed_plugin_ep.long_description = "(WARNING: {0}) {1}".format(
|
|
||||||
message, prefixed_plugin_ep.long_description)
|
|
||||||
|
|
||||||
return cls(plugins)
|
return cls(plugins)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _load_entry_point(cls, entry_point: pkg_resources.EntryPoint,
|
def _load_entry_point(cls, entry_point: pkg_resources.EntryPoint,
|
||||||
plugins: Dict[str, PluginEntryPoint],
|
plugins: Dict[str, PluginEntryPoint]) -> None:
|
||||||
with_prefix: bool) -> PluginEntryPoint:
|
plugin_ep = PluginEntryPoint(entry_point)
|
||||||
plugin_ep = PluginEntryPoint(entry_point, with_prefix)
|
|
||||||
if plugin_ep.name in plugins:
|
if plugin_ep.name in plugins:
|
||||||
other_ep = plugins[plugin_ep.name]
|
other_ep = plugins[plugin_ep.name]
|
||||||
plugin1 = plugin_ep.entry_point.dist.key if plugin_ep.entry_point.dist else "unknown"
|
plugin1 = plugin_ep.entry_point.dist.key if plugin_ep.entry_point.dist else "unknown"
|
||||||
@@ -257,8 +225,6 @@ class PluginsRegistry(Mapping):
|
|||||||
logger.warning(
|
logger.warning(
|
||||||
"%r does not inherit from Plugin, skipping", plugin_ep)
|
"%r does not inherit from Plugin, skipping", plugin_ep)
|
||||||
|
|
||||||
return plugin_ep
|
|
||||||
|
|
||||||
def __getitem__(self, name: str) -> PluginEntryPoint:
|
def __getitem__(self, name: str) -> PluginEntryPoint:
|
||||||
return self._plugins[name]
|
return self._plugins[name]
|
||||||
|
|
||||||
|
|||||||
@@ -55,21 +55,7 @@ class PluginEntryPointTest(unittest.TestCase):
|
|||||||
|
|
||||||
for entry_point, name in names.items():
|
for entry_point, name in names.items():
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
name, PluginEntryPoint.entry_point_to_plugin_name(entry_point, with_prefix=False))
|
name, PluginEntryPoint.entry_point_to_plugin_name(entry_point))
|
||||||
|
|
||||||
def test_entry_point_to_plugin_name_prefixed(self):
|
|
||||||
from certbot._internal.plugins.disco import PluginEntryPoint
|
|
||||||
|
|
||||||
names = {
|
|
||||||
self.ep1: "p1:ep1",
|
|
||||||
self.ep1prim: "p2:ep1",
|
|
||||||
self.ep2: "p2:ep2",
|
|
||||||
self.ep3: "p3:ep3",
|
|
||||||
}
|
|
||||||
|
|
||||||
for entry_point, name in names.items():
|
|
||||||
self.assertEqual(
|
|
||||||
name, PluginEntryPoint.entry_point_to_plugin_name(entry_point, with_prefix=True))
|
|
||||||
|
|
||||||
def test_description(self):
|
def test_description(self):
|
||||||
self.assertIn("temporary webserver", self.plugin_ep.description)
|
self.assertIn("temporary webserver", self.plugin_ep.description)
|
||||||
@@ -204,8 +190,7 @@ class PluginsRegistryTest(unittest.TestCase):
|
|||||||
self.assertIs(plugins["wr"].entry_point, EP_WR)
|
self.assertIs(plugins["wr"].entry_point, EP_WR)
|
||||||
self.assertIs(plugins["ep1"].plugin_cls, null.Installer)
|
self.assertIs(plugins["ep1"].plugin_cls, null.Installer)
|
||||||
self.assertIs(plugins["ep1"].entry_point, self.ep1)
|
self.assertIs(plugins["ep1"].entry_point, self.ep1)
|
||||||
self.assertIs(plugins["p1:ep1"].plugin_cls, null.Installer)
|
self.assertNotIn("p1:ep1", plugins)
|
||||||
self.assertIs(plugins["p1:ep1"].entry_point, self.ep1)
|
|
||||||
|
|
||||||
def test_getitem(self):
|
def test_getitem(self):
|
||||||
self.assertEqual(self.plugin_ep, self.reg["mock"])
|
self.assertEqual(self.plugin_ep, self.reg["mock"])
|
||||||
|
|||||||
Reference in New Issue
Block a user