From 47a58715546d780a5df8d362ab5eeedd3813ecdb Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Wed, 29 Jul 2020 21:32:57 -0500 Subject: Use ruamel.yaml for yaml parser --- config_file/parsers/yaml_parser.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'config_file/parsers/yaml_parser.py') diff --git a/config_file/parsers/yaml_parser.py b/config_file/parsers/yaml_parser.py index 77b59fe..1937e17 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 @@ -23,7 +18,11 @@ class YamlParser(BaseParser): "file was attempted to be used. Install the `toml` " "extra first with `pip install config-file[toml]`." ) + + 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 ) -- cgit v1.2.3 From e40a3a23fb6649758f40e9b67e3f3100ec23f116 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Thu, 30 Jul 2020 12:57:56 -0500 Subject: Fix missing dependency error messages for yaml and toml --- config_file/parsers/yaml_parser.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'config_file/parsers/yaml_parser.py') diff --git a/config_file/parsers/yaml_parser.py b/config_file/parsers/yaml_parser.py index 1937e17..babe873 100644 --- a/config_file/parsers/yaml_parser.py +++ b/config_file/parsers/yaml_parser.py @@ -14,12 +14,12 @@ 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 = YAML(typ="safe") yaml.loads = round_trip_load yaml.dumps = round_trip_dump -- cgit v1.2.3