在 Python 2.7 中使用 Ruffus 库,just_print 标志失败
Using Ruffus library in Python 2.7, just_print flag fails
我在 Python 2.7 中有一个 ruffus 管道,但是当我用 -n
或 --just_print
调用它时,它仍然运行所有实际任务,而不仅仅是打印管道就像它应该的那样。我:
* 没有 -n
参数会取代内置参数(尽管我有其他命令行参数)
* 有一堆带有 @transform()
或 @merge()
装饰器的函数
* 使用 run_pipeline()
调用
结束管道
有没有其他人遇到过这个问题?非常感谢!
从 ruffus 2.4 版开始,您可以使用内置的 ruffus.cmdline
,它通过使用 argparse
的 cmdline.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 是必需的),您可以使用 argparse
调用 pipeline_printout()
rather than pipeline_run()
,以便 --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 2.7 中有一个 ruffus 管道,但是当我用 -n
或 --just_print
调用它时,它仍然运行所有实际任务,而不仅仅是打印管道就像它应该的那样。我:
* 没有 -n
参数会取代内置参数(尽管我有其他命令行参数)
* 有一堆带有 @transform()
或 @merge()
装饰器的函数
* 使用 run_pipeline()
调用
有没有其他人遇到过这个问题?非常感谢!
从 ruffus 2.4 版开始,您可以使用内置的 ruffus.cmdline
,它通过使用 argparse
的 cmdline.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 是必需的),您可以使用 argparse
调用 pipeline_printout()
rather than pipeline_run()
,以便 --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