From c3ac95be03b0166b5910675f1d07c4d00db9dff8 Mon Sep 17 00:00:00 2001 From: Anthon van der Neut Date: Thu, 15 Aug 2019 13:14:08 +0200 Subject: allow # in 1.2 URI's fixes issue #305 *When this change indeed resolves your problem, please **Close** this issue*. *(You can do so using the WorkFlow pull-down (close to the top right of this page))* --- CHANGES | 5 +++++ Dockerfile | 25 ------------------------- README.rst | 9 +++++++-- __init__.py | 4 ++-- _doc/_static/pypi.svg | 2 +- _test/roundtrip.py | 6 ++---- _test/test_issues.py | 19 ++++++++++++++----- docker-compose.yaml | 13 ------------- emitter.py | 10 ++++++++-- main.py | 3 ++- 10 files changed, 41 insertions(+), 55 deletions(-) delete mode 100644 Dockerfile delete mode 100644 docker-compose.yaml diff --git a/CHANGES b/CHANGES index e2d3e83..4df6850 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,8 @@ +[0, 16, 2]: 2019-08-15 + - preserve YAML and TAG directives on roundtrip, correctly output # + in URL for YAML 1.2 (both reported by `Thomas Smith + `__) + [0, 16, 1]: 2019-08-08 - Force the use of new version of ruamel.yaml.clib (reported by `Alex Joz `__) diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 4906b2e..0000000 --- a/Dockerfile +++ /dev/null @@ -1,25 +0,0 @@ -FROM quay.io/pypa/manylinux1_x86_64:latest - -MAINTAINER Anthon van der Neut - -RUN echo '[global]' > /etc/pip.conf -RUN echo 'disable-pip-version-check = true' >> /etc/pip.conf - -RUN echo 'cd /src' > /usr/bin/makewheel -RUN echo 'rm -f /tmp/*.whl' >> /usr/bin/makewheel -RUN echo 'for PYVER in $*; do' >> /usr/bin/makewheel -RUN echo ' for PYBIN in /opt/python/cp$PYVER*/bin/; do' >> /usr/bin/makewheel -RUN echo ' echo "$PYBIN"' >> /usr/bin/makewheel -RUN echo ' ${PYBIN}/pip install -Uq pip' >> /usr/bin/makewheel -RUN echo ' ${PYBIN}/pip wheel . -w /tmp' >> /usr/bin/makewheel -RUN echo ' done' >> /usr/bin/makewheel -RUN echo 'done' >> /usr/bin/makewheel -RUN echo '' >> /usr/bin/makewheel -RUN echo 'for whl in /tmp/*.whl; do' >> /usr/bin/makewheel -RUN echo ' echo processing "$whl"' >> /usr/bin/makewheel -RUN echo ' auditwheel show "$whl"' >> /usr/bin/makewheel -RUN echo ' auditwheel repair "$whl" -w /src/dist/' >> /usr/bin/makewheel -RUN echo 'done' >> /usr/bin/makewheel -RUN chmod 755 /usr/bin/makewheel - -CMD /usr/bin/makewheel 27 35 36 37 diff --git a/README.rst b/README.rst index 10da491..c7152a8 100644 --- a/README.rst +++ b/README.rst @@ -4,8 +4,8 @@ ruamel.yaml ``ruamel.yaml`` is a YAML 1.2 loader/dumper package for Python. -:version: 0.16.1 -:updated: 2019-08-08 +:version: 0.16.2 +:updated: 2019-08-15 :documentation: http://yaml.readthedocs.io :repository: https://bitbucket.org/ruamel/yaml :pypi: https://pypi.org/project/ruamel.yaml/ @@ -54,6 +54,11 @@ ChangeLog .. should insert NEXT: at the beginning of line for next key (with empty line) +0.16.2 (2019-08-15): + - preserve YAML and TAG directives on roundtrip, correctly output # + in URL for YAML 1.2 (both reported by `Thomas Smith + `__) + 0.16.1 (2019-08-08): - Force the use of new version of ruamel.yaml.clib (reported by `Alex Joz `__) diff --git a/__init__.py b/__init__.py index 995bca9..7e1b208 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, 16, 1), - __version__='0.16.1', + version_info=(0, 16, 2), + __version__='0.16.2', 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 aa448d9..dc4abf1 100644 --- a/_doc/_static/pypi.svg +++ b/_doc/_static/pypi.svg @@ -1 +1 @@ - pypipypi0.16.10.16.1 + pypipypi0.16.20.16.2 diff --git a/_test/roundtrip.py b/_test/roundtrip.py index 090b9e0..af8a555 100644 --- a/_test/roundtrip.py +++ b/_test/roundtrip.py @@ -169,6 +169,7 @@ def na_round_trip( inp: input string to parse outp: expected output (equals input if not specified) """ + inp = dedent(inp) if outp is None: outp = inp if version is not None: @@ -194,10 +195,7 @@ def na_round_trip( yaml.explicit_start = explicit_start yaml.explicit_end = explicit_end res = yaml.dump(data, compare=doutp) - #if res != doutp: - # diff(doutp, res, 'input string') - #print('\nroundtrip data:\n', res, sep="") - #assert res == doutp + return res def YAML(**kw): diff --git a/_test/test_issues.py b/_test/test_issues.py index 9b301a9..5606122 100644 --- a/_test/test_issues.py +++ b/_test/test_issues.py @@ -853,11 +853,20 @@ class TestIssues: def test_issue_304(self): inp = """ - %YAML 1.2 - %TAG ! tag:example.com,2019: - --- - !foo null - ... + %YAML 1.2 + %TAG ! tag:example.com,2019: + --- + !foo null + ... + """ + d = na_round_trip(inp) # NOQA + + def test_issue_305(self): + inp = """ + %YAML 1.2 + --- + ! null + ... """ d = na_round_trip(inp) # NOQA diff --git a/docker-compose.yaml b/docker-compose.yaml deleted file mode 100644 index 1b1e6c4..0000000 --- a/docker-compose.yaml +++ /dev/null @@ -1,13 +0,0 @@ -version: '2' -user-data: - author: Anthon van der Neut - description: manylinux wheel build container for ruamel.yaml - env-defaults: - PYDISTBASE: /tmp # for building, normally set by `dv --distbase` -services: - ruamel_yaml_manylinux1: - container_name: ruamel_yaml - build: . - volumes: - - ${PYDISTBASE}/ruamel.yaml:/src/dist - - .:/src diff --git a/emitter.py b/emitter.py index 7cdebcd..1b6006f 100644 --- a/emitter.py +++ b/emitter.py @@ -410,7 +410,8 @@ class Emitter(object): and self.sequence_context ): self.sequence_context = False - if root and isinstance(self.event, ScalarEvent) and not self.scalar_after_indicator: + if root and isinstance(self.event, ScalarEvent) \ + and not self.scalar_after_indicator: self.write_indent() self.process_tag() if isinstance(self.event, ScalarEvent): @@ -951,13 +952,18 @@ class Emitter(object): suffix = tag[len(prefix) :] chunks = [] # type: List[Any] start = end = 0 + ch_set = u"-;/?:@&=+$,_.~*'()[]" + if self.dumper: + version = getattr(self.dumper, 'version', (1, 2)) + if version is None or version >= (1, 2): + ch_set += u'#' while end < len(suffix): ch = suffix[end] if ( u'0' <= ch <= u'9' or u'A' <= ch <= u'Z' or u'a' <= ch <= u'z' - or ch in u"-;/?:@&=+$,_.~*'()[]" + or ch in ch_set or (ch == u'!' and handle != u'!') ): end += 1 diff --git a/main.py b/main.py index 0785c95..2d5103e 100644 --- a/main.py +++ b/main.py @@ -161,7 +161,8 @@ class YAML(object): self.tags = None self.default_style = None self.top_level_block_style_scalar_no_indent_error_1_1 = False - self.scalar_after_indicator = None # directives end indicator with single scalar document + # directives end indicator with single scalar document + self.scalar_after_indicator = None # [a, b: 1, c: {d: 2}] vs. [a, {b: 1}, {c: {d: 2}}] self.brace_single_entry_mapping_in_flow_sequence = False -- cgit v1.2.1