From f87f51d208a3848e42a2645334d995033fd14d67 Mon Sep 17 00:00:00 2001 From: chriskiehl Date: Mon, 16 Feb 2015 23:41:48 -0500 Subject: [PATCH] Added exception for main functions that end with an if statement --- gooey/python_bindings/source_parser.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gooey/python_bindings/source_parser.py b/gooey/python_bindings/source_parser.py index 7acba8a..a979089 100644 --- a/gooey/python_bindings/source_parser.py +++ b/gooey/python_bindings/source_parser.py @@ -135,10 +135,15 @@ def extract_parser(modulepath): main_func = get_nodes_by_containing_attr(funcs, 'main')[0] parse_args_assignment = get_nodes_by_containing_attr(main_func.body, 'parse_args')[0] + # ast seemingly incorrectly reports the line no of ast.If objects (bug?) + # thus, if we end on an IF statement, decriment the line number by one. + final_line = main_func.body[-1] + restart_line = final_line.lineno if not isinstance(final_line, ast.If) else final_line.lineno - 1 + module_source = format_source_to_return_parser( source, cutoff_line=parse_args_assignment.lineno, - restart_line=main_func.body[-1].lineno, + restart_line=restart_line, col_offset=parse_args_assignment.col_offset, parser_name=parse_args_assignment.value.func.value.id )