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

Avoid cyclic dependency by merging callers.py into hooks.py #227

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 2 additions & 2 deletions docs/api_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Api Reference
:show-inheritance:


.. automethod:: pluggy.callers._Result.get_result
.. automethod:: pluggy._result._Result.get_result

.. automethod:: pluggy.callers._Result.force_result
.. automethod:: pluggy._result._Result.force_result

.. automethod:: pluggy.hooks._HookCaller.call_extra
6 changes: 3 additions & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,11 @@ be implemented as generator function with a single ``yield`` in its body:
if config.use_defaults:
outcome.force_result(defaults)

The generator is `sent`_ a :py:class:`pluggy.callers._Result` object which can
The generator is `sent`_ a :py:class:`pluggy._result._Result` object which can
be assigned in the ``yield`` expression and used to override or inspect
the final result(s) returned back to the caller using the
:py:meth:`~pluggy.callers._Result.force_result` or
:py:meth:`~pluggy.callers._Result.get_result` methods.
:py:meth:`~pluggy._result._Result.force_result` or
:py:meth:`~pluggy._result._Result.get_result` methods.

.. note::
Hook wrappers can **not** return results (as per generator function
Expand Down
3 changes: 1 addition & 2 deletions src/pluggy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@
]

from .manager import PluginManager, PluginValidationError
from .callers import HookCallError
from .hooks import HookspecMarker, HookimplMarker
from .hooks import HookspecMarker, HookimplMarker, HookCallError
64 changes: 64 additions & 0 deletions src/pluggy/_result.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import sys
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm not huge on moving big chunks like this since we lose attribution from the original author in git (unless that's been addressed in recent versions).

I am guilty of this when creating this file (which was an attempt to breakout caller implementations into a separate namespace - see comment below). I really would have liked to have kept @hpk42's original attribution here..

import warnings


if sys.version_info < (3,):
exec(
"""
def _reraise(cls, val, tb):
raise cls, val, tb
"""
)


class _Result(object):
def __init__(self, result, excinfo):
self._result = result
self._excinfo = excinfo

@property
def excinfo(self):
return self._excinfo

@property
def result(self):
"""Get the result(s) for this hook call (DEPRECATED in favor of ``get_result()``)."""
msg = "Use get_result() which forces correct exception handling"
warnings.warn(DeprecationWarning(msg), stacklevel=2)
return self._result

@classmethod
def from_call(cls, func):
__tracebackhide__ = True
result = excinfo = None
try:
result = func()
except BaseException:
excinfo = sys.exc_info()

return cls(result, excinfo)

def force_result(self, result):
"""Force the result(s) to ``result``.

If the hook was marked as a ``firstresult`` a single value should
be set otherwise set a (modified) list of results. Any exceptions
found during invocation will be deleted.
"""
self._result = result
self._excinfo = None

def get_result(self):
"""Get the result(s) for this hook call.

If the hook was marked as a ``firstresult`` only a single value
will be returned otherwise a list of results.
"""
__tracebackhide__ = True
if self._excinfo is None:
return self._result
else:
ex = self._excinfo
if sys.version_info >= (3,):
raise ex[1].with_traceback(ex[2])
_reraise(*ex) # noqa
2 changes: 1 addition & 1 deletion src/pluggy/_tracing.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Tracing utils
"""
from .callers import _Result
from ._result import _Result


class TagTracer(object):
Expand Down
208 changes: 0 additions & 208 deletions src/pluggy/callers.py

This file was deleted.

Loading