From 44039bec3ed41506e026de9fd2c3a840b3ba01e5 Mon Sep 17 00:00:00 2001 From: Daniel Himmelstein Date: Thu, 29 Aug 2019 13:32:24 -0400 Subject: [PATCH 1/3] Refactor args.config processing --- pdoc/cli.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pdoc/cli.py b/pdoc/cli.py index 149d1117..78592d69 100755 --- a/pdoc/cli.py +++ b/pdoc/cli.py @@ -2,6 +2,7 @@ """pdoc's CLI interface and helper functions.""" import argparse +import ast import importlib import inspect import os @@ -370,12 +371,17 @@ def main(_args=None): _warn_deprecated('--overwrite', '--force') args.force = args.overwrite - try: - template_config = {opt.split('=', 1)[0]: eval(opt.split('=', 1)[1], {}) - for opt in args.config} - except Exception as e: - raise RuntimeError('Error evaluating config values {}: {}\n' - 'Make sure string values are quoted?'.format(args.config, e)) + template_config = {} + for opt in args.config: + try: + config_key, config_value = opt.split('=', 1) + config_value = ast.literal_eval(config_value) + template_config[config_key] = config_value + except Exception as e: + raise RuntimeError( + 'Error evaluating config value {!r}\n' + 'Make sure string values are quoted?'.format(opt, e) + ) if args.html_no_source: _warn_deprecated('--html-no-source', '-c show_source_code=False', True) template_config['show_source_code'] = False From 78d31523b2b2348e74af8c33e28cb0075df757f4 Mon Sep 17 00:00:00 2001 From: Daniel Himmelstein Date: Fri, 30 Aug 2019 12:57:20 -0400 Subject: [PATCH 2/3] Update RuntimeError message --- pdoc/cli.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pdoc/cli.py b/pdoc/cli.py index 78592d69..163a6dbc 100755 --- a/pdoc/cli.py +++ b/pdoc/cli.py @@ -372,15 +372,16 @@ def main(_args=None): args.force = args.overwrite template_config = {} - for opt in args.config: + for config_str in args.config: try: - config_key, config_value = opt.split('=', 1) + config_key, config_value = config_str.split('=', 1) config_value = ast.literal_eval(config_value) template_config[config_key] = config_value - except Exception as e: + except Exception as error: raise RuntimeError( - 'Error evaluating config value {!r}\n' - 'Make sure string values are quoted?'.format(opt, e) + '{} evaluating --config {}\n{}\n' + 'Make sure string values are quoted?' + .format(error.__class__.__name__, config_str, error) ) if args.html_no_source: _warn_deprecated('--html-no-source', '-c show_source_code=False', True) From 809e42f9276332d94998b68c3b4f45089cbdaf51 Mon Sep 17 00:00:00 2001 From: Kernc Date: Sun, 1 Sep 2019 17:15:45 +0200 Subject: [PATCH 3/3] update --- pdoc/cli.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pdoc/cli.py b/pdoc/cli.py index 163a6dbc..a6819da1 100755 --- a/pdoc/cli.py +++ b/pdoc/cli.py @@ -374,15 +374,16 @@ def main(_args=None): template_config = {} for config_str in args.config: try: - config_key, config_value = config_str.split('=', 1) - config_value = ast.literal_eval(config_value) - template_config[config_key] = config_value - except Exception as error: - raise RuntimeError( - '{} evaluating --config {}\n{}\n' + key, value = config_str.split('=', 1) + value = ast.literal_eval(value) + template_config[key] = value + except Exception: + raise ValueError( + 'Error evaluating --config statement "{}". ' 'Make sure string values are quoted?' - .format(error.__class__.__name__, config_str, error) + .format(config_str) ) + if args.html_no_source: _warn_deprecated('--html-no-source', '-c show_source_code=False', True) template_config['show_source_code'] = False