Skip to content

Commit bfc2ae3

Browse files
author
Tyler Goodlet
committed
Move hook execution tracer to tracing module
1 parent dfedf4a commit bfc2ae3

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

pluggy/_tracing.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""
2+
Tracing utils
3+
"""
4+
from .callers import _Result
15

26

37
class TagTracer(object):
@@ -60,3 +64,22 @@ def setmyprocessor(self, processor):
6064

6165
def get(self, name):
6266
return self.__class__(self.root, self.tags + (name,))
67+
68+
69+
class _TracedHookExecution(object):
70+
def __init__(self, pluginmanager, before, after):
71+
self.pluginmanager = pluginmanager
72+
self.before = before
73+
self.after = after
74+
self.oldcall = pluginmanager._inner_hookexec
75+
assert not isinstance(self.oldcall, _TracedHookExecution)
76+
self.pluginmanager._inner_hookexec = self
77+
78+
def __call__(self, hook, hook_impls, kwargs):
79+
self.before(hook.name, hook_impls, kwargs)
80+
outcome = _Result.from_call(lambda: self.oldcall(hook, hook_impls, kwargs))
81+
self.after(outcome, hook.name, hook_impls, kwargs)
82+
return outcome.get_result()
83+
84+
def undo(self):
85+
self.pluginmanager._inner_hookexec = self.oldcall

pluggy/manager.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,6 @@ class PluginValidationError(Exception):
88
""" plugin failed validation. """
99

1010

11-
class _TracedHookExecution(object):
12-
def __init__(self, pluginmanager, before, after):
13-
self.pluginmanager = pluginmanager
14-
self.before = before
15-
self.after = after
16-
self.oldcall = pluginmanager._inner_hookexec
17-
assert not isinstance(self.oldcall, _TracedHookExecution)
18-
self.pluginmanager._inner_hookexec = self
19-
20-
def __call__(self, hook, hook_impls, kwargs):
21-
self.before(hook.name, hook_impls, kwargs)
22-
outcome = _Result.from_call(lambda: self.oldcall(hook, hook_impls, kwargs))
23-
self.after(outcome, hook.name, hook_impls, kwargs)
24-
return outcome.get_result()
25-
26-
def undo(self):
27-
self.pluginmanager._inner_hookexec = self.oldcall
28-
29-
3011
class PluginManager(object):
3112
""" Core Pluginmanager class which manages registration
3213
of plugin objects and 1:N hook calling.
@@ -271,7 +252,7 @@ def add_hookcall_monitoring(self, before, after):
271252
same arguments as ``before`` but also a :py:class:`_Result`` object
272253
which represents the result of the overall hook call.
273254
"""
274-
return _TracedHookExecution(self, before, after).undo
255+
return _tracing._TracedHookExecution(self, before, after).undo
275256

276257
def enable_tracing(self):
277258
""" enable tracing of hook calls and return an undo function. """

0 commit comments

Comments
 (0)