From 6a4367d579998e76b1632a1f041cc9daa0eba171 Mon Sep 17 00:00:00 2001 From: Daniel Reed Date: Tue, 14 May 2019 17:46:42 -0700 Subject: [PATCH] This is actually really simple, yaml/pyyaml#254 just added a new sort_keys arg. As far as I can tell, no other changes cause problems. (While I'm here, go ahead and rely on the new default default_flow_style=False.) Fixes #40. --- metabot/util/yamlutil.py | 16 +++++++--------- setup.py | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/metabot/util/yamlutil.py b/metabot/util/yamlutil.py index 267871c..da0da6b 100644 --- a/metabot/util/yamlutil.py +++ b/metabot/util/yamlutil.py @@ -22,11 +22,7 @@ def load(fname): def dump(fname, obj): """Save obj as a YAML file to fname.""" - data = yaml.dump_all([obj], - indent=4, - default_flow_style=False, - width=200, - Dumper=_SimplifyingDumper).encode('ascii') + data = yaml.dump_all([obj], indent=4, width=200, Dumper=_SimplifyingDumper).encode('ascii') with open(fname, 'wb') as fobj: fobj.write(data) return obj @@ -43,11 +39,11 @@ class _SimplifyingRepresenter(yaml.representer.SafeRepresenter): class _SimplifyingDumper(yaml.emitter.Emitter, yaml.serializer.Serializer, _SimplifyingRepresenter, yaml.resolver.Resolver): - # pylint: disable=too-many-arguments + # pylint: disable=too-many-arguments,too-many-locals def __init__(self, stream, default_style=None, - default_flow_style=None, + default_flow_style=False, canonical=None, indent=None, width=None, @@ -57,7 +53,8 @@ def __init__(self, explicit_start=None, explicit_end=None, version=None, - tags=None): + tags=None, + sort_keys=True): yaml.emitter.Emitter.__init__(self, stream, canonical=canonical, @@ -73,5 +70,6 @@ def __init__(self, tags=tags) _SimplifyingRepresenter.__init__(self, default_style=default_style, - default_flow_style=default_flow_style) + default_flow_style=default_flow_style, + sort_keys=sort_keys) yaml.resolver.Resolver.__init__(self) diff --git a/setup.py b/setup.py index f3f685c..d0da400 100644 --- a/setup.py +++ b/setup.py @@ -16,6 +16,6 @@ install_requires=[ 'ntelebot >= 0.2.0, < 0.3', 'pytz', - 'PyYAML == 3.13', + 'PyYAML >= 5.1', 'requests', ])