-
Notifications
You must be signed in to change notification settings - Fork 124
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 __multicall__ #58
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fb00c4e
Convert pluggy.py into a package module
845c502
Deprecate __multicall__ support
09d7589
Adjust tests to use legacy multicall when necessary
21fd6c4
Parametrize over legacy versus new multicall types
88f1b73
Remove _CallOutcome; embrace _Result
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
''' | ||
Call loop machinery | ||
''' | ||
import sys | ||
|
||
|
||
_py3 = sys.version_info > (3, 0) | ||
|
||
|
||
if not _py3: | ||
exec(""" | ||
def _reraise(cls, val, tb): | ||
raise cls, val, tb | ||
""") | ||
|
||
|
||
def _raise_wrapfail(wrap_controller, msg): | ||
co = wrap_controller.gi_code | ||
raise RuntimeError("wrap_controller at %r %s:%d %s" % | ||
(co.co_name, co.co_filename, co.co_firstlineno, msg)) | ||
|
||
|
||
class HookCallError(Exception): | ||
""" Hook was called wrongly. """ | ||
|
||
|
||
class Result(object): | ||
def __init__(self, result, excinfo): | ||
self.result = result | ||
self.excinfo = excinfo | ||
|
||
def force_result(self, result): | ||
self.result = result | ||
self.excinfo = None | ||
|
||
def get_result(self): | ||
if self.excinfo is None: | ||
return self.result | ||
else: | ||
ex = self.excinfo | ||
if _py3: | ||
raise ex[1].with_traceback(ex[2]) | ||
_reraise(*ex) # noqa | ||
|
||
|
||
class _MultiCall(object): | ||
"""Execute a call into multiple python functions/methods. | ||
""" | ||
def __init__(self, hook_impls, kwargs, specopts={}, hook=None): | ||
self.hook = hook | ||
self.hook_impls = hook_impls | ||
self.caller_kwargs = kwargs # come from _HookCaller.__call__() | ||
self.specopts = hook.spec_opts if hook else specopts | ||
|
||
def execute(self): | ||
caller_kwargs = self.caller_kwargs | ||
self.results = results = [] | ||
firstresult = self.specopts.get("firstresult") | ||
excinfo = None | ||
try: # run impl and wrapper setup functions in a loop | ||
teardowns = [] | ||
try: | ||
for hook_impl in reversed(self.hook_impls): | ||
try: | ||
args = [caller_kwargs[argname] for argname in hook_impl.argnames] | ||
# args = operator.itemgetter(hookimpl.argnames)(caller_kwargs) | ||
except KeyError: | ||
for argname in hook_impl.argnames: | ||
if argname not in caller_kwargs: | ||
raise HookCallError( | ||
"hook call must provide argument %r" % (argname,)) | ||
|
||
if hook_impl.hookwrapper: | ||
try: | ||
gen = hook_impl.function(*args) | ||
next(gen) # first yield | ||
teardowns.append(gen) | ||
except StopIteration: | ||
_raise_wrapfail(gen, "did not yield") | ||
else: | ||
res = hook_impl.function(*args) | ||
if res is not None: | ||
results.append(res) | ||
if firstresult: # halt further impl calls | ||
break | ||
except BaseException: | ||
excinfo = sys.exc_info() | ||
finally: | ||
outcome = Result(results, excinfo) | ||
|
||
# run all wrapper post-yield blocks | ||
for gen in reversed(teardowns): | ||
try: | ||
gen.send(outcome) | ||
_raise_wrapfail(gen, "has second yield") | ||
except StopIteration: | ||
pass | ||
|
||
if firstresult: | ||
return outcome.get_result()[0] | ||
|
||
return outcome.get_result() | ||
|
||
def __repr__(self): | ||
status = "%d meths" % (len(self.hook_impls),) | ||
if hasattr(self, "results"): | ||
status = ("%d results, " % len(self.results)) + status | ||
return "<_MultiCall %s, kwargs=%r>" % (status, self.caller_kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a duplication of outcome just to remove the bad ctor
lets just move the exception handling behaviour to a alternate ctor,
so we can have
_Result(result=...)
or_Result.from_call(func)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I really didn't like the duplication.
@RonnyPfannschmidt are you ok with keeping
_Result
and being rid of_CallOutcome
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
both are internal classes and the exposed api is the same, so go ahead :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RonnyPfannschmidt good enough?