Source code for core.factory_decorator
"""
Decorators to attach signature information to functions
"""
import sys
[docs]def factory(f):
'''
Flag the given function `f` as an openalea factory.
'''
f.__factory__ = True
mod = sys.modules[f.__module__]
if not hasattr(mod, '__factories__'):
mod.__factories__ = [f]
else:
mod.__factories__.append(f)
return f
[docs]class outputs(inputs):
'''
Add outputs information to a function
Example:
>>> from openalea.core.factory_decorator import outputs
>>> @outputs('first:int,remainder:list')
... def fct(*args):
... return int(args[0]), args[1:]
'''
def __call__(self, f):
f.__outputs__ = self.args
return f