From 88cdb867368e93ec59740fa1b5a1440d2f438d05 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Thu, 21 Feb 2019 00:43:13 +0100 Subject: test_task: check and display argparser help before loading the task MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before --help was weirldy broken, apparently due to some bytes/str issue in the Python 2→3 conversion. Parameters are printed anyway after loading a task without -q. --- kpov_judge/test_task.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'kpov_judge') diff --git a/kpov_judge/test_task.py b/kpov_judge/test_task.py index a1f3608..ad8c963 100755 --- a/kpov_judge/test_task.py +++ b/kpov_judge/test_task.py @@ -114,15 +114,15 @@ def load_params(filename): if __name__ == '__main__': # get the parameters needed to get to the task, such as the URLs, the name of the task and optionally an ID from the student # start with the the parameters needed for the dialog gui to work - argparser = argparse.ArgumentParser(conflict_handler='resolve', add_help=False, - description='Get task parameters') + argparser = argparse.ArgumentParser(conflict_handler='resolve', + description='Test a KPOV Judge task.') argparser.add_argument('-h', '--help', action='store_true') argparser.add_argument('-q', '--quiet', action='store_true', help='disable prompts') argparser.add_argument('-g', '--generate_params', action='store_true', help='generate initial values for the task parameters') argparser.add_argument('-pf', '--params_file', nargs='?', default=PARAMS_FILE, - help='a local file containing saved param values') + help='a local file with saved param values') basic_args, unknown_args = argparser.parse_known_args() # get default parameters including language @@ -133,6 +133,10 @@ if __name__ == '__main__': basic_args, unknown_args = argparser.parse_known_args() params['language'] = basic_args.language + if basic_args.help: + argparser.print_help() + exit(0) + # continue with the parameters needed to get the task params = locate_task(params, argparser, quiet=basic_args.quiet) # TODO: if the task name is missing or invalid, try to get a list of tasks @@ -205,9 +209,6 @@ if __name__ == '__main__': task_params[k] = args[k] if not basic_args.quiet: task_params = get_params(task_params, task_params_meta, language=params['language']) - if basic_args.help: - print(task_argparser.format_help()) - exit(0) public_params = {} for k in inspect.getargs(task.__code__)[0]: -- cgit v1.2.1