Skip to content

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

Closed
bluetech wants to merge 1 commit into
pytest-dev:masterfrom
bluetech:merge-callers-hooks
Closed

Avoid cyclic dependency by merging callers.py into hooks.py#227
bluetech wants to merge 1 commit into
pytest-dev:masterfrom
bluetech:merge-callers-hooks

Conversation

@bluetech

Copy link
Copy Markdown
Member

The two modules have a type-level cyclic dependency:
hooks.py uses _multicall and _legacymulticall from callers.py.
callers.py uses HookImpl from hooks.py.

This suggests that they're better off combined.

The _Result functionality from callers.py is independent and general, so
move it to its own module _result.py.

Backward compatibility: I did not find any external project which
imports directly from pluggy.callers. It exposes two potential import
candidates:

  • HookCallError: exposed from the top-level, so no reason to reach
    inside.
  • _Result: it's prefixed and hidden, so no guarantees about that.

@bluetech bluetech mentioned this pull request Jul 26, 2019
The two modules have a type-level cyclic dependency:
hooks.py uses _multicall and _legacymulticall from callers.py.
callers.py uses HookImpl from hooks.py.

This suggests that they're better off combined.

The _Result functionality from callers.py is independent and general, so
move it to its own module _result.py.

Backward compatibility: I did not find any external project which
imports directly from pluggy.callers. It exposes two potential import
candidates:
- HookCallError: exposed from the top-level, so no reason to reach
  inside.
- _Result: it's prefixed and hidden, so no guarantees about that.
@bluetech bluetech force-pushed the merge-callers-hooks branch from 8d3bad6 to 36f03b2 Compare July 27, 2019 07:52
@codecov-io

codecov-io commented Jul 27, 2019

Copy link
Copy Markdown

Codecov Report

Merging #227 into master will decrease coverage by 0.01%.
The diff coverage is 79.84%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #227      +/-   ##
==========================================
- Coverage   93.08%   93.07%   -0.02%     
==========================================
  Files          14       14              
  Lines        1677     1674       -3     
  Branches      117      117              
==========================================
- Hits         1561     1558       -3     
  Misses        101      101              
  Partials       15       15
Impacted Files Coverage Δ
src/pluggy/__init__.py 71.42% <100%> (-3.58%) ⬇️
testing/test_deprecations.py 91.17% <100%> (ø) ⬆️
src/pluggy/_tracing.py 100% <100%> (ø) ⬆️
testing/test_multicall.py 99.27% <100%> (-0.01%) ⬇️
src/pluggy/_result.py 100% <100%> (ø)
src/pluggy/hooks.py 86.41% <70.78%> (-7.94%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a1c6c35...36f03b2. Read the comment docs.

@nicoddemus nicoddemus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks for the PR! 👍

Comment thread src/pluggy/hooks.py
return call_outcome.get_result()


class _LegacyMultiCall(object):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This reminds me, we can drop _LegacyMultiCall by now (#59).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There is an open PR for this #147. Would certainly simplify things to drop it, if it's now possible.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes that should land before we start moving big chunks of code around. Let's simplify first then worry about a reorg.

@pytest-dev pytest-dev deleted a comment from codecov-io Aug 15, 2019
@nicoddemus

Copy link
Copy Markdown
Member

@goodboy, absolutely no rush here, but would you like for us to wait here so you can review this, or are you OK with us merging this?

@goodboy

goodboy commented Aug 30, 2019

Copy link
Copy Markdown
Contributor

@nicoddemus I would like to review.

One thing I definitely want to maintain in the project is clarity of authorship. Moving big chunks of code around like this can sometimes obscure that.

@goodboy goodboy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The two modules have a type-level cyclic dependency:
hooks.py uses _multicall and _legacymulticall from callers.py.
callers.py uses HookImpl from hooks.py.

This suggests that they're better off combined.

Not sure I agree that HookImpl is a cyclic dependency (caller.py never instantiates the type only uses instances) and even if it more technically is from a design perspective, moving all the caller.py code into the hooks.py module is the wrong way to solve it. The dependency should be moved out of both modules into a lower level one.

HookImpl seems to originally be a way to work around not having a proper dataclass type and should probably go into some kind of type header like module where it can be imported by multiple modules that require its interface def. We don't want to be stuck in the same situation later with some new module C that requires it and then also hooks.py requires functionality from that new module - let's hope we don't also merge C into hooks.py 😏

On top of all of this callers.py was an effort to break out the caller implementations into a separate space so we can begin to generalize the interface and eventually add new implementations soon (see #50 and #151).

The _Result functionality from callers.py is independent and general, so
move it to its own module _result.py.

This I like though I wish there was some way we could keep track of original attribution - this is @hpk42's original code. Not sure if there's a way to solve this right now.

Summary:

  • callers.py -> _callers.py 👍 (should keep attribution in git)
  • moving _Result to a lower level module 👍 (original attribution would be nice but not a blocker)
  • move HookImpl into a lower level module (along with any others) to avoid cyclic interfaces.

Comment thread src/pluggy/hooks.py
self.opts = opts
self.argnames = ["__multicall__"] + list(self.argnames)
self.warn_on_impl = opts.get("warn_on_impl")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah so this is basically reverting work to break this stuff out of hooks.py originally (see the history). The idea here was that we want a separate package/module space so we can keep track of and add new caller implementations.

Imho putting this back into hooks is wrong and doesn't work towards that goal and we'll want to revert this again eventually anyway.

Comment thread src/pluggy/_result.py
@@ -0,0 +1,64 @@
import sys

Copy link
Copy Markdown
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..

Comment thread src/pluggy/hooks.py
return call_outcome.get_result()


class _LegacyMultiCall(object):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes that should land before we start moving big chunks of code around. Let's simplify first then worry about a reorg.

@bluetech

Copy link
Copy Markdown
Member Author

Thanks for the review @goodboy.

Yes that should land before we start moving big chunks of code around. Let's simplify first then worry about a reorg.

OK, so this is blocked on #147. I'll close this now and maybe revisit when that happens.

@bluetech bluetech closed this Sep 10, 2019
@bluetech bluetech mentioned this pull request Jun 4, 2020
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants