Skip to content

Commit cab120f

Browse files
author
goodboy
authored
Merge pull request #144 from tgoodlet/deprecate_implprefix
Deprecate implprefix
2 parents aeb1f67 + 77578ad commit cab120f

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

pluggy/manager.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,20 @@ class PluginManager(object):
4040
"""
4141

4242
def __init__(self, project_name, implprefix=None):
43-
""" if implprefix is given implementation functions
43+
"""If ``implprefix`` is given implementation functions
4444
will be recognized if their name matches the implprefix. """
4545
self.project_name = project_name
4646
self._name2plugin = {}
4747
self._plugin2hookcallers = {}
4848
self._plugin_distinfo = []
4949
self.trace = _tracing.TagTracer().get("pluginmanage")
5050
self.hook = _HookRelay(self.trace.root.get("hook"))
51+
if implprefix is not None:
52+
warnings.warn(
53+
"Support for the `implprefix` arg is now deprecated and will "
54+
"be removed in an upcoming release. Please use HookimplMarker.",
55+
DeprecationWarning
56+
)
5157
self._implprefix = implprefix
5258
self._inner_hookexec = lambda hook, methods, kwargs: \
5359
hook.multicall(
@@ -106,7 +112,14 @@ def parse_hookimpl_opts(self, plugin, name):
106112
if res is not None and not isinstance(res, dict):
107113
# false positive
108114
res = None
115+
# TODO: remove when we drop implprefix in 1.0
109116
elif res is None and self._implprefix and name.startswith(self._implprefix):
117+
_warn_for_function(
118+
DeprecationWarning(
119+
"The `implprefix` system is deprecated please decorate "
120+
"this function using an instance of HookimplMarker."),
121+
method
122+
)
110123
res = {}
111124
return res
112125

testing/test_details.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,15 @@ def test_result_deprecated():
124124
r = _Result(10, None)
125125
with pytest.deprecated_call():
126126
assert r.result == 10
127+
128+
129+
def test_implprefix_deprecated():
130+
with pytest.deprecated_call():
131+
pm = PluginManager('blah', implprefix='blah_')
132+
133+
class Plugin:
134+
def blah_myhook(self, arg1):
135+
return arg1
136+
137+
with pytest.deprecated_call():
138+
pm.register(Plugin())

testing/test_method_ordering.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ def he_method1(self):
291291

292292
@pytest.mark.parametrize('include_hookspec', [True, False])
293293
def test_prefix_hookimpl(include_hookspec):
294-
pm = PluginManager(hookspec.project_name, "hello_")
294+
with pytest.deprecated_call():
295+
pm = PluginManager(hookspec.project_name, "hello_")
295296

296297
if include_hookspec:
297298
class HookSpec(object):
@@ -305,14 +306,16 @@ class Plugin(object):
305306
def hello_myhook(self, arg1):
306307
return arg1 + 1
307308

308-
pm.register(Plugin())
309-
pm.register(Plugin())
309+
with pytest.deprecated_call():
310+
pm.register(Plugin())
311+
pm.register(Plugin())
310312
results = pm.hook.hello_myhook(arg1=17)
311313
assert results == [18, 18]
312314

313315

314316
def test_prefix_hookimpl_dontmatch_module():
315-
pm = PluginManager(hookspec.project_name, "hello_")
317+
with pytest.deprecated_call():
318+
pm = PluginManager(hookspec.project_name, "hello_")
316319

317320
class BadPlugin(object):
318321
hello_module = __import__('email')

testing/test_pluginmanager.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,12 +393,14 @@ def example_hook():
393393
""")
394394
exec(src, conftest.__dict__)
395395
conftest.example_blah = types.ModuleType("example_blah")
396-
name = pm.register(conftest)
396+
with pytest.deprecated_call():
397+
name = pm.register(conftest)
397398
assert name == 'conftest'
398399
assert getattr(pm.hook, 'example_blah', None) is None
399400
assert getattr(pm.hook, 'example_hook', None) # conftest.example_hook should be collected
400-
assert pm.parse_hookimpl_opts(conftest, 'example_blah') is None
401-
assert pm.parse_hookimpl_opts(conftest, 'example_hook') == {}
401+
with pytest.deprecated_call():
402+
assert pm.parse_hookimpl_opts(conftest, 'example_blah') is None
403+
assert pm.parse_hookimpl_opts(conftest, 'example_hook') == {}
402404

403405

404406
def test_callhistoric_proc_deprecated(pm):

0 commit comments

Comments
 (0)