函数依赖关系解析与执行
pyungo的Python项目详细描述
平果
pyungo是一个轻量级库,用于链接一组依赖项 一起工作,并以有序的方式执行它们。
pyungo是围绕Graphs和Nodes构建的,用于 DAG (有向无环图)。节点表示 使用一组已定义的输入运行并返回一个或多个 输出。Graph是Nodes的集合,其中 可以以逻辑方式流动,一个节点服务的输出 作为另一个的输入。
安装
>> pip install pyungo
简单示例
graph=Graph()@graph.register(inputs=['d','a'],outputs=['e'])deff_my_function_2(d,a):returnd-a@graph.register(inputs=['c'],outputs=['d'])deff_my_function_1(c):returnc/10.@graph.register(inputs=['a','b'],outputs=['c'])deff_my_function_3(a,b):returna+bres=graph.calculate(data={'a':2,'b':3})print(res)
pyungo正在导入时注册函数。那么 解析DAG,并找出 函数必须根据其输入/输出运行。在这个 case,它将是函数3,然后是函数1,最后是函数2。
有序的Graph与calculate一起运行,并使用给定的 数据。它返回最后一个函数的输出 运行(e),但所有中间结果也可用 在graph实例中。
结果是(a+b)/10-a=-1.5