gpt4 book ai didi

python - 在 Python 2.7 中使用 Ruffus 库,just_print 标志失败

转载 作者:太空宇宙 更新时间:2023-11-04 05:16:01 25 4
gpt4 key购买 nike

我在 Python 2.7 中有一个 ruffus 管道,但是当我用 -n--just_print 调用它时,它仍然运行所有实际任务,而不仅仅是像预期的那样打印管道。我:
* 没有 -n 参数会取代内置参数(尽管我有其他命令行参数)
* 有一堆带有 @transform()@merge() 装饰器的函数
* 使用 run_pipeline() 调用结束管道

有没有人遇到过这个问题?非常感谢!

最佳答案

从 ruffus 2.4 版开始,您可以使用内置的 ruffus.cmdline它通过使用 argparsecmdline.py 模块存储适当的标志,例如:

from ruffus import *
parser = cmdline.get_argparse(description='Example pipeline')
options = parser.parse_args()

@originate("test_out.txt")
def run_testFunction(output):
with open(output,"w") as f:
f.write("it's working!\n")

cmdline.run(options)

然后使用如下命令从终端运行您的管道:

python script.py --verbose 6 --target_tasks run_testFunction --just_print

如果您想手动执行此操作(这对于旧版本的 ruffus 是必需的),您可以调用 pipeline_printout()而不是 pipeline_run() ,使用 argparse 以便 --just_print 标志导致适当的调用,例如:

from ruffus import *
import argparse
import sys

parser = argparse.ArgumentParser(description='Example pipeline')
parser.add_argument('--just_print', dest='feature', action='store_true')
parser.set_defaults(feature=False)
args = parser.parse_args()

@originate("test_out.txt")
def run_testFunction(output):
with open(output,"w") as f:
f.write("it's working!\n")

if args.feature:
pipeline_printout(sys.stdout, run_testFunction, verbose = 6)
else:
pipeline_run(run_testFunction, verbose = 6)

然后您将运行如下命令:

python script.py --just_print

关于python - 在 Python 2.7 中使用 Ruffus 库,just_print 标志失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41683560/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com