Merge pull request #2121 from hroff-1902/config-allow-comments

Allow comments in config files
This commit is contained in:
Matthias
2019-08-14 06:37:33 +02:00
committed by GitHub
5 changed files with 183 additions and 14 deletions

View File

@@ -1,7 +1,7 @@
"""
This module contain functions to load the configuration file
"""
import json
import rapidjson
import logging
import sys
from typing import Any, Dict
@@ -12,6 +12,9 @@ from freqtrade import OperationalException
logger = logging.getLogger(__name__)
CONFIG_PARSE_MODE = rapidjson.PM_COMMENTS | rapidjson.PM_TRAILING_COMMAS
def load_config_file(path: str) -> Dict[str, Any]:
"""
Loads a config file from the given path
@@ -21,7 +24,7 @@ def load_config_file(path: str) -> Dict[str, Any]:
try:
# Read config from stdin if requested in the options
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:
raise OperationalException(
f'Config file "{path}" not found!'