I've got a ruffus pipeline in Python 2.7, but when I call it with -n
or --just_print
it still runs all the actual tasks instead of just printing the pipeline like it's supposed to. I:
* don't have a -n
argument that would supercede the built-in (although I do have other command-line arguments)
* have a bunch of functions with @transform()
or @merge()
decorators
* end the pipeline with a run_pipeline()
call
Has anyone else experienced this problem? Many thanks!
As of ruffus version 2.4, you can use the builtin ruffus.cmdline
which stores the appropriate flags via the cmdline.py
module that uses argparse
, for example:
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)
Then run your pipeline from the terminal with a command like:
python script.py --verbose 6 --target_tasks run_testFunction --just_print
If you want to do this manually instead (which is necessary for older version of ruffus) you can call pipeline_printout()
rather than pipeline_run()
, using argparse
so that the --just_print
flag leads to the appropriate call, for example:
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)
You would then run the command like:
python script.py --just_print