Skip to content

Commit 44c9606

Browse files
dhimmelkernc
authored andcommitted
REF: Refactor args.config processing (#103)
* Refactor args.config processing * Update RuntimeError message * update
1 parent 0502112 commit 44c9606

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

pdoc/cli.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""pdoc's CLI interface and helper functions."""
33

44
import argparse
5+
import ast
56
import importlib
67
import inspect
78
import os
@@ -370,12 +371,19 @@ def main(_args=None):
370371
_warn_deprecated('--overwrite', '--force')
371372
args.force = args.overwrite
372373

373-
try:
374-
template_config = {opt.split('=', 1)[0]: eval(opt.split('=', 1)[1], {})
375-
for opt in args.config}
376-
except Exception as e:
377-
raise RuntimeError('Error evaluating config values {}: {}\n'
378-
'Make sure string values are quoted?'.format(args.config, e))
374+
template_config = {}
375+
for config_str in args.config:
376+
try:
377+
key, value = config_str.split('=', 1)
378+
value = ast.literal_eval(value)
379+
template_config[key] = value
380+
except Exception:
381+
raise ValueError(
382+
'Error evaluating --config statement "{}". '
383+
'Make sure string values are quoted?'
384+
.format(config_str)
385+
)
386+
379387
if args.html_no_source:
380388
_warn_deprecated('--html-no-source', '-c show_source_code=False', True)
381389
template_config['show_source_code'] = False

0 commit comments

Comments
 (0)