Comments (12)
I don't think there's support for that currently, but one workaround might for your plugin to implement the hook and return some sentinel object. When you call the hook implementation, you then might check if the call returned only [sentinel]
which means only your call was implemented and treat that accordingly.
from pluggy.
I implemented that functionality, but am unsure how to name the parameter.
requireimplementation=True
is very long and not as readable as I would like, require_implementation=True
is inconsistent with the other parameter firstresult
.
I named it requireimpl
for now, because of HookImplMarker
and it often being assigned to hookimpl
.
What do you/others think?
from pluggy.
How about required=True
?
from pluggy.
When you call the hook implementation, you then might check if the call returned only [sentinel] which means only your call was implemented and treat that accordingly.
This means that it's not possible to validate plugin availability without their implicit execution?
from pluggy.
required=True
sounds good, but I feel is not telling enough what exactly is required.
@hoefling Do you mean hook implementations? There is a has_plugin
method for checking plugin availability.
from pluggy.
IMHO:
@hookspec(required=True)
def my_hook():
Is clear enough, but that's just me. requireimpl
sounds fine as well, although I like my suggestion better. 😁
from pluggy.
I would love to hear another opinion on this, though I agree with you that required
looks nicer :)
from pluggy.
Do you mean hook implementations?
Sure, my bad.
from pluggy.
I am with hoefling on that required=True
does not convey much meaning.
Moreover, i am skeptical of putting this into the hookspec. I'd rather like to have another runtime-API like my_hook.has_implementations()
returning True or False. In several projects using pluggy i've never had the need for asserting that a hook must have implementations FWIW.
from pluggy.
I believe having it in the actual hook definition makes it easier to see what hooks require an implementation. Having to find the places where the hook is called and checking if their is a check for my_hook.has_implementation()
sounds unnecessary when developing plugins. It also adheres to the principle of EAFP.
We plan on using pluggy to allow easy interchangability of parts of the system, also for some "core functionality" of the whole system. That's where I believe an explicit error will help in development and testing.
from pluggy.
why is it a problem to begin with if certain hooks have no implementation at all?
@MrGreenTea do you have a minimal example that illustrates this, both @hpk42 and me have a very different perspective on the issue/usage and may be completely missing your point without a painfully oblivious illustration
from pluggy.
I am closing this as i don't see enough rationale yet for adding something to hookspec. I'd like to keep pluggy minimal especially wrt to hookspec. I hold that something like assert hook.has_implementations()
would be sufficient and simpler to understand directly at the calling site of the hook. @MrGreenTea feel free to add a PR along those lines and thanks for your efforts so far!
from pluggy.
Related Issues (20)
- Export our typing HOT 2
- multi hook registration does not unregister HOT 6
- Can plugins be executed concurrently? HOT 3
- RFE: is it possible to start making github releases?🤔 HOT 3
- pytest won't run root conftest.py's pytest_configure in special circumstances HOT 2
- Rename misleading function name `PluggyManager.load_setuptools_entrypoints` HOT 3
- Issue with ordering of hooks HOT 2
- Question about default values in hook implementation HOT 1
- discussion: pluggy speedup by using 'codegen' HOT 7
- Is it possible to override an existing hook with a HookCaller class?
- pluggy loads disabled pytest plugins HOT 5
- Warn when old-style hookwrapper raises during teardown
- Add python-lsp-server to downstream tests
- Troubles to understand the new updates on Pluggy HOT 11
- Bug: Pluggy 1.4 searches all home dirs for __init__.py HOT 2
- Possible to tell which hook answered a call? HOT 1
- load_setuptools_entrypoints messing up with rpath HOT 2
- How to get in touch regarding a security concern HOT 6
- [FR] Rename `load_setuptools_entrypoints` to `load_package_metadata_entrypoints()` HOT 2
- Why `pluggy` ignore `hookimpl` kwargsnames? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pluggy.