From c389fcbd0ad897f550ffdb7f59f4f8bfa6b642d8 Mon Sep 17 00:00:00 2001 From: Ralphie Raccoon Date: Mon, 24 Jan 2022 19:03:26 +0000 Subject: [PATCH] Added --force option to force rerun a named list of sessions. --- pythontex/pythontex2.py | 9 ++++++++- pythontex/pythontex3.py | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/pythontex/pythontex2.py b/pythontex/pythontex2.py index 661ef37..79ce50a 100644 --- a/pythontex/pythontex2.py +++ b/pythontex/pythontex2.py @@ -162,6 +162,10 @@ def process_argv(data, temp_data): parser.add_argument('-v', '--verbose', default=False, action='store_true', help='verbose output') parser.add_argument('--interpreter', default=None, help='set a custom interpreter; argument should be in the form ":, :, ..." where is "python", "ruby", etc., and is the command for invoking the interpreter; argument may also be in the form of a Python dictionary') + parser.add_argument('--force', default=None, + metavar='::;[::;...]', + type=lambda s: [i for i in s.split(';')], + help='force listed session(s) to be rerun, regardless of rerun option condition') group_debug = parser.add_mutually_exclusive_group() group_debug.add_argument('--debug', nargs='?', default=None, const='default', @@ -201,6 +205,7 @@ def process_argv(data, temp_data): temp_data['verbose'] = args.verbose temp_data['debug'] = args.debug temp_data['interactive'] = args.interactive + temp_data['force'] = args.force # Update interpreter_dict based on interpreter set_python_interpreter = False if args.interpreter is not None: @@ -677,7 +682,9 @@ def modified_dependencies(key, data, old_data, temp_data): def should_rerun(hash, old_hash, old_exit_status, key, rerun, data, old_data, temp_data): # #### Need to clean up arg passing here - if rerun == 'never': + if temp_data['force'] is not None and key.replace('#', ':') in temp_data['force']: + return True # Don't check rerun if session has been forced to rerun + elif rerun == 'never': if (hash != old_hash or modified_dependencies(key, data, old_data, temp_data)): print('* PythonTeX warning') print(' Session ' + key.replace('#', ':') + ' has rerun=never') diff --git a/pythontex/pythontex3.py b/pythontex/pythontex3.py index 488c234..e1002e7 100644 --- a/pythontex/pythontex3.py +++ b/pythontex/pythontex3.py @@ -162,6 +162,10 @@ def process_argv(data, temp_data): parser.add_argument('-v', '--verbose', default=False, action='store_true', help='verbose output') parser.add_argument('--interpreter', default=None, help='set a custom interpreter; argument should be in the form ":, :, ..." where is "python", "ruby", etc., and is the command for invoking the interpreter; argument may also be in the form of a Python dictionary') + parser.add_argument('--force', default=None, + type=lambda s: [i for i in s.split(';')], + metavar='::;[::;...]', + help='force listed session(s) to be rerun, regardless of rerun option condition') group_debug = parser.add_mutually_exclusive_group() group_debug.add_argument('--debug', nargs='?', default=None, const='default', @@ -201,6 +205,7 @@ def process_argv(data, temp_data): temp_data['verbose'] = args.verbose temp_data['debug'] = args.debug temp_data['interactive'] = args.interactive + temp_data['force'] = args.force # Update interpreter_dict based on interpreter set_python_interpreter = False if args.interpreter is not None: @@ -677,7 +682,9 @@ def modified_dependencies(key, data, old_data, temp_data): def should_rerun(hash, old_hash, old_exit_status, key, rerun, data, old_data, temp_data): # #### Need to clean up arg passing here - if rerun == 'never': + if temp_data['force'] is not None and key.replace('#', ':') in temp_data['force']: + return True # Don't check rerun if session has been forced to rerun + elif rerun == 'never': if (hash != old_hash or modified_dependencies(key, data, old_data, temp_data)): print('* PythonTeX warning') print(' Session ' + key.replace('#', ':') + ' has rerun=never')