From ba2b501022fd0975389cd49f0cbc1e2e2b04b272 Mon Sep 17 00:00:00 2001 From: Vince Date: Wed, 19 Jun 2019 23:27:28 -0400 Subject: [PATCH] first pass at print-only behavior for PM; #4 --- pypiper/manager.py | 20 +++++++++++++------- pypiper/utils.py | 11 +++++++++-- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/pypiper/manager.py b/pypiper/manager.py index 25be0109..414519e1 100644 --- a/pypiper/manager.py +++ b/pypiper/manager.py @@ -124,7 +124,9 @@ def __init__( 'config_file': config_file, 'output_parent': output_parent, 'cores': cores, - 'mem': mem} + 'mem': mem, + 'testmode': False + } # Transform the command-line namespace into a Mapping. args_dict = vars(args) if args else dict() @@ -168,6 +170,7 @@ def __init__( self.dirty = params['dirty'] self.cores = params['cores'] self.output_parent = params['output_parent'] + self.testmode = params['testmode'] # Keep track of an ID for the number of processes attempted self.proc_count = 0 @@ -794,9 +797,12 @@ def checkprint(self, cmd, shell=None, nofail=False): :param bool nofail: Should the pipeline bail on a nonzero return from a process? Default: False Nofail can be used to implement non-essential parts of the pipeline; if these processes fail, they will not cause the pipeline to bail out. + :return str: text output by the executed subprocess (check_output) """ self._report_command(cmd) + if self.testmode: + return "" likely_shell = check_shell(cmd, shell) @@ -874,10 +880,6 @@ def get_mem_child_sum(proc): def display_memory(memval): return None if memval < 0 else "{}GB".format(round(memval, 3)) - def make_dict(command): - a, s = (command, True) if check_shell(command, shell) else (shlex.split(command), False) - return dict(args=a, stdout=subprocess.PIPE, shell=s) - def make_hash(o): """ Convert the object to string and hash it, return None in case of failure @@ -893,6 +895,10 @@ def make_hash(o): if container: cmd = "docker exec " + container + " " + cmd + if self.testmode: + self._report_command(cmd) + return 0, 0 + param_list = parse_cmd(cmd, shell) proc_name = get_proc_name(cmd) @@ -929,7 +935,7 @@ def make_hash(o): print("") ids = [x.pid for x in processes] print ("Not waiting for subprocesses: " + str(ids)) - return [0, -1] + return 0, -1 def proc_wrapup(i): """ @@ -1307,7 +1313,7 @@ def _report_command(self, cmd, procs=None): :param str | list[str] procs: process numbers for processes in the command """ if isinstance(procs, list): - procs = ",".join(map(str,procs)) + procs = ",".join(map(str, procs)) if procs: line = "\n> `{cmd}` ({procs})\n".format(cmd=str(cmd), procs=procs) else: diff --git a/pypiper/utils.py b/pypiper/utils.py index 4a4397d8..6e4a912e 100644 --- a/pypiper/utils.py +++ b/pypiper/utils.py @@ -222,6 +222,7 @@ def check_shell_asterisk(cmd): """ return r"*" in cmd + def split_by_pipes_nonnested(cmd): """ Split the command by shell pipes, but preserve contents in @@ -235,8 +236,10 @@ def split_by_pipes_nonnested(cmd): r = re.compile(r'(?:[^|(]|\([^)]*\)+|\{[^}]*\})') return r.findall(cmd) + # cmd="a | b | { c | d } ABC | { x | y } hello '( () e |f )" + def split_by_pipes(cmd): """ Split the command by shell pipes, but preserve contents in @@ -303,6 +306,7 @@ def strip_braced_txt(cmd): return cmd + def check_shell_redirection(cmd): """ Determine whether a command appears to contain shell redirection symbol outside of curly brackets @@ -399,7 +403,7 @@ def get_first_value(param, param_pools, on_missing=None, error=True): if param in pool: return pool[param] - # Raise error if unfound and no strategy or value is provided or handling + # Raise error if not found and no strategy or value is provided or handling # unmapped parameter requests. if error and on_missing is None: raise KeyError("Unmapped parameter: '{}'".format(param)) @@ -691,7 +695,7 @@ def _determine_args(argument_groups, arguments, use_all_args=False): # Define the argument groups. args_by_group = { - "pypiper": ["recover", "new-start", "dirty", "force-follow"], + "pypiper": ["recover", "new-start", "dirty", "force-follow", "testmode"], "config": ["config"], "checkpoint": ["stop-before", "stop-after"], "resource": ["mem", "cores"], @@ -763,6 +767,9 @@ def _add_args(parser, args, required): # Define the arguments. argument_data = { + "testmode": + ("-T", {"action": "store_true", + "help": "Only print commands, don't run"}), "recover": ("-R", {"action": "store_true", "help": "Overwrite locks to recover from previous failed run"}),