Skip to content

Commit

Permalink
FIX: Robustness across argparse formatting change
Browse files Browse the repository at this point in the history
  • Loading branch information
mgxd committed May 14, 2021
1 parent 7f0bcd0 commit d06ef8b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion wrapper/fmriprep_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ def check_memory(image):


def merge_help(wrapper_help, target_help):
def _get_posargs(usage):
posargs = []
for t_arg in t_usage.split('\n')[-3:]:
line = t_arg.lstrip()
if line[0].isalnum() or line[0] == "{":
posargs.append(line)
return " ".join(posargs)

# Matches all flags with up to one nested square bracket
opt_re = re.compile(r'(\[--?[\w-]+(?:[^\[\]]+(?:\[[^\[\]]+\])?)?\])')
# Matches flag name only
Expand All @@ -151,7 +159,7 @@ def merge_help(wrapper_help, target_help):
t_groups = t_details.split('\n\n')

w_posargs = w_usage.split('\n')[-1].lstrip()
t_posargs = t_usage.split('\n')[-1].lstrip()
t_posargs = _get_posargs(t_usage)

w_options = opt_re.findall(w_usage)
w_flags = sum(map(flag_re.findall, w_options), [])
Expand Down

0 comments on commit d06ef8b

Please sign in to comment.