mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 05:11:16 +00:00
Bug 1287023
- Allow to use delayed_getattr in more cases. r=chmanchester
Until now, it's not been possible to do something as straightforward as: option('--foo', default=delayed_getattr(milestone, 'is_nightly')) The reason is that option's default needs what it's given, if it's a @depends function, to depend on --help. But we can't have every delayed_getattr add dependencies on --help, because that would make unwanted things to depend on --help and run when displaying the help. Until we can totally remove --help dependencies, this change makes the resulting @depends function created by delayed_getattr depend on --help if the @depends function it's given already depends on --help.
This commit is contained in:
parent
31cd6cfe1f
commit
fa43fb4a81
@ -137,14 +137,21 @@ def namespace(**kwargs):
|
||||
# return namespace(foo=value)
|
||||
# set_config('FOO', delayed_getattr(option, 'foo')
|
||||
@template
|
||||
@imports('__sandbox__')
|
||||
def delayed_getattr(func, key):
|
||||
@depends(func)
|
||||
def result(value):
|
||||
_, deps = __sandbox__._depends.get(func, (None, ()))
|
||||
|
||||
def result(value, _=None):
|
||||
# The @depends function we're being passed may have returned
|
||||
# None, or an object that simply doesn't have the wanted key.
|
||||
# In that case, just return None.
|
||||
return getattr(value, key, None)
|
||||
return result
|
||||
|
||||
# Automatically add a dependency on --help when the given @depends
|
||||
# function itself depends on --help.
|
||||
if __sandbox__._help_option in deps:
|
||||
return depends(func, '--help')(result)
|
||||
return depends(func)(result)
|
||||
|
||||
|
||||
# Like @depends, but the decorated function is only called if one of the
|
||||
|
Loading…
Reference in New Issue
Block a user