diff options
-rw-r--r-- | CHANGES | 5 | ||||
-rw-r--r-- | README.rst | 7 | ||||
-rw-r--r-- | __init__.py | 70 | ||||
-rw-r--r-- | _doc/_static/pypi.svg | 2 | ||||
-rw-r--r-- | _test/test_issues.py | 103 | ||||
-rw-r--r-- | scanner.py | 13 | ||||
-rw-r--r-- | tokens.py | 1 |
7 files changed, 161 insertions, 40 deletions
@@ -1,3 +1,8 @@ +[0, 15, 96]: 2019-05-16 + - fix failure to indent comments on round-trip anchored block style + scalars in block sequence (reported by `William Kimball + <https://bitbucket.org/%7Bba35ed20-4bb0-46f8-bb5d-c29871e86a22%7D/>`__) + [0, 15, 95]: 2019-05-16 - fix failure to round-trip anchored scalars in block sequence (reported by `William Kimball @@ -4,7 +4,7 @@ ruamel.yaml ``ruamel.yaml`` is a YAML 1.2 loader/dumper package for Python. -:version: 0.15.95 +:version: 0.15.96 :updated: 2019-05-16 :documentation: http://yaml.readthedocs.io :repository: https://bitbucket.org/ruamel/ @@ -54,6 +54,11 @@ ChangeLog .. should insert NEXT: at the beginning of line for next key (with empty line) +0.15.96 (2019-05-16): + - fix failure to indent comments on round-trip anchored block style + scalars in block sequence (reported by `William Kimball + <https://bitbucket.org/%7Bba35ed20-4bb0-46f8-bb5d-c29871e86a22%7D/>`__) + 0.15.95 (2019-05-16): - fix failure to round-trip anchored scalars in block sequence (reported by `William Kimball diff --git a/__init__.py b/__init__.py index 82769bb..eccda43 100644 --- a/__init__.py +++ b/__init__.py @@ -7,59 +7,59 @@ if False: # MYPY _package_data = dict( full_package_name='ruamel.yaml', - version_info=(0, 15, 95), - __version__='0.15.95', + version_info=(0, 15, 96), + __version__='0.15.96', 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 entry_points=None, since=2014, - extras_require={ - ':platform_python_implementation=="CPython" and python_version<="2.7"': [ - 'ruamel.ordereddict' - ], - 'jinja2': ['ruamel.yaml.jinja2>=0.2'], - 'docs': ['ryd'], - }, + extras_require={':platform_python_implementation=="CPython" and python_version<="2.7"': [ + 'ruamel.ordereddict', + ], 'jinja2': ['ruamel.yaml.jinja2>=0.2'], 'docs': ['ryd']}, ext_modules=[ - dict( - name='_ruamel_yaml', - src=[ - 'ext/_ruamel_yaml.c', - 'ext/api.c', - 'ext/writer.c', - 'ext/dumper.c', - 'ext/loader.c', - 'ext/reader.c', - 'ext/scanner.c', - 'ext/parser.c', - 'ext/emitter.c', - ], - lib=[], - test=""" + dict( + name='_ruamel_yaml', + src=[ + 'ext/_ruamel_yaml.c', + 'ext/api.c', + 'ext/writer.c', + 'ext/dumper.c', + 'ext/loader.c', + 'ext/reader.c', + 'ext/scanner.c', + 'ext/parser.c', + 'ext/emitter.c', + ], + lib=[], + test=""" int main(int argc, char* argv[]) { /* prevent warning */ return 0; } """, - ) + ), ], # NOQA # test='#include "ext/yaml.h"\n\nint main(int argc, char* argv[])\n{\nyaml_parser_t parser;\nparser = parser; /* prevent warning */\nreturn 0;\n}\n', # NOQA classifiers=[ - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: Implementation :: CPython', - 'Programming Language :: Python :: Implementation :: PyPy', - 'Programming Language :: Python :: Implementation :: Jython', - 'Topic :: Software Development :: Libraries :: Python Modules', - 'Topic :: Text Processing :: Markup', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: Implementation :: CPython', + 'Programming Language :: Python :: Implementation :: PyPy', + 'Programming Language :: Python :: Implementation :: Jython', + 'Topic :: Software Development :: Libraries :: Python Modules', + 'Topic :: Text Processing :: Markup', ], keywords='yaml 1.2 parser round-trip preserve quotes order config', - wheels=dict(windows='appveyor', linux='libyaml-devel', macos='builder@macos'), + wheels=dict( + windows='appveyor', + linux='libyaml-devel', + macos='builder@macos', + ), read_the_docs='yaml', supported=[(2, 7), (3, 5)], # minimum tox=dict( diff --git a/_doc/_static/pypi.svg b/_doc/_static/pypi.svg index 1c1ffd2..ac96396 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.95</text><text x="585" y="140" transform="scale(.1)" textLength="430">0.15.95</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.96</text><text x="585" y="140" transform="scale(.1)" textLength="430">0.15.96</text></g> </svg> diff --git a/_test/test_issues.py b/_test/test_issues.py index ec7d95d..990d538 100644 --- a/_test/test_issues.py +++ b/_test/test_issues.py @@ -695,6 +695,109 @@ class TestIssues: yaml.dump(data, buf) assert buf.getvalue() == yamldoc + def test_issue_288a(self): + import sys + from ruamel.yaml.compat import StringIO + from ruamel.yaml import YAML + + yamldoc = dedent("""\ + --- + # Reusable values + aliases: + # First-element comment + - &firstEntry First entry + # Second-element comment + - &secondEntry Second entry + + # Third-element comment is + # a multi-line value + - &thirdEntry Third entry + + # EOF Comment + """) + + yaml = YAML() + yaml.indent(mapping=2, sequence=4, offset=2) + yaml.explicit_start = True + yaml.preserve_quotes = True + yaml.width = sys.maxsize + data = yaml.load(yamldoc) + buf = StringIO() + yaml.dump(data, buf) + assert buf.getvalue() == yamldoc + + def test_issue_290(self): + import sys + from ruamel.yaml.compat import StringIO + from ruamel.yaml import YAML + + yamldoc = dedent("""\ + --- + aliases: + # Folded-element comment + # for a multi-line value + - &FoldedEntry > + THIS IS A + FOLDED, MULTI-LINE + VALUE + + # Literal-element comment + # for a multi-line value + - &literalEntry | + THIS IS A + LITERAL, MULTI-LINE + VALUE + + # Plain-element comment + - &plainEntry Plain entry + """) + + yaml = YAML() + yaml.indent(mapping=2, sequence=4, offset=2) + yaml.explicit_start = True + yaml.preserve_quotes = True + yaml.width = sys.maxsize + data = yaml.load(yamldoc) + buf = StringIO() + yaml.dump(data, buf) + assert buf.getvalue() == yamldoc + + def test_issue_290a(self): + import sys + from ruamel.yaml.compat import StringIO + from ruamel.yaml import YAML + + yamldoc = dedent("""\ + --- + aliases: + # Folded-element comment + # for a multi-line value + - &FoldedEntry > + THIS IS A + FOLDED, MULTI-LINE + VALUE + + # Literal-element comment + # for a multi-line value + - &literalEntry | + THIS IS A + LITERAL, MULTI-LINE + VALUE + + # Plain-element comment + - &plainEntry Plain entry + """) + + yaml = YAML() + yaml.indent(mapping=2, sequence=4, offset=2) + yaml.explicit_start = True + yaml.preserve_quotes = True + yaml.width = sys.maxsize + data = yaml.load(yamldoc) + buf = StringIO() + yaml.dump(data, buf) + assert buf.getvalue() == yamldoc + # @pytest.mark.xfail(strict=True, reason='bla bla', raises=AssertionError) # def test_issue_ xxx(self): # inp = """ @@ -1237,7 +1237,7 @@ class Scanner(object): # Eat whitespaces and comments until we reach the next token. comment = self.scan_to_next_token() while comment: - trailing.append(comment[0]) + trailing.append(' ' * comment[1].column + comment[0]) comment = self.scan_to_next_token() # Keep track of the trailing whitespace and following comments @@ -1824,7 +1824,14 @@ class RoundTripScanner(Scanner): and self.tokens[0].end_mark.line == self.tokens[1].start_mark.line ): self.tokens_taken += 1 - self.tokens[0].add_post_comment(self.tokens.pop(1)) + c = self.tokens.pop(1) + self.fetch_more_tokens() + while len(self.tokens) > 1 and isinstance(self.tokens[1], CommentToken): + self.tokens_taken += 1 + c1 = self.tokens.pop(1) + c.value = c.value + (' ' * c1.start_mark.column) + c1.value + self.fetch_more_tokens() + self.tokens[0].add_post_comment(c) elif ( len(self.tokens) > 1 and isinstance(self.tokens[0], ScalarToken) @@ -1843,7 +1850,7 @@ class RoundTripScanner(Scanner): while len(self.tokens) > 1 and isinstance(self.tokens[1], CommentToken): self.tokens_taken += 1 c1 = self.tokens.pop(1) - c.value = c.value + (' ' * c.start_mark.column) + c1.value + c.value = c.value + (' ' * c1.start_mark.column) + c1.value self.fetch_more_tokens() self.tokens_taken += 1 return self.tokens.pop(0) @@ -266,6 +266,7 @@ class CommentToken(Token): if SHOWLINES: try: v += ', line: ' + str(self.start_mark.line) + v += ', col: ' + str(self.start_mark.column) except: # NOQA pass return 'CommentToken({})'.format(v) |