Skip to content

Commit

Permalink
Output YAML for the Graph __repr__.
Browse files Browse the repository at this point in the history
Closes #235.
Closes #291.
  • Loading branch information
grahamgower committed May 10, 2021
1 parent 5620c5c commit ab1ccff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 6 additions & 1 deletion demes/demes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import attr

from .load_dump import dumps as demes_dumps

Number = Union[int, float]
Name = str
Time = Number
Expand Down Expand Up @@ -1139,7 +1141,7 @@ def time_span(self):
return self.start_time - self.end_time


@attr.s(auto_attribs=True, kw_only=True, slots=True)
@attr.s(auto_attribs=True, kw_only=True, slots=True, repr=False)
class Graph:
"""
The Graph class provides a high-level API for working with a demographic
Expand Down Expand Up @@ -1211,6 +1213,9 @@ def __contains__(self, deme_name):
"""
return deme_name in self._deme_map

# Use the simplified YAML output for the console repr.
__repr__ = demes_dumps

def assert_close(
self,
other,
Expand Down
5 changes: 3 additions & 2 deletions demes/load_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ def _load_yaml_asdict(fp):

def _dump_yaml_fromdict(data, fp):
with ruamel.yaml.YAML(typ="safe", output=fp) as yaml:
# Disable JSON-style inline arrays and dicts.
yaml.default_flow_style = False
# Output flow style, but only for collections that consist only
# of scalars (i.e. the leaves in the document tree).
yaml.default_flow_style = None
# Don't emit obscure unicode, output "\Uxxxxxxxx" instead.
# Needed for string equality after round-tripping.
yaml.allow_unicode = False
Expand Down

0 comments on commit ab1ccff

Please sign in to comment.