Skip to content

Commit

Permalink
This is actually really simple, yaml/pyyaml#254 just added a new sort…
Browse files Browse the repository at this point in the history
…_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.
  • Loading branch information
nmlorg committed May 15, 2019
1 parent 8da60c2 commit 6a4367d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
16 changes: 7 additions & 9 deletions metabot/util/yamlutil.py
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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)
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -16,6 +16,6 @@
install_requires=[
'ntelebot >= 0.2.0, < 0.3',
'pytz',
'PyYAML == 3.13',
'PyYAML >= 5.1',
'requests',
])

0 comments on commit 6a4367d

Please sign in to comment.