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
properties: add adapter for callables #522
Conversation
it is a very common need for users just to want to create a function to do the property interpolation. one can now say: Shell(command=lambda p:"echo next build is"+(p.getProperty("buildnumber")+1)) Signed-off-by: Pierre Tardy <pierre.tardy@intel.com>
I like this! Can you add some docs once the Interpolate docs are in? |
I feel that this should be a decorator, rather than an adapter. I don't have a good reason for this, but that is why I didn't implement this originally. I think part of the reason is that it isn't obvious to me that the signature that this expects is the only/most common reasonable one, and so I didn't want to commit to a particular interpretation. |
Also, I think that whatever this ends up looking like, it should land in 0.8.7. |
Another benefit to not having something like this, is that it exposes people to the simplicity of writing renderables. |
while renderable is simple and elegant, it still uses advanced python semantics. I think we should not require our users to use decorators, or even to override classes when it is not stricly needed. I like the syntax sugar of adapters, and the fact that it just works. |
This is also one-line syntax, where decorators and/or renderables require more verbiage. |
Something like
seems like better code, even if it is slightly more verbose. |
The lambda fans could also write
I think both adaptor VS decorator approaches make sense. dustin to decide.. |
I personally really like the decorator. As tardyp mentions, the lambda version works with decorator, and the decorator feels more pythonic as a solution. And for naming, can we call the decorator @withProperties. (ducks. im kidding.) |
I'm disappointed that @jaredgrubb was kidding, since that name is probably the ideal name (except of course for the fact that we have an existing class |
@tomprince .. it was the first thing that came to my mind! You've been working so hard to dismantle and deprecate WithProperties that proposing to backdoor it back in seemed like a joke thing to do... I do kinda like it -- with the worry that it might be confusing ("no, you have to use the one with the small 'w'; the big 'W' doesnt work anymore..."). |
I think we're all agreed that explicit is better than implicit here: a decorator that can also be used inline as in @tardyp's example above. I think we'll end up getting old and gray telling people about
or
|
I certainly agree that |
abandon this change in favor of properties.renderer |
I just merged |
This decorator was suggested by tomprince: buildbot#522 (comment) and has been modified, tested, and documented here. This commit also reorganizes some of the properties documentation, splitting that in "Customization" between the "Properties" section and the "Classes" section.
This decorator was suggested by tomprince: buildbot#522 (comment) and has been modified, tested, and documented here. This commit also reorganizes some of the properties documentation, splitting that in "Customization" between the "Properties" section and the "Classes" section.
it is a very common need for users just to want to create a
function to do the property interpolation.
one can now say:
Shell(command=lambda p:"echo next build is"+(p.getProperty("buildnumber")+1))