diff options
author | Anthon van der Neut <anthon@mnt.org> | 2018-08-13 11:15:32 +0200 |
---|---|---|
committer | Anthon van der Neut <anthon@mnt.org> | 2018-08-13 11:15:32 +0200 |
commit | c6c7a98673690f6c46c80c88ba2909b7721fd40a (patch) | |
tree | 678b61ea38d89e4c5f9165586366fbce9a4bedde | |
parent | b49a56399b1086eabf0abb9d86297188db108c19 (diff) | |
download | ruamel.yaml-c6c7a98673690f6c46c80c88ba2909b7721fd40a.tar.gz |
fix issue 102 now also for empty mappings with comments0.15.54
*When this change indeed resolves your problem, please **Close** this issue*.
*(You can do so usingthe WorkFlow pull-down (close to the top right of this page)*
-rw-r--r-- | CHANGES | 10 | ||||
-rw-r--r-- | README.rst | 14 | ||||
-rw-r--r-- | __init__.py | 4 | ||||
-rw-r--r-- | _doc/_static/pypi.svg | 2 | ||||
-rw-r--r-- | _test/test_comments.py | 2 | ||||
-rw-r--r-- | _test/test_issues.py | 8 | ||||
-rw-r--r-- | emitter.py | 8 | ||||
-rw-r--r-- | main.py | 10 | ||||
-rw-r--r-- | scanner.py | 20 |
9 files changed, 43 insertions, 35 deletions
@@ -1,3 +1,13 @@ +[0, 15, 54]: 2018-08-13 + + - fix issue where a comment could pop-up twice in the output (reported by + `Mike Kazantsev <https://bitbucket.org/mk_fg/>`__ and by + `Nate Peterson <https://bitbucket.org/ndpete21/>`__) + - fix issue where JSON object (mapping) without spaces was not parsed + properly (reported by `Marc Schmidt <https://bitbucket.org/marcj/>`__) + - fix issue where comments after empty flow-style mappings were not emitted + (reported by `Qinfench Chen <https://bitbucket.org/flyin5ish/>`__) + [0, 15, 53]: 2018-08-12 - fix issue with flow style mapping with comments gobbled newline (reported by `Christopher Lambert <https://bitbucket.org/XN137/>`__) @@ -4,8 +4,8 @@ ruamel.yaml ``ruamel.yaml`` is a YAML 1.2 loader/dumper package for Python. -:version: 0.15.53 -:updated: 2018-08-12 +:version: 0.15.54 +:updated: 2018-08-13 :documentation: http://yaml.readthedocs.io :repository: https://bitbucket.org/ruamel/ :pypi: https://pypi.org/project/ruamel.yaml/ @@ -54,6 +54,16 @@ ChangeLog .. should insert NEXT: at the beginning of line for next key (with empty line) +0.15.54 (2018-08-13): + + - fix issue where a comment could pop-up twice in the output (reported by + `Mike Kazantsev <https://bitbucket.org/mk_fg/>`__ and by + `Nate Peterson <https://bitbucket.org/ndpete21/>`__) + - fix issue where JSON object (mapping) without spaces was not parsed + properly (reported by `Marc Schmidt <https://bitbucket.org/marcj/>`__) + - fix issue where comments after empty flow-style mappings were not emitted + (reported by `Qinfench Chen <https://bitbucket.org/flyin5ish/>`__) + 0.15.53 (2018-08-12): - fix issue with flow style mapping with comments gobbled newline (reported by `Christopher Lambert <https://bitbucket.org/XN137/>`__) diff --git a/__init__.py b/__init__.py index 1af5ab8..cfddf1b 100644 --- a/__init__.py +++ b/__init__.py @@ -7,8 +7,8 @@ if False: # MYPY _package_data = dict( full_package_name='ruamel.yaml', - version_info=(0, 15, 53), - __version__='0.15.53', + version_info=(0, 15, 54), + __version__='0.15.54', author='Anthon van der Neut', author_email='a.van.der.neut@ruamel.eu', description='ruamel.yaml is a YAML parser/emitter that supports roundtrip preservation of comments, seq/map flow style, and map key order', # NOQA diff --git a/_doc/_static/pypi.svg b/_doc/_static/pypi.svg index b218d84..369335f 100644 --- a/_doc/_static/pypi.svg +++ b/_doc/_static/pypi.svg @@ -1 +1 @@ -<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="86" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="a"><rect width="86" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#a)"><path fill="#555" d="M0 0h33v20H0z"/><path fill="#007ec6" d="M33 0h53v20H33z"/><path fill="url(#b)" d="M0 0h86v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110"> <text x="175" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="230">pypi</text><text x="175" y="140" transform="scale(.1)" textLength="230">pypi</text><text x="585" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="430">0.15.53</text><text x="585" y="140" transform="scale(.1)" textLength="430">0.15.53</text></g> </svg> +<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="86" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="a"><rect width="86" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#a)"><path fill="#555" d="M0 0h33v20H0z"/><path fill="#007ec6" d="M33 0h53v20H33z"/><path fill="url(#b)" d="M0 0h86v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110"> <text x="175" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="230">pypi</text><text x="175" y="140" transform="scale(.1)" textLength="230">pypi</text><text x="585" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="430">0.15.54</text><text x="585" y="140" transform="scale(.1)" textLength="430">0.15.54</text></g> </svg> diff --git a/_test/test_comments.py b/_test/test_comments.py index bb08f7e..a5e4ee0 100644 --- a/_test/test_comments.py +++ b/_test/test_comments.py @@ -59,7 +59,7 @@ class TestComments: # comment scalar ... - """, "scalar\n...\n") + """, 'scalar\n...\n') def test_main_mapping_begin_end(self): round_trip(""" diff --git a/_test/test_issues.py b/_test/test_issues.py index fb11322..d2ea460 100644 --- a/_test/test_issues.py +++ b/_test/test_issues.py @@ -34,7 +34,7 @@ class TestIssues: var4: {a: 1} #filled object var5: [] #empty array """) - x = round_trip(s, preserve_quotes=True) # NOQA + x = round_trip(yaml_str, preserve_quotes=True) # NOQA def test_issue_160(self): s = dedent("""\ @@ -85,7 +85,5 @@ class TestIssues: json_str2 = '{"abc":[{"a":"1", "uses":0}]}' def test_issue_172(self): - x = round_trip_load(TestIssues.json_str2) - x = round_trip_load(TestIssues.json_str) - - + x = round_trip_load(TestIssues.json_str2) # NOQA + x = round_trip_load(TestIssues.json_str) # NOQA @@ -507,9 +507,9 @@ class Emitter(object): self.indent = self.indents.pop() self.flow_level -= 1 self.write_indicator(u'}', False) - # if self.event.comment and self.event.comment[0]: - # # eol comment on flow sequence - # self.write_post_comment(self.event) + if self.event.comment and self.event.comment[0]: + # eol comment on empty mapping + self.write_post_comment(self.event) self.state = self.states.pop() else: if self.canonical or self.column > self.best_width: @@ -534,7 +534,7 @@ class Emitter(object): self.write_indent() self.write_indicator(u'}', False) if self.event.comment and self.event.comment[0]: - # eol comment on flow mapping + # eol comment on flow mapping, never reached on empty mappings self.write_post_comment(self.event) self.state = self.states.pop() else: @@ -640,7 +640,7 @@ class YAML(object): return cls def parse(self, stream): - # type: (StreamTextType, Any) -> Any + # type: (StreamTextType) -> Any """ Parse a YAML stream and produce parsing events. """ @@ -920,11 +920,11 @@ def load(stream, Loader=None, version=None, preserve_quotes=None): finally: loader._parser.dispose() try: - loader._reader.reset_reader() # type: ignore + loader._reader.reset_reader() except AttributeError: pass try: - loader._scanner.reset_scanner() # type: ignore + loader._scanner.reset_scanner() except AttributeError: pass @@ -945,11 +945,11 @@ def load_all(stream, Loader=None, version=None, preserve_quotes=None): finally: loader._parser.dispose() try: - loader._reader.reset_reader() # type: ignore + loader._reader.reset_reader() except AttributeError: pass try: - loader._scanner.reset_scanner() # type: ignore + loader._scanner.reset_scanner() except AttributeError: pass @@ -84,23 +84,17 @@ class Scanner(object): @property def flow_level(self): + # type: () -> int return len(self.flow_context) - # @flow_level.setter - # def flow_level(self): - # self.flow_context = [] - def reset_scanner(self): # type: () -> None # Had we reached the end of the stream? self.done = False # flow_context is an expanding/shrinking list consisting of '{' and '[' - # in general len(flow_context) == flow_level - self.flow_context = [] - # The number of unclosed '{' and '['. `flow_level == 0` means block - # context. - self.flow_level_org = 0 + # for each unclosed flow context. If empty list that means block context + self.flow_context = [] # type: List[Text] # List of processed tokens that are not yet emitted. self.tokens = [] # type: List[Any] @@ -507,13 +501,11 @@ class Scanner(object): self.fetch_flow_collection_start(FlowMappingStartToken, to_push='{') def fetch_flow_collection_start(self, TokenClass, to_push): - # type: (Any) -> None + # type: (Any, Text) -> None # '[' and '{' may start a simple key. self.save_possible_simple_key() # Increase the flow level. - self.flow_level_org += 1 self.flow_context.append(to_push) - # assert self.flow_level == len(self.flow_context) # Simple keys are allowed after '[' and '{'. self.allow_simple_key = True # Add FLOW-SEQUENCE-START or FLOW-MAPPING-START. @@ -531,13 +523,11 @@ class Scanner(object): self.fetch_flow_collection_end(FlowMappingEndToken, to_pop='{') def fetch_flow_collection_end(self, TokenClass, to_pop): - # type: (Any) -> None + # type: (Any, Text) -> None # Reset possible simple key on the current level. self.remove_possible_simple_key() # Decrease the flow level. - self.flow_level_org -= 1 assert self.flow_context.pop() == to_pop - assert self.flow_level_org == len(self.flow_context) # No simple keys after ']' or '}'. self.allow_simple_key = False # Add FLOW-SEQUENCE-END or FLOW-MAPPING-END. |