mirror of https://github.com/coqui-ai/TTS.git
read_json_with_comments
This commit is contained in:
parent
563bc921d8
commit
ea39715305
|
@ -20,6 +20,16 @@ class AttrDict(dict):
|
||||||
self.__dict__ = self
|
self.__dict__ = self
|
||||||
|
|
||||||
|
|
||||||
|
def read_json_with_comments(json_path):
|
||||||
|
# fallback to json
|
||||||
|
with open(json_path, "r") as f:
|
||||||
|
input_str = f.read()
|
||||||
|
# handle comments
|
||||||
|
input_str = re.sub(r'\\\n', '', input_str)
|
||||||
|
input_str = re.sub(r'//.*\n', '\n', input_str)
|
||||||
|
data = json.loads(input_str)
|
||||||
|
return data
|
||||||
|
|
||||||
def load_config(config_path: str) -> AttrDict:
|
def load_config(config_path: str) -> AttrDict:
|
||||||
"""Load config files and discard comments
|
"""Load config files and discard comments
|
||||||
|
|
||||||
|
@ -33,14 +43,7 @@ def load_config(config_path: str) -> AttrDict:
|
||||||
with open(config_path, "r") as f:
|
with open(config_path, "r") as f:
|
||||||
data = yaml.safe_load(f)
|
data = yaml.safe_load(f)
|
||||||
else:
|
else:
|
||||||
# fallback to json
|
data = read_json_with_comments(config_path)
|
||||||
with open(config_path, "r") as f:
|
|
||||||
input_str = f.read()
|
|
||||||
# handle comments
|
|
||||||
input_str = re.sub(r'\\\n', '', input_str)
|
|
||||||
input_str = re.sub(r'//.*\n', '\n', input_str)
|
|
||||||
data = json.loads(input_str)
|
|
||||||
|
|
||||||
config.update(data)
|
config.update(data)
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue