allow comments and trailing commas in config files
This commit is contained in:
parent
85094a59e6
commit
2d60e4b18b
@ -1,7 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
This module contain functions to load the configuration file
|
This module contain functions to load the configuration file
|
||||||
"""
|
"""
|
||||||
import json
|
import rapidjson
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
from typing import Any, Dict
|
from typing import Any, Dict
|
||||||
@ -12,6 +12,9 @@ from freqtrade import OperationalException
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
CONFIG_PARSE_MODE = rapidjson.PM_COMMENTS | rapidjson.PM_TRAILING_COMMAS
|
||||||
|
|
||||||
|
|
||||||
def load_config_file(path: str) -> Dict[str, Any]:
|
def load_config_file(path: str) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
Loads a config file from the given path
|
Loads a config file from the given path
|
||||||
@ -21,7 +24,7 @@ def load_config_file(path: str) -> Dict[str, Any]:
|
|||||||
try:
|
try:
|
||||||
# Read config from stdin if requested in the options
|
# Read config from stdin if requested in the options
|
||||||
with open(path) if path != '-' else sys.stdin as file:
|
with open(path) if path != '-' else sys.stdin as file:
|
||||||
config = json.load(file)
|
config = rapidjson.load(file, parse_mode=CONFIG_PARSE_MODE)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
raise OperationalException(
|
raise OperationalException(
|
||||||
f'Config file "{path}" not found!'
|
f'Config file "{path}" not found!'
|
||||||
|
Loading…
Reference in New Issue
Block a user