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

Remove deprecated implprefix support #271

Merged
merged 1 commit into from
Jun 7, 2020
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions changelog/116.removal.rst
Original file line number Diff line number Diff line change
@@ -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``.
22 changes: 1 addition & 21 deletions src/pluggy/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down
14 changes: 1 addition & 13 deletions testing/test_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
69 changes: 0 additions & 69 deletions testing/test_pluginmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
``PluginManager`` unit and public API testing.
"""
import pytest
import types

from pluggy import (
PluginManager,
PluginValidationError,
HookCallError,
HookimplMarker,
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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()