use libyaml-based loader

factor 10 faster on my laptop
This commit is contained in:
Martin Diehl 2022-04-30 19:44:50 +02:00
parent 07b95a3dec
commit 8168d43553
1 changed files with 6 additions and 2 deletions

View File

@ -6,6 +6,10 @@ from typing import Union, Dict, Any, Type, TypeVar
import numpy as np import numpy as np
import yaml import yaml
try:
from yaml import CSafeLoader as SafeLoader
except ImportError:
from yaml import SafeLoader
from ._typehints import FileHandle from ._typehints import FileHandle
from . import Rotation from . import Rotation
@ -53,7 +57,7 @@ class Config(dict):
**kwargs): **kwargs):
"""Initialize from YAML, dict, or key=value pairs.""" """Initialize from YAML, dict, or key=value pairs."""
if isinstance(yml,str): if isinstance(yml,str):
kwargs.update(yaml.safe_load(yml)) kwargs.update(yaml.load(yml, Loader=SafeLoader))
elif isinstance(yml,dict): elif isinstance(yml,dict):
kwargs.update(yml) kwargs.update(yml)
@ -144,7 +148,7 @@ class Config(dict):
Configuration from file. Configuration from file.
""" """
return cls(yaml.safe_load(util.open_text(fname))) return cls(yaml.load(util.open_text(fname), Loader=SafeLoader))
def save(self, def save(self,
fname: FileHandle, fname: FileHandle,