From c74f09a3c4c3c97f09caba1e3206ab91ed4d75d3 Mon Sep 17 00:00:00 2001 From: Mathew Guest Date: Sun, 19 Jul 2020 00:34:10 -0600 Subject: [PATCH] two small fixes: bugfix with older python and error ran into with a user program --- app_skellington/cli.py | 20 +++++++++++++++++--- app_skellington/log.py | 7 +++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app_skellington/cli.py b/app_skellington/cli.py index f1e4175..8b5be8a 100644 --- a/app_skellington/cli.py +++ b/app_skellington/cli.py @@ -80,11 +80,25 @@ class CommandTree: Creates a root-level submenu with no entries. SubMenu node is returned which can have submenus and commands attached to it. """ + # NOTE(MG) Fix below strategizes whether to pass in 'required' + # paremter to ArgumentParser.add_subparsers() + # which was added in in Python3.7. + func_args = { + 'dest': param_name, + 'metavar': param_name, + 'required': is_required + } + if ( + sys.version_info.major == 3 + and sys.version_info.minor <= 6 + ): + if is_required: + _bootstrap_logger.warn('Unable to enforce required submenu: Requires >= Python 3.7') + del func_args[required] + # Creates an argument as a slot in the underlying argparse. subparsers = self.root_parser.add_subparsers( - dest = param_name, - metavar = param_name, - required = is_required + **func_args ) submenu = SubMenu(self, subparsers, param_name) diff --git a/app_skellington/log.py b/app_skellington/log.py index 67a4033..ae4a3b2 100644 --- a/app_skellington/log.py +++ b/app_skellington/log.py @@ -108,8 +108,11 @@ class LoggingLayer: # Replace 'root' logger with '', logging module convention for root handler # Note: '' is disallowed in ConfigObj (hence the reason for this replacement) - config_dict['loggers'][''] = config_dict['loggers']['root'] - del config_dict['loggers']['root'] + try: + config_dict['loggers'][''] = config_dict['loggers']['root'] + del config_dict['loggers']['root'] + except Exception as ex: + _bootstrap.logger.warn('internal failure patching root logger') # Evaluate the full filepath of the file handler