Skip to content

Commit fa58f79

Browse files
committed
fix: add argparse to summary_run so -h shows help
summary_run previously consumed sys.argv[1] as the 'patch' positional without parsing, so 'summary_run -h' tried to create a directory named '-h'. Switch to argparse: help/usage work, required patch is enforced, optional job_exclusive and --verbose preserved. Closes #711
1 parent c76640a commit fa58f79

1 file changed

Lines changed: 33 additions & 15 deletions

File tree

src/shapepipe/summary_run.py

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python
22

3+
import argparse
34
import sys
45
import os
56

@@ -8,16 +9,7 @@
89
from shapepipe.utilities import summary_params_pre_v2 as summary_params
910

1011

11-
def run(*args):
12-
13-
patch = args[0]
14-
15-
if len(args) >= 2:
16-
job_exclusive = args[1]
17-
else:
18-
job_exclusive = None
19-
20-
verbose = len(args) == 3
12+
def run(patch, job_exclusive=None, verbose=False):
2113

2214
jobs, list_tile_IDs_dot = summary_params.set_jobs_v2_pre_v2(patch, verbose)
2315

@@ -73,11 +65,37 @@ def run(*args):
7365
return 0
7466

7567

76-
def main(args=None):
77-
78-
if args is None:
79-
args = sys.argv[1:] # skip script name
80-
run(*args)
68+
def parse_args(argv=None):
69+
parser = argparse.ArgumentParser(
70+
description=(
71+
'Print summary of ShapePipe job status for a given UNIONS patch.'
72+
),
73+
)
74+
parser.add_argument(
75+
'patch',
76+
help='Patch identifier (e.g. P3, P9).',
77+
)
78+
parser.add_argument(
79+
'job_exclusive',
80+
nargs='?',
81+
default=None,
82+
help=(
83+
'Bitmask selecting which jobs to run; '
84+
+ 'if omitted, all jobs run.'
85+
),
86+
)
87+
parser.add_argument(
88+
'-v',
89+
'--verbose',
90+
action='store_true',
91+
help='Verbose output.',
92+
)
93+
return parser.parse_args(argv)
94+
95+
96+
def main(argv=None):
97+
args = parse_args(argv)
98+
run(args.patch, args.job_exclusive, args.verbose)
8199

82100

83101
if __name__ == "__main__":

0 commit comments

Comments
 (0)