aboutsummaryrefslogtreecommitdiffstats
path: root/config_file/parsers/yaml_parser.py
diff options
context:
space:
mode:
Diffstat (limited to 'config_file/parsers/yaml_parser.py')
-rw-r--r--config_file/parsers/yaml_parser.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/config_file/parsers/yaml_parser.py b/config_file/parsers/yaml_parser.py
index 77b59fe..babe873 100644
--- a/config_file/parsers/yaml_parser.py
+++ b/config_file/parsers/yaml_parser.py
@@ -1,12 +1,7 @@
try:
- import yaml
+ from ruamel.yaml import YAML, YAMLError, round_trip_dump, round_trip_load
YAML_AVAILABLE = True
-
- # Conform yaml to json and
- # toml package syntax
- yaml.loads = yaml.load
- yaml.dumps = yaml.dump
except ImportError:
YAML_AVAILABLE = False
@@ -19,11 +14,15 @@ class YamlParser(BaseParser):
def __init__(self, file_contents: str):
if not YAML_AVAILABLE:
raise MissingDependencyError(
- "It doesn't appear `PyYaml` is installed, but a yaml "
- "file was attempted to be used. Install the `toml` "
- "extra first with `pip install config-file[toml]`."
+ "It doesn't appear `ruamel.yaml` is installed, but a yaml "
+ "file was attempted to be used. Install the `yaml` "
+ "extra first with `pip install config-file[yaml]`."
)
+ yaml = YAML(typ="safe")
+ yaml.loads = round_trip_load
+ yaml.dumps = round_trip_dump
+
super().__init__(
- file_contents=file_contents, module=yaml, decode_error=yaml.YAMLError
+ file_contents=file_contents, module=yaml, decode_error=YAMLError
)