Upgrade ruamel.yaml dependency to support version 0.18.x (#783).

This commit is contained in:
Dan Helfman 2023-11-07 10:00:13 -08:00
parent 12b75f9075
commit dcf25fa041
4 changed files with 11 additions and 10 deletions

1
NEWS
View file

@ -9,6 +9,7 @@
* #779: Only parse "--override" values as complex data types when they're for options of those * #779: Only parse "--override" values as complex data types when they're for options of those
types. types.
* #782: Fix environment variable interpolation within configured repository paths. * #782: Fix environment variable interpolation within configured repository paths.
* #783: Upgrade ruamel.yaml dependency to support version 0.18.x.
1.8.4 1.8.4
* #715: Add a monitoring hook for sending backup status to a variety of monitoring services via the * #715: Add a monitoring hook for sending backup status to a variety of monitoring services via the

View file

@ -3,7 +3,7 @@ import io
import os import os
import re import re
from ruamel import yaml import ruamel.yaml
from borgmatic.config import load, normalize from borgmatic.config import load, normalize
@ -17,7 +17,7 @@ def insert_newline_before_comment(config, field_name):
field and its comments. field and its comments.
''' '''
config.ca.items[field_name][1].insert( 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 return example
if schema_type == 'array': if schema_type == 'array':
config = yaml.comments.CommentedSeq( config = ruamel.yaml.comments.CommentedSeq(
[schema_to_sample_configuration(schema['items'], level, parent_is_sequence=True)] [schema_to_sample_configuration(schema['items'], level, parent_is_sequence=True)]
) )
add_comments_to_configuration_sequence(config, schema, indent=(level * INDENT)) add_comments_to_configuration_sequence(config, schema, indent=(level * INDENT))
elif schema_type == 'object': elif schema_type == 'object':
config = yaml.comments.CommentedMap( config = ruamel.yaml.comments.CommentedMap(
[ [
(field_name, schema_to_sample_configuration(sub_schema, level + 1)) (field_name, schema_to_sample_configuration(sub_schema, level + 1))
for field_name, sub_schema in schema['properties'].items() 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. 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) dumper.indent(mapping=INDENT, sequence=INDENT + SEQUENCE_INDENT, offset=INDENT)
rendered = io.StringIO() rendered = io.StringIO()
dumper.dump(config, rendered) 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(): for field_name, source_value in source_config.items():
# Since this key/value is from the source configuration, leave it uncommented and remove any # Since this key/value is from the source configuration, leave it uncommented and remove any
# sentinel that would cause it to get commented out. # 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. # This is a mapping. Recurse for this key/value.
if isinstance(source_value, collections.abc.Mapping): 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. # This is a sequence. Recurse for each item in it.
if isinstance(source_value, collections.abc.Sequence) and not isinstance(source_value, str): if isinstance(source_value, collections.abc.Sequence) and not isinstance(source_value, str):
destination_value = destination_config[field_name] 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( merge_source_configuration_into_destination(
destination_value[index] if index < len(destination_value) else None, 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 schema. If a source filename is provided, merge the parsed contents of that configuration into
the generated configuration. the generated configuration.
''' '''
schema = yaml.round_trip_load(open(schema_filename)) schema = ruamel.yaml.YAML(typ='safe').load(open(schema_filename))
source_config = None source_config = None
if source_filename: if source_filename:

View file

@ -33,7 +33,7 @@ setup(
'jsonschema', 'jsonschema',
'packaging', 'packaging',
'requests', 'requests',
'ruamel.yaml>0.15.0,<0.18.0', 'ruamel.yaml>0.15.0',
'setuptools', 'setuptools',
), ),
extras_require={"Apprise": ["apprise"]}, extras_require={"Apprise": ["apprise"]},

View file

@ -30,7 +30,7 @@ pytest-cov==4.0.0
PyYAML>5.0.0 PyYAML>5.0.0
regex; python_version >= '3.8' regex; python_version >= '3.8'
requests==2.31.0 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' toml==0.10.2; python_version >= '3.8'
typed-ast; python_version >= '3.8' typed-ast; python_version >= '3.8'
typing-extensions==4.5.0; python_version < '3.8' typing-extensions==4.5.0; python_version < '3.8'