From d19c9bf89fe176c00756a3f9a97c67b1e4a6c2ba Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Fri, 5 Jun 2020 10:13:16 +0300 Subject: [PATCH] Remove deprecated implprefix support --- changelog/116.removal.rst | 3 ++ src/pluggy/manager.py | 22 +---------- testing/test_deprecations.py | 14 +------ testing/test_pluginmanager.py | 69 ----------------------------------- 4 files changed, 5 insertions(+), 103 deletions(-) create mode 100644 changelog/116.removal.rst diff --git a/changelog/116.removal.rst b/changelog/116.removal.rst new file mode 100644 index 00000000..8f83ee63 --- /dev/null +++ b/changelog/116.removal.rst @@ -0,0 +1,3 @@ +Remove deprecated ``implprefix`` support. +Decorate hook implementations using an instance of HookimplMarker instead. +The deprecation was announced in release ``0.7.0``. diff --git a/src/pluggy/manager.py b/src/pluggy/manager.py index 6677a440..f7e8ceb6 100644 --- a/src/pluggy/manager.py +++ b/src/pluggy/manager.py @@ -64,23 +64,13 @@ class PluginManager(object): which will subsequently send debug information to the trace helper. """ - def __init__(self, project_name, implprefix=None): - """If ``implprefix`` is given implementation functions - will be recognized if their name matches the ``implprefix``. """ + def __init__(self, project_name): self.project_name = project_name self._name2plugin = {} self._plugin2hookcallers = {} self._plugin_distinfo = [] self.trace = _tracing.TagTracer().get("pluginmanage") self.hook = _HookRelay() - if implprefix is not None: - warnings.warn( - "Support for the `implprefix` arg is now deprecated and will " - "be removed in an upcoming release. Please use HookimplMarker.", - DeprecationWarning, - stacklevel=2, - ) - self._implprefix = implprefix self._inner_hookexec = lambda hook, methods, kwargs: _multicall( methods, kwargs, @@ -141,16 +131,6 @@ def parse_hookimpl_opts(self, plugin, name): if res is not None and not isinstance(res, dict): # false positive res = None - # TODO: remove when we drop implprefix in 1.0 - elif res is None and self._implprefix and name.startswith(self._implprefix): - _warn_for_function( - DeprecationWarning( - "The `implprefix` system is deprecated please decorate " - "this function using an instance of HookimplMarker." - ), - method, - ) - res = {} return res def unregister(self, plugin=None, name=None): diff --git a/testing/test_deprecations.py b/testing/test_deprecations.py index bfec882f..d0a6c623 100644 --- a/testing/test_deprecations.py +++ b/testing/test_deprecations.py @@ -2,24 +2,12 @@ Deprecation warnings testing roundup. """ import pytest -from pluggy import PluginManager, HookimplMarker, HookspecMarker +from pluggy import HookimplMarker, HookspecMarker hookspec = HookspecMarker("example") hookimpl = HookimplMarker("example") -def test_implprefix_deprecated(): - with pytest.deprecated_call(): - pm = PluginManager("blah", implprefix="blah_") - - class Plugin: - def blah_myhook(self, arg1): - return arg1 - - with pytest.deprecated_call(): - pm.register(Plugin()) - - def test_callhistoric_proc_deprecated(pm): """``proc`` kwarg to `PluginMananger.call_historic()` is now officially deprecated. diff --git a/testing/test_pluginmanager.py b/testing/test_pluginmanager.py index 67261aaa..96d4f2dc 100644 --- a/testing/test_pluginmanager.py +++ b/testing/test_pluginmanager.py @@ -2,10 +2,8 @@ ``PluginManager`` unit and public API testing. """ import pytest -import types from pluggy import ( - PluginManager, PluginValidationError, HookCallError, HookimplMarker, @@ -422,31 +420,6 @@ def test_add_hookspecs_nohooks(pm): pm.add_hookspecs(10) -def test_reject_prefixed_module(pm): - """Verify that a module type attribute that contains the project - prefix in its name (in this case `'example_*'` isn't collected - when registering a module which imports it. - """ - pm._implprefix = "example" - conftest = types.ModuleType("conftest") - src = """ -def example_hook(): - pass -""" - exec(src, conftest.__dict__) - conftest.example_blah = types.ModuleType("example_blah") - with pytest.deprecated_call(): - name = pm.register(conftest) - assert name == "conftest" - assert getattr(pm.hook, "example_blah", None) is None - assert getattr( - pm.hook, "example_hook", None - ) # conftest.example_hook should be collected - with pytest.deprecated_call(): - assert pm.parse_hookimpl_opts(conftest, "example_blah") is None - assert pm.parse_hookimpl_opts(conftest, "example_hook") == {} - - def test_load_setuptools_instantiation(monkeypatch, pm): class EntryPoint(object): name = "myname" @@ -556,45 +529,3 @@ def he_method1(self): assert saveindent[0] > indent finally: undo() - - -def test_implprefix_warning(recwarn): - PluginManager(hookspec.project_name, "hello_") - w = recwarn.pop(DeprecationWarning) - assert "test_pluginmanager.py" in w.filename - - -@pytest.mark.parametrize("include_hookspec", [True, False]) -def test_prefix_hookimpl(include_hookspec): - with pytest.deprecated_call(): - pm = PluginManager(hookspec.project_name, "hello_") - - if include_hookspec: - - class HookSpec(object): - @hookspec - def hello_myhook(self, arg1): - """ add to arg1 """ - - pm.add_hookspecs(HookSpec) - - class Plugin(object): - def hello_myhook(self, arg1): - return arg1 + 1 - - with pytest.deprecated_call(): - pm.register(Plugin()) - pm.register(Plugin()) - results = pm.hook.hello_myhook(arg1=17) - assert results == [18, 18] - - -def test_prefix_hookimpl_dontmatch_module(): - with pytest.deprecated_call(): - pm = PluginManager(hookspec.project_name, "hello_") - - class BadPlugin(object): - hello_module = __import__("email") - - pm.register(BadPlugin()) - pm.check_pending()