mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Fix #2938
Get rid of the coerce_overrides() function. Add the ParseOverrides argparse.Action to parse overrides. Treat all extra settings values strictly as json values. Test overrides. Edit docs and cli help.
This commit is contained in:
parent
ab81f183c6
commit
5c178a1ccb
5 changed files with 42 additions and 60 deletions
|
|
@ -1,7 +1,6 @@
|
|||
import copy
|
||||
import importlib.util
|
||||
import inspect
|
||||
import json
|
||||
import locale
|
||||
import logging
|
||||
import os
|
||||
|
|
@ -659,25 +658,3 @@ def configure_settings(settings):
|
|||
continue # setting not specified, nothing to do
|
||||
|
||||
return settings
|
||||
|
||||
|
||||
def coerce_overrides(overrides):
|
||||
if overrides is None:
|
||||
return {}
|
||||
coerced = {}
|
||||
types_to_cast = {int, str, bool}
|
||||
for k, v in overrides.items():
|
||||
if k not in DEFAULT_CONFIG:
|
||||
logger.warning('Override for unknown setting %s, ignoring', k)
|
||||
continue
|
||||
setting_type = type(DEFAULT_CONFIG[k])
|
||||
if setting_type not in types_to_cast:
|
||||
coerced[k] = json.loads(v)
|
||||
else:
|
||||
try:
|
||||
coerced[k] = setting_type(v)
|
||||
except ValueError:
|
||||
logger.debug('ValueError for %s override with %s, try to '
|
||||
'load as json', k, v)
|
||||
coerced[k] = json.loads(v)
|
||||
return coerced
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue