-
Notifications
You must be signed in to change notification settings - Fork 121
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
Feature/get plugins for hook #177
Merged
RonnyPfannschmidt
merged 9 commits into
pytest-dev:master
from
Sup3rGeo:feature/get-plugins-for-hook
Oct 14, 2018
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bcd551d
Added get_hookimpl with test.
5e1ee95
Fixed test.
17783a5
Updated docstring.
163ff50
Moved get_hookimpl to HookCaller.
ca0d071
Fixed test.
e1fcf60
Refactored to use get_hookimpls()
c85f154
Inverted order, needed for calls.
21dec08
Added comment to make order importance more explicit.
a5c17ec
Simplify asserts in test_get_hookimpls
nicoddemus 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 |
---|---|---|
|
@@ -384,6 +384,40 @@ class PluginNo(object): | |
assert out == [10] | ||
|
||
|
||
def test_get_hookimpl(pm): | ||
class Hooks(object): | ||
@hookspec | ||
def he_method1(self, arg): | ||
pass | ||
|
||
pm.add_hookspecs(Hooks) | ||
|
||
class Plugin1(object): | ||
Sup3rGeo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@hookimpl | ||
def he_method1(self, arg): | ||
pass | ||
|
||
class Plugin2(object): | ||
@hookimpl | ||
def he_method1(self, arg): | ||
pass | ||
|
||
class PluginNo(object): | ||
pass | ||
|
||
plugin1, plugin2, plugin3 = Plugin1(), Plugin2(), PluginNo() | ||
pm.register(plugin1) | ||
pm.register(plugin2) | ||
pm.register(plugin3) | ||
|
||
hookimpls = pm.get_hookimpl("he_method1") | ||
hook_plugins = [hookimpl.plugin for hookimpl in hookimpls] | ||
|
||
assert plugin1 in hook_plugins | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Took the liberty of improving this check a bit. 👍 |
||
assert plugin2 in hook_plugins | ||
assert plugin3 not in hook_plugins | ||
|
||
|
||
def test_add_hookspecs_nohooks(pm): | ||
with pytest.raises(ValueError): | ||
pm.add_hookspecs(10) | ||
|
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.
the part dealing with private attributes should be delegated to the hookcaller
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.
I initially did like this, but I saw other functions using also the
_wrappers+_nonwrappers
pattern and decided to follow it.Is it ok to refactor them as well to keep coherence?
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.
seems like i missed the introduction of the pattern, lets do this as a follow-up issue so this one can be self-contained an in line with the current coding standard, we can resolve the pattern as a separate pr after its merit is taken into account
so lets keep yours as is 👍
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.
Ok!
Another thing - if hookcaller can give you the hookimpl, then maybe it is more general if we can just get the caller from pluginmanager and then call
get_hookimpl()
on the returned caller.For getting the caller, we have two options:
hook_caller(name)
. Reads nice and simple.subset_hook_caller
withremove_plugins
asNone
or[]
. It actually just returns the original caller. No need to introduce another function, but does not read as nice (running this subset method to actually get the whole thing, not the subset)I think I prefer the first option.
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.
for now i wont explore the domain in detail as i lack personal time
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.
I just realized you can get the hookcaller just by
pluginmanager.hook.<name>
. Even better, then I will just add theget_hookimpl
to the hook caller, it should be enough.