From dcf25fa0418b9a458f5a25ef15911130d6c6a15b Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Tue, 7 Nov 2023 10:00:13 -0800 Subject: [PATCH] Upgrade ruamel.yaml dependency to support version 0.18.x (#783). --- NEWS | 1 + borgmatic/config/generate.py | 16 ++++++++-------- setup.py | 2 +- test_requirements.txt | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/NEWS b/NEWS index 149bb12..68c49f9 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,7 @@ * #779: Only parse "--override" values as complex data types when they're for options of those types. * #782: Fix environment variable interpolation within configured repository paths. + * #783: Upgrade ruamel.yaml dependency to support version 0.18.x. 1.8.4 * #715: Add a monitoring hook for sending backup status to a variety of monitoring services via the diff --git a/borgmatic/config/generate.py b/borgmatic/config/generate.py index 0109654..3f7a5ef 100644 --- a/borgmatic/config/generate.py +++ b/borgmatic/config/generate.py @@ -3,7 +3,7 @@ import io import os import re -from ruamel import yaml +import ruamel.yaml from borgmatic.config import load, normalize @@ -17,7 +17,7 @@ def insert_newline_before_comment(config, field_name): field and its comments. ''' config.ca.items[field_name][1].insert( - 0, yaml.tokens.CommentToken('\n', yaml.error.CommentMark(0), None) + 0, ruamel.yaml.tokens.CommentToken('\n', ruamel.yaml.error.CommentMark(0), None) ) @@ -32,12 +32,12 @@ def schema_to_sample_configuration(schema, level=0, parent_is_sequence=False): return example if schema_type == 'array': - config = yaml.comments.CommentedSeq( + config = ruamel.yaml.comments.CommentedSeq( [schema_to_sample_configuration(schema['items'], level, parent_is_sequence=True)] ) add_comments_to_configuration_sequence(config, schema, indent=(level * INDENT)) elif schema_type == 'object': - config = yaml.comments.CommentedMap( + config = ruamel.yaml.comments.CommentedMap( [ (field_name, schema_to_sample_configuration(sub_schema, level + 1)) for field_name, sub_schema in schema['properties'].items() @@ -101,7 +101,7 @@ def render_configuration(config): ''' Given a config data structure of nested OrderedDicts, render the config as YAML and return it. ''' - dumper = yaml.YAML() + dumper = ruamel.yaml.YAML(typ='rt') dumper.indent(mapping=INDENT, sequence=INDENT + SEQUENCE_INDENT, offset=INDENT) rendered = io.StringIO() dumper.dump(config, rendered) @@ -236,7 +236,7 @@ def merge_source_configuration_into_destination(destination_config, source_confi for field_name, source_value in source_config.items(): # Since this key/value is from the source configuration, leave it uncommented and remove any # sentinel that would cause it to get commented out. - remove_commented_out_sentinel(destination_config, field_name) + remove_commented_out_sentinel(ruamel.yaml.comments.CommentedMap(destination_config), field_name) # This is a mapping. Recurse for this key/value. if isinstance(source_value, collections.abc.Mapping): @@ -248,7 +248,7 @@ def merge_source_configuration_into_destination(destination_config, source_confi # This is a sequence. Recurse for each item in it. if isinstance(source_value, collections.abc.Sequence) and not isinstance(source_value, str): destination_value = destination_config[field_name] - destination_config[field_name] = yaml.comments.CommentedSeq( + destination_config[field_name] = ruamel.yaml.comments.CommentedSeq( [ merge_source_configuration_into_destination( destination_value[index] if index < len(destination_value) else None, @@ -275,7 +275,7 @@ def generate_sample_configuration( schema. If a source filename is provided, merge the parsed contents of that configuration into the generated configuration. ''' - schema = yaml.round_trip_load(open(schema_filename)) + schema = ruamel.yaml.YAML(typ='safe').load(open(schema_filename)) source_config = None if source_filename: diff --git a/setup.py b/setup.py index 8e5e0ee..5655c44 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ setup( 'jsonschema', 'packaging', 'requests', - 'ruamel.yaml>0.15.0,<0.18.0', + 'ruamel.yaml>0.15.0', 'setuptools', ), extras_require={"Apprise": ["apprise"]}, diff --git a/test_requirements.txt b/test_requirements.txt index f886ff3..36a09cf 100644 --- a/test_requirements.txt +++ b/test_requirements.txt @@ -30,7 +30,7 @@ pytest-cov==4.0.0 PyYAML>5.0.0 regex; python_version >= '3.8' requests==2.31.0 -ruamel.yaml>0.15.0,<0.18.0 +ruamel.yaml>0.15.0 toml==0.10.2; python_version >= '3.8' typed-ast; python_version >= '3.8' typing-extensions==4.5.0; python_version < '3.8'