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

Deprecate implprefix #144

Merged
merged 3 commits into from
May 22, 2018
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
15 changes: 14 additions & 1 deletion pluggy/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,20 @@ class PluginManager(object):
"""

def __init__(self, project_name, implprefix=None):
""" if implprefix is given implementation functions
"""If ``implprefix`` is given implementation functions
will be recognized if their name matches the implprefix. """
self.project_name = project_name
self._name2plugin = {}
self._plugin2hookcallers = {}
self._plugin_distinfo = []
self.trace = _tracing.TagTracer().get("pluginmanage")
self.hook = _HookRelay(self.trace.root.get("hook"))
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
)
self._implprefix = implprefix
self._inner_hookexec = lambda hook, methods, kwargs: \
hook.multicall(
Expand Down Expand Up @@ -106,7 +112,14 @@ 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

Expand Down
12 changes: 12 additions & 0 deletions testing/test_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,15 @@ def test_result_deprecated():
r = _Result(10, None)
with pytest.deprecated_call():
assert r.result == 10


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())
11 changes: 7 additions & 4 deletions testing/test_method_ordering.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ def he_method1(self):

@pytest.mark.parametrize('include_hookspec', [True, False])
def test_prefix_hookimpl(include_hookspec):
pm = PluginManager(hookspec.project_name, "hello_")
with pytest.deprecated_call():
pm = PluginManager(hookspec.project_name, "hello_")

if include_hookspec:
class HookSpec(object):
Expand All @@ -305,14 +306,16 @@ class Plugin(object):
def hello_myhook(self, arg1):
return arg1 + 1

pm.register(Plugin())
pm.register(Plugin())
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():
pm = PluginManager(hookspec.project_name, "hello_")
with pytest.deprecated_call():
pm = PluginManager(hookspec.project_name, "hello_")

class BadPlugin(object):
hello_module = __import__('email')
Expand Down
8 changes: 5 additions & 3 deletions testing/test_pluginmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,14 @@ def example_hook():
""")
exec(src, conftest.__dict__)
conftest.example_blah = types.ModuleType("example_blah")
name = pm.register(conftest)
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
assert pm.parse_hookimpl_opts(conftest, 'example_blah') is None
assert pm.parse_hookimpl_opts(conftest, 'example_hook') == {}
with pytest.deprecated_call():
assert pm.parse_hookimpl_opts(conftest, 'example_blah') is None
assert pm.parse_hookimpl_opts(conftest, 'example_hook') == {}


def test_callhistoric_proc_deprecated(pm):
Expand Down