Giter Site home page Giter Site logo

Comments (12)

nicoddemus avatar nicoddemus commented on August 23, 2024

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.

MrGreenTea avatar MrGreenTea commented on August 23, 2024

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.

nicoddemus avatar nicoddemus commented on August 23, 2024

How about required=True?

from pluggy.

hoefling avatar hoefling commented on August 23, 2024

@nicoddemus:

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.

MrGreenTea avatar MrGreenTea commented on August 23, 2024

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.

nicoddemus avatar nicoddemus commented on August 23, 2024

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.

MrGreenTea avatar MrGreenTea commented on August 23, 2024

I would love to hear another opinion on this, though I agree with you that required looks nicer :)

from pluggy.

hoefling avatar hoefling commented on August 23, 2024

@MrGreenTea:

Do you mean hook implementations?

Sure, my bad.

from pluggy.

hpk42 avatar hpk42 commented on August 23, 2024

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.

MrGreenTea avatar MrGreenTea commented on August 23, 2024

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.

RonnyPfannschmidt avatar RonnyPfannschmidt commented on August 23, 2024

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.

hpk42 avatar hpk42 commented on August 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.