diff options
Diffstat (limited to 'xnt/__init__.py')
-rw-r--r-- | xnt/__init__.py | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/xnt/__init__.py b/xnt/__init__.py index 61de895..507041f 100644 --- a/xnt/__init__.py +++ b/xnt/__init__.py @@ -55,15 +55,24 @@ from xnt.tasks import setup from xnt.tasks import which from xnt.tasks import in_path -def target(target_fn): +def target(*args, **kwargs): """Decorator function for marking a method in build file as a "target" method, or a method meant to be invoked from Xnt """ - def wrap(): - """Inner wrapper function for decorator""" - print(target_fn.__name__ + ":") - return target_fn() - wrap.decorator = "target" - wrap.__doc__ = target_fn.__doc__ - return wrap + def w_target(target_fn): + """target wrapping function""" + has_run = [False,] + def wrap(): + """Inner wrapper function for decorator""" + if not has_run[0] or kwargs.get('always_run', False): + has_run[0] = True + print(target_fn.__name__ + ":") + return target_fn() + return None + wrap.decorator = "target" + wrap.__doc__ = target_fn.__doc__ + return wrap + if len(args) == 1 and callable(args[0]): + return w_target(args[0]) + return w_target |