diff options
author | Anthon van der Neut <anthon@mnt.org> | 2016-02-16 21:16:30 +0100 |
---|---|---|
committer | Anthon van der Neut <anthon@mnt.org> | 2016-02-16 21:16:30 +0100 |
commit | a5f5028c7d5623a13b392d8e9bdb9be622476f8c (patch) | |
tree | 8622585e8067711fcd86cda71d289f46b1309b75 | |
parent | 64c39f0c0b38bcac13cb4c31429b5e3caadf278e (diff) | |
download | ruamel.yaml-a5f5028c7d5623a13b392d8e9bdb9be622476f8c.tar.gz |
- make sure there is a space before # if scalar pushes (through indent)
a comment from its original column
- flake 8
37 files changed, 310 insertions, 240 deletions
@@ -7,7 +7,11 @@ REGEN:=/home/bin/ruamel_util_new util --published --command YAML --skip-hg include ~/.config/ruamel_util_new/Makefile.inc gen_win_whl: - @python make_win_whl.py dist/$(PKGNAME)-$(VERSION)-*-none-any.whl + python2 setup.py bdist_wheel --plat-name win32 + python2 setup.py bdist_wheel --plat-name win_amd64 + python3 setup.py bdist_wheel --plat-name win32 + python3 setup.py bdist_wheel --plat-name win_amd64 + #@python make_win_whl.py dist/$(PKGNAME)-$(VERSION)-*-none-any.whl clean: clean_common find . -name "*py.class" -exec rm {} + diff --git a/__init__.py b/__init__.py index 73617c9..ffb5f39 100644 --- a/__init__.py +++ b/__init__.py @@ -9,7 +9,7 @@ from __future__ import absolute_import _package_data = dict( full_package_name="ruamel.yaml", - version_info=(0, 10, 20), + version_info=(0, 10, 21), 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 @@ -19,7 +19,7 @@ _package_data = dict( py26=["ruamel.ordereddict"], py27=["ruamel.ordereddict"] ), - ext_modules=[ dict( + 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", @@ -70,17 +70,14 @@ __version__ = _convert_version(version_info) del _convert_version try: - from .cyaml import * + from .cyaml import * # NOQA __with_libyaml__ = True except (ImportError, ValueError): # for Jython __with_libyaml__ = False -import sys # body extracted to main.py try: - from .main import * + from .main import * # NOQA except ImportError: - from ruamel.yaml.main import * - - + from ruamel.yaml.main import * # NOQA diff --git a/_test/lib/test_tokens.py b/_test/lib/test_tokens.py index 0b547e3..be067f0 100644 --- a/_test/lib/test_tokens.py +++ b/_test/lib/test_tokens.py @@ -45,6 +45,7 @@ _replaces = { yaml.ValueToken: ':', } + def test_tokens(data_filename, tokens_filename, verbose=False): tokens1 = [] with open(tokens_filename, 'r' if PY3 else 'rb') as fp: @@ -65,6 +66,7 @@ def test_tokens(data_filename, tokens_filename, verbose=False): test_tokens.unittest = ['.data', '.tokens'] + def test_scanner(data_filename, canonical_filename, verbose=False): for filename in [data_filename, canonical_filename]: tokens = [] @@ -81,4 +83,3 @@ test_scanner.unittest = ['.data', '.canonical'] if __name__ == '__main__': import test_appliance test_appliance.run(globals()) - diff --git a/_test/lib/test_yaml.py b/_test/lib/test_yaml.py index d92ab5c..65a4bc6 100644 --- a/_test/lib/test_yaml.py +++ b/_test/lib/test_yaml.py @@ -1,16 +1,17 @@ +# coding: utf-8 -from test_mark import * -from test_reader import * -from test_canonical import * -from test_tokens import * -from test_structure import * -from test_errors import * -from test_resolver import * -from test_constructor import * -from test_emitter import * -from test_representer import * -from test_recursive import * -from test_input_output import * +from test_mark import * # NOQA +from test_reader import * # NOQA +from test_canonical import * # NOQA +from test_tokens import * # NOQA +from test_structure import * # NOQA +from test_errors import * # NOQA +from test_resolver import * # NOQA +from test_constructor import * # NOQA +from test_emitter import * # NOQA +from test_representer import * # NOQA +from test_recursive import * # NOQA +from test_input_output import * # NOQA if __name__ == '__main__': import sys diff --git a/_test/lib/test_yaml_ext.py b/_test/lib/test_yaml_ext.py index adfeb19..ebb9f58 100644 --- a/_test/lib/test_yaml_ext.py +++ b/_test/lib/test_yaml_ext.py @@ -1,9 +1,12 @@ +# coding: utf-8 + from __future__ import absolute_import from __future__ import print_function import _ruamel_yaml import ruamel.yaml -import types, pprint +import types +import pprint from ruamel.yaml.compat import PY3 ruamel.yaml.PyBaseLoader = ruamel.yaml.BaseLoader @@ -14,65 +17,96 @@ ruamel.yaml.PySafeDumper = ruamel.yaml.SafeDumper ruamel.yaml.PyDumper = ruamel.yaml.Dumper old_scan = ruamel.yaml.scan + + def new_scan(stream, Loader=ruamel.yaml.CLoader): return old_scan(stream, Loader) old_parse = ruamel.yaml.parse + + def new_parse(stream, Loader=ruamel.yaml.CLoader): return old_parse(stream, Loader) old_compose = ruamel.yaml.compose + + def new_compose(stream, Loader=ruamel.yaml.CLoader): return old_compose(stream, Loader) old_compose_all = ruamel.yaml.compose_all + + def new_compose_all(stream, Loader=ruamel.yaml.CLoader): return old_compose_all(stream, Loader) old_load = ruamel.yaml.load + + def new_load(stream, Loader=ruamel.yaml.CLoader): return old_load(stream, Loader) old_load_all = ruamel.yaml.load_all + + def new_load_all(stream, Loader=ruamel.yaml.CLoader): return old_load_all(stream, Loader) old_safe_load = ruamel.yaml.safe_load + + def new_safe_load(stream): return old_load(stream, ruamel.yaml.CSafeLoader) old_safe_load_all = ruamel.yaml.safe_load_all + + def new_safe_load_all(stream): return old_load_all(stream, ruamel.yaml.CSafeLoader) old_emit = ruamel.yaml.emit + + def new_emit(events, stream=None, Dumper=ruamel.yaml.CDumper, **kwds): return old_emit(events, stream, Dumper, **kwds) old_serialize = ruamel.yaml.serialize + + def new_serialize(node, stream, Dumper=ruamel.yaml.CDumper, **kwds): return old_serialize(node, stream, Dumper, **kwds) old_serialize_all = ruamel.yaml.serialize_all + + def new_serialize_all(nodes, stream=None, Dumper=ruamel.yaml.CDumper, **kwds): return old_serialize_all(nodes, stream, Dumper, **kwds) old_dump = ruamel.yaml.dump + + def new_dump(data, stream=None, Dumper=ruamel.yaml.CDumper, **kwds): return old_dump(data, stream, Dumper, **kwds) old_dump_all = ruamel.yaml.dump_all + + def new_dump_all(documents, stream=None, Dumper=ruamel.yaml.CDumper, **kwds): return old_dump_all(documents, stream, Dumper, **kwds) old_safe_dump = ruamel.yaml.safe_dump + + def new_safe_dump(data, stream=None, **kwds): return old_dump(data, stream, ruamel.yaml.CSafeDumper, **kwds) old_safe_dump_all = ruamel.yaml.safe_dump_all + + def new_safe_dump_all(documents, stream=None, **kwds): return old_dump_all(documents, stream, ruamel.yaml.CSafeDumper, **kwds) + def _set_up(): ruamel.yaml.BaseLoader = ruamel.yaml.CBaseLoader ruamel.yaml.SafeLoader = ruamel.yaml.CSafeLoader @@ -96,6 +130,7 @@ def _set_up(): ruamel.yaml.safe_dump = new_safe_dump ruamel.yaml.safe_dump_all = new_safe_dump_all + def _tear_down(): ruamel.yaml.BaseLoader = ruamel.yaml.PyBaseLoader ruamel.yaml.SafeLoader = ruamel.yaml.PySafeLoader @@ -119,12 +154,14 @@ def _tear_down(): ruamel.yaml.safe_dump = old_safe_dump ruamel.yaml.safe_dump_all = old_safe_dump_all + def test_c_version(verbose=False): if verbose: print(_ruamel_yaml.get_version()) print(_ruamel_yaml.get_version_string()) - assert ("%s.%s.%s" % _ruamel_yaml.get_version()) == _ruamel_yaml.get_version_string(), \ - (_ruamel_yaml.get_version(), _ruamel_yaml.get_version_string()) + assert ("%s.%s.%s" % _ruamel_yaml.get_version()) == _ruamel_yaml.get_version_string(), \ + (_ruamel_yaml.get_version(), _ruamel_yaml.get_version_string()) + def _compare_scanners(py_data, c_data, verbose): py_tokens = list(ruamel.yaml.scan(py_data, Loader=ruamel.yaml.PyLoader)) @@ -139,9 +176,12 @@ def _compare_scanners(py_data, c_data, verbose): assert py_token.value == c_token.value, (py_token, c_token) if isinstance(py_token, ruamel.yaml.StreamEndToken): continue - py_start = (py_token.start_mark.index, py_token.start_mark.line, py_token.start_mark.column) - py_end = (py_token.end_mark.index, py_token.end_mark.line, py_token.end_mark.column) - c_start = (c_token.start_mark.index, c_token.start_mark.line, c_token.start_mark.column) + py_start = (py_token.start_mark.index, py_token.start_mark.line, + py_token.start_mark.column) + py_end = (py_token.end_mark.index, py_token.end_mark.line, + py_token.end_mark.column) + c_start = (c_token.start_mark.index, c_token.start_mark.line, + c_token.start_mark.column) c_end = (c_token.end_mark.index, c_token.end_mark.line, c_token.end_mark.column) assert py_start == c_start, (py_start, c_start) assert py_end == c_end, (py_end, c_end) @@ -152,6 +192,7 @@ def _compare_scanners(py_data, c_data, verbose): print("C_TOKENS:") pprint.pprint(c_tokens) + def test_c_scanner(data_filename, canonical_filename, verbose=False): with open(data_filename, 'rb') as fp0: with open(data_filename, 'rb') as fp1: @@ -169,6 +210,7 @@ def test_c_scanner(data_filename, canonical_filename, verbose=False): test_c_scanner.unittest = ['.data', '.canonical'] test_c_scanner.skip = ['.skip-ext'] + def _compare_parsers(py_data, c_data, verbose): py_events = list(ruamel.yaml.parse(py_data, Loader=ruamel.yaml.PyLoader)) c_events = [] @@ -178,7 +220,7 @@ def _compare_parsers(py_data, c_data, verbose): assert len(py_events) == len(c_events), (len(py_events), len(c_events)) for py_event, c_event in zip(py_events, c_events): for attribute in ['__class__', 'anchor', 'tag', 'implicit', - 'value', 'explicit', 'version', 'tags']: + 'value', 'explicit', 'version', 'tags']: py_value = getattr(py_event, attribute, None) c_value = getattr(c_event, attribute, None) assert py_value == c_value, (py_event, c_event, attribute) @@ -189,6 +231,7 @@ def _compare_parsers(py_data, c_data, verbose): print("C_EVENTS:") pprint.pprint(c_events) + def test_c_parser(data_filename, canonical_filename, verbose=False): with open(data_filename, 'rb') as fp0: with open(data_filename, 'rb') as fp1: @@ -206,6 +249,7 @@ def test_c_parser(data_filename, canonical_filename, verbose=False): test_c_parser.unittest = ['.data', '.canonical'] test_c_parser.skip = ['.skip-ext'] + def _compare_emitters(data, verbose): events = list(ruamel.yaml.parse(data, Loader=ruamel.yaml.PyLoader)) c_data = ruamel.yaml.emit(events, Dumper=ruamel.yaml.CDumper) @@ -218,7 +262,7 @@ def _compare_emitters(data, verbose): assert len(events) == len(c_events), (len(events), len(c_events)) for event, py_event, c_event in zip(events, py_events, c_events): for attribute in ['__class__', 'anchor', 'tag', 'implicit', - 'value', 'explicit', 'version', 'tags']: + 'value', 'explicit', 'version', 'tags']: value = getattr(event, attribute, None) py_value = getattr(py_event, attribute, None) c_value = getattr(c_event, attribute, None) @@ -238,6 +282,7 @@ def _compare_emitters(data, verbose): print("C_EVENTS:") pprint.pprint(c_events) + def test_c_emitter(data_filename, canonical_filename, verbose=False): with open(data_filename, 'rb') as fp0: _compare_emitters(fp0.read(), verbose) @@ -247,6 +292,7 @@ def test_c_emitter(data_filename, canonical_filename, verbose=False): test_c_emitter.unittest = ['.data', '.canonical'] test_c_emitter.skip = ['.skip-ext'] + def wrap_ext_function(function): def wrapper(*args, **kwds): _set_up() @@ -266,6 +312,7 @@ def wrap_ext_function(function): wrapper.skip = getattr(function, 'skip', [])+['.skip-ext'] return wrapper + def wrap_ext(collections): functions = [] if not isinstance(collections, list): @@ -285,13 +332,19 @@ def wrap_ext(collections): assert function.unittest_name not in globals() globals()[function.unittest_name] = function -import test_tokens, test_structure, test_errors, test_resolver, test_constructor, \ - test_emitter, test_representer, test_recursive, test_input_output +import test_tokens # NOQA +import test_structure # NOQA +import test_errors # NOQA +import test_resolver # NOQA +import test_constructor # NOQA +import test_emitter # NOQA +import test_representer # NOQA +import test_recursive # NOQA +import test_input_output # NOQA wrap_ext([test_tokens, test_structure, test_errors, test_resolver, test_constructor, - test_emitter, test_representer, test_recursive, test_input_output]) + test_emitter, test_representer, test_recursive, test_input_output]) if __name__ == '__main__': import sys import test_appliance sys.exit(test_appliance.run(globals())) - diff --git a/_test/roundtrip.py b/_test/roundtrip.py index 446e943..a8b0fb7 100644 --- a/_test/roundtrip.py +++ b/_test/roundtrip.py @@ -26,9 +26,9 @@ def round_trip_load(dinp): return ruamel.yaml.load(dinp, ruamel.yaml.RoundTripLoader) -def round_trip_dump(data): +def round_trip_dump(data, indent=None): dumper = ruamel.yaml.RoundTripDumper - return ruamel.yaml.dump(data, default_flow_style=False, Dumper=dumper) + return ruamel.yaml.dump(data, default_flow_style=False, Dumper=dumper, indent=indent) def round_trip(inp, outp=None, extra=None, intermediate=None): diff --git a/_test/test_anchor.py b/_test/test_anchor.py index b0ce521..1735bdd 100644 --- a/_test/test_anchor.py +++ b/_test/test_anchor.py @@ -8,12 +8,13 @@ import pytest from textwrap import dedent import platform -import ruamel.yaml -from roundtrip import round_trip, dedent, round_trip_load, round_trip_dump +from roundtrip import round_trip, dedent, round_trip_load, round_trip_dump # NOQA + def load(s): return round_trip_load(dedent(s)) + def compare(data, s): assert round_trip_dump(data) == dedent(s) @@ -47,11 +48,11 @@ class TestAnchorsAliases: assert not templated_id(u'id000') assert not templated_id(u'x000') - #def test_re_matcher(self): - # import re - # assert re.compile(u'id(?!000)\\d{3,}').match('id001') - # assert not re.compile(u'id(?!000\\d*)\\d{3,}').match('id000') - # assert re.compile(u'id(?!000$)\\d{3,}').match('id0001') + # def test_re_matcher(self): + # import re + # assert re.compile(u'id(?!000)\\d{3,}').match('id001') + # assert not re.compile(u'id(?!000\\d*)\\d{3,}').match('id000') + # assert re.compile(u'id(?!000$)\\d{3,}').match('id0001') def test_anchor_assigned(self): from ruamel.yaml.comments import CommentedMap @@ -73,7 +74,7 @@ class TestAnchorsAliases: assert e.yaml_anchor().value == 'etemplate' assert e.yaml_anchor().always_dump is False - #@pytest.mark.xfail + # @pytest.mark.xfail def test_anchor_id_retained(self): data = load(""" a: &id002 @@ -107,6 +108,7 @@ class TestAnchorsAliases: b: 1 c: 2 """) + data = data def test_anchor_on_sequence(self): # as reported by Bjorn Stabell @@ -128,7 +130,6 @@ class TestAnchorsAliases: assert l.yaml_anchor() is not None assert l.yaml_anchor().value == 'alice' - merge_yaml = dedent(""" - &CENTER {x: 1, y: 2} - &LEFT {x: 0, y: 2} @@ -197,7 +198,7 @@ class TestAnchorsAliases: b: <<: *content ''' - data = round_trip(yaml) + data = round_trip(yaml) # NOQA def test_merge_nested_with_sequence(self): yaml = ''' @@ -210,7 +211,7 @@ class TestAnchorsAliases: b: <<: [*content, *y2] ''' - data = round_trip(yaml) + data = round_trip(yaml) # NOQA def test_add_anchor(self): from ruamel.yaml.comments import CommentedMap diff --git a/_test/test_comment_manipulation.py b/_test/test_comment_manipulation.py index a500b79..306c365 100644 --- a/_test/test_comment_manipulation.py +++ b/_test/test_comment_manipulation.py @@ -2,11 +2,9 @@ from __future__ import print_function -import pytest -from textwrap import dedent +import pytest # NOQA -import ruamel.yaml -from roundtrip import round_trip, dedent, round_trip_load, round_trip_dump +from roundtrip import round_trip, dedent, round_trip_load, round_trip_dump # NOQA def load(s): @@ -15,7 +13,7 @@ def load(s): def compare(data, s): assert round_trip_dump(data) == dedent(s) -#@pytest.mark.xfail +# @pytest.mark.xfail class TestCommentsManipulation: @@ -85,7 +83,7 @@ class TestCommentsManipulation: print(data._yaml_comment) # print(type(data._yaml_comment._items[0][0].start_mark)) # ruamel.yaml.error.Mark - #print(type(data._yaml_comment._items[0][0].start_mark)) + # print(type(data._yaml_comment._items[0][0].start_mark)) data.yaml_add_eol_comment('comment 2', key=2) compare(data, """ - a # comment 1 @@ -110,7 +108,7 @@ class TestCommentsManipulation: print(data._yaml_comment) # print(type(data._yaml_comment._items[0][0].start_mark)) # ruamel.yaml.error.Mark - #print(type(data._yaml_comment._items[0][0].start_mark)) + # print(type(data._yaml_comment._items[0][0].start_mark)) data.yaml_add_eol_comment('comment 2', key=3) compare(data, """ - a # comment 1 @@ -170,7 +168,6 @@ class TestCommentsManipulation: e: 5 """) - def test_map_set_comment_on_existing_column_prev(self): data = load(""" a: 1 # comment 1 @@ -231,7 +228,7 @@ class TestCommentsManipulation: # py.test cannot handle comments in strings properly # https://bitbucket.org/pytest-dev/pytest/issue/752/internalerror-indexerror-list-index-out-of - #@pytest.mark.xfail + # @pytest.mark.xfail def test_before_top_map_rt(self): data = load(""" a: 1 @@ -266,8 +263,8 @@ class TestCommentsManipulation: data['a'] = 1 data['b'] = 2 data.yaml_set_start_comment('Hello\nWorld\n') - #print(data.ca) - #print(data.ca._items) + # print(data.ca) + # print(data.ca._items) compare(data, """ {comment} Hello {comment} World @@ -390,4 +387,3 @@ class TestCommentsManipulation: - c - d """.format(comment='#')) - diff --git a/_test/test_comments.py b/_test/test_comments.py index 8d87f0e..727243b 100644 --- a/_test/test_comments.py +++ b/_test/test_comments.py @@ -12,7 +12,6 @@ roundtrip changes import pytest -import ruamel.yaml from roundtrip import round_trip, dedent, round_trip_load, round_trip_dump @@ -72,6 +71,20 @@ class TestComments: # C end b """) + def test_reindent(self): + x = dedent("""\ + a: + b: # comment 1 + c: 1 # comment 2 + """) + d = round_trip_load(x) + y = round_trip_dump(d, indent=4) + assert y == dedent("""\ + a: + b: # comment 1 + c: 1 # comment 2 + """) + def test_main_mapping_begin_end_items_post(self): round_trip(""" # C start a @@ -184,7 +197,6 @@ class TestComments: x = x.replace(': secret ', ': deleted password') assert round_trip_dump(data) == x - def test_set_comment(self): round_trip(""" !!set @@ -268,4 +280,3 @@ class TestMultiLevelGet: assert d.mlget(['a', 1, 'd', 'f'], list_ok=True) == 196 with pytest.raises(AssertionError): d.mlget(['a', 1, 'd', 'f']) == 196 - diff --git a/_test/test_cyaml.py b/_test/test_cyaml.py index 26f2683..81dc4a5 100644 --- a/_test/test_cyaml.py +++ b/_test/test_cyaml.py @@ -1,9 +1,11 @@ +# coding: utf-8 import platform import pytest + @pytest.mark.skipif(platform.python_implementation() == 'Jython', - reason="Jython throws RepresenterError") + reason="Jython throws RepresenterError") def test_load_cyaml(): import ruamel.yaml assert ruamel.yaml.__with_libyaml__ diff --git a/_test/test_indentation.py b/_test/test_indentation.py index 9a79c64..9d5fc96 100644 --- a/_test/test_indentation.py +++ b/_test/test_indentation.py @@ -1,3 +1,5 @@ +# coding: utf-8 + from __future__ import absolute_import from __future__ import print_function from __future__ import unicode_literals @@ -5,7 +7,7 @@ from __future__ import unicode_literals from textwrap import dedent -import pytest +import pytest # NOQA import ruamel.yaml @@ -22,6 +24,7 @@ def test_roundtrip_inline_list(): output = rt(s) assert s == output + def test_roundtrip_mapping_of_inline_lists(): s = dedent("""\ a: [a, b, c] @@ -30,6 +33,7 @@ def test_roundtrip_mapping_of_inline_lists(): output = rt(s) assert s == output + def test_roundtrip_mapping_of_inline_lists_comments(): s = dedent("""\ # comment A @@ -40,6 +44,7 @@ def test_roundtrip_mapping_of_inline_lists_comments(): output = rt(s) assert s == output + def test_roundtrip_mapping_of_inline_sequence_eol_comments(): s = dedent("""\ # comment A @@ -66,7 +71,8 @@ def test_added_inline_list(): output = ruamel.yaml.dump(data, Dumper=ruamel.yaml.RoundTripDumper) assert s == output -############# flow mappings +# ############ flow mappings + def test_roundtrip_flow_mapping(): s = dedent("""\ @@ -77,6 +83,7 @@ def test_roundtrip_flow_mapping(): output = ruamel.yaml.dump(data, Dumper=ruamel.yaml.RoundTripDumper) assert s == output + def test_roundtrip_sequence_of_inline_mappings_eol_comments(): s = dedent("""\ # comment A @@ -86,10 +93,9 @@ def test_roundtrip_sequence_of_inline_mappings_eol_comments(): output = rt(s) assert s == output +# ############ indentation -############# indentation - @pytest.mark.xfail def test_roundtrip_four_space_indents(): s = ( diff --git a/_test/test_json_numbers.py b/_test/test_json_numbers.py index db5bcaa..b41c350 100644 --- a/_test/test_json_numbers.py +++ b/_test/test_json_numbers.py @@ -1,11 +1,13 @@ +# coding: utf-8 from __future__ import print_function -import pytest +import pytest # NOQA import ruamel.yaml import json + def load(s, typ=float): x = '{"low": %s }' % (s) print('input: [%s]' % (s), repr(x)) @@ -16,6 +18,7 @@ def load(s, typ=float): print(ret_val) return ret_val['low'] + class TestJSONNumbers: # based on http://stackoverflow.com/a/30462009/1307905 # yaml number regex: http://yaml.org/spec/1.2/spec.html#id2804092 @@ -45,4 +48,3 @@ class TestJSONNumbers: continue res = load(x, int) assert isinstance(res, int) - diff --git a/_test/test_line_col.py b/_test/test_line_col.py index 75a0237..febe9c2 100644 --- a/_test/test_line_col.py +++ b/_test/test_line_col.py @@ -1,10 +1,8 @@ # coding: utf-8 -import pytest -from textwrap import dedent +import pytest # NOQA -import ruamel.yaml -from roundtrip import round_trip, dedent, round_trip_load, round_trip_dump +from roundtrip import round_trip, dedent, round_trip_load, round_trip_dump # NOQA def load(s): @@ -54,7 +52,6 @@ class TestLineCol: assert data[2].lc.line == 2 assert data[2].lc.col == 2 - def test_item_04(self): data = load(""" # testing line and column based on SO diff --git a/_test/test_program_config.py b/_test/test_program_config.py index 7974ffc..dcd8351 100644 --- a/_test/test_program_config.py +++ b/_test/test_program_config.py @@ -1,8 +1,8 @@ -import pytest +import pytest # NOQA -import ruamel.yaml -from roundtrip import round_trip, dedent +# import ruamel.yaml +from roundtrip import round_trip class TestProgramConfig: diff --git a/_test/test_string.py b/_test/test_string.py index 8e85cdf..5aa0700 100644 --- a/_test/test_string.py +++ b/_test/test_string.py @@ -1,3 +1,4 @@ +# coding: utf-8 from __future__ import print_function @@ -17,9 +18,8 @@ and the chomping modifiers: import pytest import platform -import ruamel.yaml -from ruamel.yaml.compat import ordereddict -from roundtrip import round_trip, dedent, round_trip_load, round_trip_dump +# from ruamel.yaml.compat import ordereddict +from roundtrip import round_trip, dedent, round_trip_load, round_trip_dump # NOQA class TestYAML: @@ -34,7 +34,7 @@ class TestYAML: """) @pytest.mark.skipif(platform.python_implementation() == 'Jython', - reason="Jython throws RepresenterError") + reason="Jython throws RepresenterError") def test_preserve_string(self): round_trip(""" a: | @@ -43,7 +43,7 @@ class TestYAML: """, intermediate=dict(a='abc\ndef\n')) @pytest.mark.skipif(platform.python_implementation() == 'Jython', - reason="Jython throws RepresenterError") + reason="Jython throws RepresenterError") def test_preserve_string_strip(self): s = """ a: |- @@ -54,7 +54,7 @@ class TestYAML: round_trip(s, intermediate=dict(a='abc\ndef')) @pytest.mark.skipif(platform.python_implementation() == 'Jython', - reason="Jython throws RepresenterError") + reason="Jython throws RepresenterError") def test_preserve_string_keep(self): # with pytest.raises(AssertionError) as excinfo: round_trip(""" @@ -67,7 +67,7 @@ class TestYAML: """, intermediate=dict(a='ghi\njkl\n\n\n', b='x')) @pytest.mark.skipif(platform.python_implementation() == 'Jython', - reason="Jython throws RepresenterError") + reason="Jython throws RepresenterError") def test_preserve_string_keep_at_end(self): # at EOF you have to specify the ... to get proper "closure" # of the multiline scalar @@ -80,7 +80,7 @@ class TestYAML: """, intermediate=dict(a='ghi\njkl\n\n')) def test_fold_string(self): - with pytest.raises(AssertionError) as excinfo: + with pytest.raises(AssertionError) as excinfo: # NOQA round_trip(""" a: > abc @@ -89,7 +89,7 @@ class TestYAML: """, intermediate=dict(a='abc def\n')) def test_fold_string_strip(self): - with pytest.raises(AssertionError) as excinfo: + with pytest.raises(AssertionError) as excinfo: # NOQA round_trip(""" a: >- abc @@ -98,7 +98,7 @@ class TestYAML: """, intermediate=dict(a='abc def')) def test_fold_string_keep(self): - with pytest.raises(AssertionError) as excinfo: + with pytest.raises(AssertionError) as excinfo: # NOQA round_trip(""" a: >+ abc diff --git a/_test/test_yamlfile.py b/_test/test_yamlfile.py index 1433820..9b224b8 100644 --- a/_test/test_yamlfile.py +++ b/_test/test_yamlfile.py @@ -6,12 +6,12 @@ various test cases for YAML files """ import sys -import pytest +import pytest # NOQA import platform import ruamel.yaml from ruamel.yaml.compat import ordereddict -from roundtrip import round_trip, dedent, round_trip_load, round_trip_dump +from roundtrip import round_trip, dedent, round_trip_load, round_trip_dump # NOQA class TestYAML: @@ -54,7 +54,7 @@ class TestYAML: - b: 2 """) - @pytest.mark.skipif(sys.version_info >= (3, 0) or \ + @pytest.mark.skipif(sys.version_info >= (3, 0) or platform.python_implementation() != "CPython", reason="ruamel.yaml not available") def test_dump_ruamel_ordereddict(self): @@ -83,7 +83,7 @@ class TestYAML: def test_set_out(self): # preferable would be the shorter format without the ': null' - from ruamel.yaml.compat import ordereddict + # from ruamel.yaml.compat import ordereddict x = set(['a', 'b', 'c']) res = ruamel.yaml.dump(x, default_flow_style=False) assert res == dedent(""" @@ -123,7 +123,7 @@ class TestYAML: """) @pytest.mark.skipif(platform.python_implementation() == 'Jython', - reason="Jython throws RepresenterError") + reason="Jython throws RepresenterError") def test_blank_line_after_literal_chip(self): s = """ c: @@ -146,7 +146,7 @@ class TestYAML: assert d['c'][1].split('line.')[1] == '\n' @pytest.mark.skipif(platform.python_implementation() == 'Jython', - reason="Jython throws RepresenterError") + reason="Jython throws RepresenterError") def test_blank_line_after_literal_keep(self): """ have to insert an eof marker in YAML to test this""" s = """ @@ -171,7 +171,7 @@ class TestYAML: assert d['c'][1].split('line.')[1] == '\n\n\n' @pytest.mark.skipif(platform.python_implementation() == 'Jython', - reason="Jython throws RepresenterError") + reason="Jython throws RepresenterError") def test_blank_line_after_literal_strip(self): s = """ c: @@ -192,4 +192,3 @@ class TestYAML: round_trip(s) assert d['c'][0].split('it.')[1] == '' assert d['c'][1].split('line.')[1] == '' - diff --git a/_test/test_z_data.py b/_test/test_z_data.py index a35bdbd..2145a19 100644 --- a/_test/test_z_data.py +++ b/_test/test_z_data.py @@ -3,8 +3,8 @@ from __future__ import print_function import sys import os -import pytest -import platform +import pytest # NOQA +import platform # NOQA sys.path.insert(0, os.path.dirname(__file__) + '/lib') diff --git a/comments.py b/comments.py index 5db056f..f82e1c4 100644 --- a/comments.py +++ b/comments.py @@ -25,6 +25,7 @@ line_col_attrib = '_yaml_line_col' anchor_attrib = '_yaml_anchor' merge_attrib = '_yaml_merge' + class Comment(object): # sys.getsize tested the Comment objects, __slots__ make them bigger # and adding self.end did not matter @@ -63,7 +64,7 @@ class Comment(object): def start(self): return self._start - @end.setter + @start.setter def start(self, value): self._start = value @@ -138,6 +139,7 @@ class Anchor(object): self.value = None self.always_dump = False + class CommentedBase(object): @property def ca(self): @@ -243,6 +245,7 @@ class CommentedBase(object): self.anchor.value = value self.anchor.always_dump = always_dump + class CommentedSeq(list, CommentedBase): __slots__ = [Comment.attrib, ] @@ -355,6 +358,7 @@ class CommentedMap(ordereddict, CommentedBase): if not isinstance(key, list): return self.get(key, default) # assume that the key is a list of recursively accessible dicts + def get_one_level(key_list, level, d): if not list_ok: assert isinstance(d, dict) @@ -370,7 +374,7 @@ class CommentedMap(ordereddict, CommentedBase): return default except (TypeError, IndexError): if not list_ok: - Raise + raise return default def __getitem__(self, key): @@ -398,7 +402,6 @@ class CommentedMap(ordereddict, CommentedBase): self.merge.extend(value) - class CommentedOrderedMap(CommentedMap): __slots__ = [Comment.attrib, ] diff --git a/composer.py b/composer.py index a6bf24f..6a7e439 100644 --- a/composer.py +++ b/composer.py @@ -5,13 +5,13 @@ __all__ = ['Composer', 'ComposerError'] try: from .error import MarkedYAMLError - from .events import * - from .nodes import * + from .events import * # NOQA + from .nodes import * # NOQA from .compat import utf8 except (ImportError, ValueError): # for Jython from ruamel.yaml.error import MarkedYAMLError - from ruamel.yaml.events import * - from ruamel.yaml.nodes import * + from ruamel.yaml.events import * # NOQA + from ruamel.yaml.nodes import * # NOQA from ruamel.yaml.compat import utf8 diff --git a/configobjwalker.py b/configobjwalker.py index 576adcd..1fe6f35 100644 --- a/configobjwalker.py +++ b/configobjwalker.py @@ -47,19 +47,19 @@ def _walk_section(s, level=0): for val in _walk_section(s[name], level=level+1): yield val -##def config_obj_2_rt_yaml(cfg): -## from .comments import CommentedMap, CommentedSeq -## from configobj import ConfigObj -## assert isinstance(cfg, ConfigObj) -## #for c in cfg.initial_comment: -## # if c.strip(): -## # pass -## cm = CommentedMap() -## for name in s.sections: -## cm[name] = d = CommentedMap() -## -## -## #for c in cfg.final_comment: -## # if c.strip(): -## # yield c -## return cm +# def config_obj_2_rt_yaml(cfg): +# from .comments import CommentedMap, CommentedSeq +# from configobj import ConfigObj +# assert isinstance(cfg, ConfigObj) +# #for c in cfg.initial_comment: +# # if c.strip(): +# # pass +# cm = CommentedMap() +# for name in s.sections: +# cm[name] = d = CommentedMap() +# +# +# #for c in cfg.final_comment: +# # if c.strip(): +# # yield c +# return cm diff --git a/constructor.py b/constructor.py index 58a4689..c3b5a59 100644 --- a/constructor.py +++ b/constructor.py @@ -13,19 +13,19 @@ import sys import types try: - from .error import * - from .nodes import * + from .error import * # NOQA + from .nodes import * # NOQA from .compat import (utf8, builtins_module, to_str, PY2, PY3, ordereddict, text_type) - from .comments import * - from .scalarstring import * + from .comments import * # NOQA + from .scalarstring import * # NOQA except (ImportError, ValueError): # for Jython - from ruamel.yaml.error import * - from ruamel.yaml.nodes import * - from ruamel.yaml.compat import (utf8, builtins_module, to_str, PY2, PY3, + from ruamel.yaml.error import * # NOQA + from ruamel.yaml.nodes import * # NOQA + from ruamel.yaml.compat import (utf8, builtins_module, to_str, PY2, PY3, ordereddict, text_type) - from ruamel.yaml.comments import * - from ruamel.yaml.scalarstring import * + from ruamel.yaml.comments import * # NOQA + from ruamel.yaml.scalarstring import * # NOQA class ConstructorError(MarkedYAMLError): @@ -372,7 +372,7 @@ class SafeConstructor(BaseConstructor): (?::(?P<tz_minute>[0-9][0-9]))?))?)?$''', re.X) def construct_yaml_timestamp(self, node): - value = self.construct_scalar(node) + value = self.construct_scalar(node) # NOQA match = self.timestamp_regexp.match(node.value) values = match.groupdict() year = int(values['year']) @@ -873,7 +873,7 @@ class RoundTripConstructor(SafeConstructor): value = self.construct_object(value_node, deep=False) return value - #merge = [] + # merge = [] merge_map_list = [] index = 0 while index < len(node.value): @@ -883,10 +883,10 @@ class RoundTripConstructor(SafeConstructor): if isinstance(value_node, MappingNode): merge_map_list.append( (index, constructed(value_node))) - #self.flatten_mapping(value_node) - #merge.extend(value_node.value) + # self.flatten_mapping(value_node) + # merge.extend(value_node.value) elif isinstance(value_node, SequenceNode): - #submerge = [] + # submerge = [] for subnode in value_node.value: if not isinstance(subnode, MappingNode): raise ConstructorError( @@ -896,11 +896,11 @@ class RoundTripConstructor(SafeConstructor): % subnode.id, subnode.start_mark) merge_map_list.append( (index, constructed(subnode))) - # self.flatten_mapping(subnode) - # submerge.append(subnode.value) - #submerge.reverse() - #for value in submerge: - # merge.extend(value) + # self.flatten_mapping(subnode) + # submerge.append(subnode.value) + # submerge.reverse() + # for value in submerge: + # merge.extend(value) else: raise ConstructorError( "while constructing a mapping", node.start_mark, @@ -912,10 +912,10 @@ class RoundTripConstructor(SafeConstructor): index += 1 else: index += 1 - #print ('merge_map_list', merge_map_list) + # print ('merge_map_list', merge_map_list) return merge_map_list - #if merge: - # node.value = merge + node.value + # if merge: + # node.value = merge + node.value def construct_mapping(self, node, maptyp, deep=False): if not isinstance(node, MappingNode): @@ -963,7 +963,7 @@ class RoundTripConstructor(SafeConstructor): maptyp._yaml_add_comment(value_node.comment, value=key) maptyp._yaml_set_kv_line_col( key, [key_node.start_mark.line, key_node.start_mark.column, - value_node.start_mark.line, value_node.start_mark.column]) + value_node.start_mark.line, value_node.start_mark.column]) maptyp[key] = value def construct_setting(self, node, typ, deep=False): @@ -1000,7 +1000,7 @@ class RoundTripConstructor(SafeConstructor): raise ConstructorError( "while constructing a mapping", node.start_mark, "found unhashable key", key_node.start_mark) - value = self.construct_object(value_node, deep=deep) + value = self.construct_object(value_node, deep=deep) # NOQA if key_node.comment: typ._yaml_add_comment(key_node.comment, key=key) if value_node.comment: @@ -6,15 +6,15 @@ __all__ = ['CBaseLoader', 'CSafeLoader', 'CLoader', from _ruamel_yaml import CParser, CEmitter try: - from .constructor import * - from .serializer import * - from .representer import * - from .resolver import * + from .constructor import * # NOQA + from .serializer import * # NOQA + from .representer import * # NOQA + from .resolver import * # NOQA except (ImportError, ValueError): # for Jython - from ruamel.yaml.constructor import * - from ruamel.yaml.serializer import * - from ruamel.yaml.representer import * - from ruamel.yaml.resolver import * + from ruamel.yaml.constructor import * # NOQA + from ruamel.yaml.serializer import * # NOQA + from ruamel.yaml.representer import * # NOQA + from ruamel.yaml.resolver import * # NOQA class CBaseLoader(CParser, BaseConstructor, BaseResolver): @@ -3,16 +3,15 @@ from __future__ import absolute_import __all__ = ['BaseDumper', 'SafeDumper', 'Dumper', 'RoundTripDumper'] try: - from .emitter import * - from .serializer import * - from .representer import * - from .resolver import * + from .emitter import * # NOQA + from .serializer import * # NOQA + from .representer import * # NOQA + from .resolver import * # NOQA except (ImportError, ValueError): # for Jython - from ruamel.yaml.emitter import * - from ruamel.yaml.serializer import * - from ruamel.yaml.representer import * - from ruamel.yaml.resolver import * - + from ruamel.yaml.emitter import * # NOQA + from ruamel.yaml.serializer import * # NOQA + from ruamel.yaml.representer import * # NOQA + from ruamel.yaml.resolver import * # NOQA class BaseDumper(Emitter, Serializer, BaseRepresenter, BaseResolver): @@ -12,15 +12,14 @@ __all__ = ['Emitter', 'EmitterError'] try: from .error import YAMLError - from .events import * + from .events import * # NOQA from .compat import utf8, text_type, PY2, nprint, dbg, DBG_EVENT except (ImportError, ValueError): # for Jython from ruamel.yaml.error import YAMLError - from ruamel.yaml.events import * + from ruamel.yaml.events import * # NOQA from ruamel.yaml.compat import utf8, text_type, PY2, nprint, dbg, DBG_EVENT - class EmitterError(YAMLError): pass @@ -213,10 +212,12 @@ class Emitter(object): handle_text = self.prepare_tag_handle(handle) prefix_text = self.prepare_tag_prefix(prefix) self.write_tag_directive(handle_text, prefix_text) - implicit = (first and not self.event.explicit - and not self.canonical - and not self.event.version and not self.event.tags - and not self.check_empty_document()) + implicit = (first and + not self.event.explicit and + not self.canonical and + not self.event.version and + not self.event.tags and + not self.check_empty_document()) if not implicit: self.write_indent() self.write_indicator(u'---', True) @@ -765,7 +766,7 @@ class Emitter(object): if not (ch == u'\n' or u'\x20' <= ch <= u'\x7E'): if (ch == u'\x85' or u'\xA0' <= ch <= u'\uD7FF' or u'\uE000' <= ch <= u'\uFFFD') and ch != u'\uFEFF': - unicode_characters = True + # unicode_characters = True if not self.allow_unicode: special_characters = True else: @@ -1205,6 +1206,7 @@ class Emitter(object): def write_comment(self, comment): value = comment.value + # print('{:02d} {:02d} {}'.format(self.column, comment.start_mark.column, value)) if value[-1] == '\n': value = value[:-1] try: @@ -1220,7 +1222,16 @@ class Emitter(object): value = value.encode('utf-8') except UnicodeDecodeError: pass - self.stream.write(' ' * (col - self.column) + value) + try: + # at least one space if the current column >= the start column of the comment + # but not at the start of a line + nr_spaces = col - self.column + if self.column and value.strip() and nr_spaces < 1: + nr_spaces = 1 + self.stream.write(' ' * nr_spaces + value) + except TypeError: + print('TypeError while trying to write', repr(value), type(value)) + raise self.write_line_break() def write_pre_comment(self, event): @@ -8,7 +8,6 @@ except (ImportError, ValueError): # for Jython from ruamel.yaml.compat import utf8 - class Mark(object): def __init__(self, name, index, line, column, buffer, pointer): self.name = name @@ -3,20 +3,19 @@ from __future__ import absolute_import __all__ = ['BaseLoader', 'SafeLoader', 'Loader', 'RoundTripLoader'] try: - from .reader import * - from .scanner import * - from .parser_ import * - from .composer import * - from .constructor import * - from .resolver import * + from .reader import * # NOQA + from .scanner import * # NOQA + from .parser_ import * # NOQA + from .composer import * # NOQA + from .constructor import * # NOQA + from .resolver import * # NOQA except (ImportError, ValueError): # for Jython - from ruamel.yaml.reader import * - from ruamel.yaml.scanner import * - from ruamel.yaml.parser_ import * - from ruamel.yaml.composer import * - from ruamel.yaml.constructor import * - from ruamel.yaml.resolver import * - + from ruamel.yaml.reader import * # NOQA + from ruamel.yaml.scanner import * # NOQA + from ruamel.yaml.parser_ import * # NOQA + from ruamel.yaml.composer import * # NOQA + from ruamel.yaml.constructor import * # NOQA + from ruamel.yaml.resolver import * # NOQA class BaseLoader(Reader, Scanner, Parser, Composer, BaseConstructor, @@ -3,17 +3,18 @@ from __future__ import absolute_import -from ruamel.yaml.error import * +from ruamel.yaml.error import * # NOQA -from ruamel.yaml.tokens import * -from ruamel.yaml.events import * -from ruamel.yaml.nodes import * +from ruamel.yaml.tokens import * # NOQA +from ruamel.yaml.events import * # NOQA +from ruamel.yaml.nodes import * # NOQA -from ruamel.yaml.loader import * -from ruamel.yaml.dumper import * +from ruamel.yaml.loader import * # NOQA +from ruamel.yaml.dumper import * # NOQA from ruamel.yaml.compat import StringIO, BytesIO, with_metaclass, PY3 -import io +# import io + def scan(stream, Loader=Loader): """ @@ -348,5 +349,3 @@ class YAMLObject(with_metaclass(YAMLObjectMetaclass)): """ return dumper.represent_yaml_object(cls.yaml_tag, data, cls, flow_style=cls.yaml_flow_style) - - @@ -73,19 +73,18 @@ __all__ = ['Parser', 'ParserError'] try: from .error import MarkedYAMLError - from .tokens import * - from .events import * - from .scanner import * + from .tokens import * # NOQA + from .events import * # NOQA + from .scanner import * # NOQA from .compat import utf8 except (ImportError, ValueError): # for Jython from ruamel.yaml.error import MarkedYAMLError - from ruamel.yaml.tokens import * - from ruamel.yaml.events import * - from ruamel.yaml.scanner import * + from ruamel.yaml.tokens import * # NOQA + from ruamel.yaml.events import * # NOQA + from ruamel.yaml.scanner import * # NOQA from ruamel.yaml.compat import utf8 - class ParserError(MarkedYAMLError): pass @@ -31,7 +31,6 @@ except (ImportError, ValueError): # for Jython from ruamel.yaml.compat import text_type, binary_type, PY3 - class ReaderError(YAMLError): def __init__(self, name, position, character, encoding, reason): diff --git a/representer.py b/representer.py index ae8f3b0..22cf720 100644 --- a/representer.py +++ b/representer.py @@ -5,17 +5,15 @@ __all__ = ['BaseRepresenter', 'SafeRepresenter', 'Representer', 'RepresenterError', 'RoundTripRepresenter'] try: - from .error import * - from .nodes import * - from .compat import text_type, binary_type, to_unicode, PY2, PY3, \ - ordereddict, nprint - from .scalarstring import * + from .error import * # NOQA + from .nodes import * # NOQA + from .compat import text_type, binary_type, to_unicode, PY2, PY3, ordereddict + from .scalarstring import * # NOQA except (ImportError, ValueError): # for Jython - from ruamel.yaml.error import * - from ruamel.yaml.nodes import * - from ruamel.yaml.compat import text_type, binary_type, to_unicode, PY2, \ - PY3, ordereddict, nprint - from ruamel.yaml.scalarstring import * + from ruamel.yaml.error import * # NOQA + from ruamel.yaml.nodes import * # NOQA + from ruamel.yaml.compat import text_type, binary_type, to_unicode, PY2, PY3, ordereddict + from ruamel.yaml.scalarstring import * # NOQA import datetime @@ -576,11 +574,10 @@ Representer.add_multi_representer(object, try: from .comments import CommentedMap, CommentedOrderedMap, CommentedSeq, \ - CommentedSet, comment_attrib, merge_attrib + CommentedSet, comment_attrib, merge_attrib except ImportError: # for Jython from ruamel.yaml.comments import CommentedMap, CommentedOrderedMap, \ - CommentedSeq, CommentedSet, comment_attrib, merge_attrib - + CommentedSeq, CommentedSet, comment_attrib, merge_attrib class RoundTripRepresenter(SafeRepresenter): @@ -818,6 +815,7 @@ class RoundTripRepresenter(SafeRepresenter): node_value.style): best_style = False value.append((node_key, node_value)) + best_style = best_style return node diff --git a/resolver.py b/resolver.py index bae0caa..04dfcf4 100644 --- a/resolver.py +++ b/resolver.py @@ -3,12 +3,12 @@ from __future__ import absolute_import __all__ = ['BaseResolver', 'Resolver'] try: - from .error import * - from .nodes import * + from .error import * # NOQA + from .nodes import * # NOQA from .compat import string_types except (ImportError, ValueError): # for Jython - from ruamel.yaml.error import * - from ruamel.yaml.nodes import * + from ruamel.yaml.error import * # NOQA + from ruamel.yaml.nodes import * # NOQA from ruamel.yaml.compat import string_types diff --git a/scalarstring.py b/scalarstring.py index 59951c9..48636f4 100644 --- a/scalarstring.py +++ b/scalarstring.py @@ -9,7 +9,6 @@ except (ImportError, ValueError): # for Jython from ruamel.yaml.compat import text_type - class ScalarString(text_type): def __new__(cls, *args, **kw): return text_type.__new__(cls, *args, **kw) @@ -19,6 +18,7 @@ class PreservedScalarString(ScalarString): def __new__(cls, value): return ScalarString.__new__(cls, value) + def preserve_literal(s): return PreservedScalarString(s.replace('\r\n', '\n').replace('\r', '\n')) @@ -31,7 +31,6 @@ def walk_tree(base): """ from ruamel.yaml.compat import string_types - if isinstance(base, dict): for k in base: v = base[k] @@ -33,15 +33,14 @@ __all__ = ['Scanner', 'RoundTripScanner', 'ScannerError'] try: from .error import MarkedYAMLError - from .tokens import * + from .tokens import * # NOQA from .compat import utf8, unichr, PY3 except (ImportError, ValueError): # for Jython from ruamel.yaml.error import MarkedYAMLError - from ruamel.yaml.tokens import * + from ruamel.yaml.tokens import * # NOQA from ruamel.yaml.compat import utf8, unichr, PY3 - class ScannerError(MarkedYAMLError): pass @@ -1381,7 +1380,6 @@ class Scanner(object): token.add_post_comment(comment) return token - def scan_plain_spaces(self, indent, start_mark): # See the specification for details. # The specification is really confusing about tabs in plain scalars. diff --git a/serializer.py b/serializer.py index 125729e..b461ca6 100644 --- a/serializer.py +++ b/serializer.py @@ -6,17 +6,16 @@ import re try: from .error import YAMLError - from .events import * - from .nodes import * + from .events import * # NOQA + from .nodes import * # NOQA from .compat import nprint, DBG_NODE, dbg except (ImportError, ValueError): # for Jython from ruamel.yaml.error import YAMLError - from ruamel.yaml.events import * - from ruamel.yaml.nodes import * + from ruamel.yaml.events import * # NOQA + from ruamel.yaml.nodes import * # NOQA from ruamel.yaml.compat import nprint, DBG_NODE, dbg - class SerializerError(YAMLError): pass @@ -27,7 +26,6 @@ class Serializer(object): ANCHOR_TEMPLATE = u'id%03d' ANCHOR_RE = re.compile(u'id(?!000$)\\d{3,}') - def __init__(self, encoding=None, explicit_start=None, explicit_end=None, version=None, tags=None): self.use_encoding = encoding @@ -168,5 +166,6 @@ class Serializer(object): self.emit(MappingEndEvent(comment=[map_comment, end_comment])) self.ascend_resolver() + def templated_id(s): return Serializer.ANCHOR_RE.match(s) @@ -548,6 +548,12 @@ class NameSpacePackager(object): return None if sys.platform == "win32" and not self._pkg_data.get('win32bin'): return None + try: + plat = sys.argv.index('--plat-name') + if 'win' in sys.argv[plat+1]: + return None + except ValueError: + pass import tempfile import shutil from textwrap import dedent @@ -622,8 +628,6 @@ class NameSpacePackager(object): print("\n\n>>>>>> LICENSE file not found <<<<<\n\n") if self._pkg_data.get('universal'): fp.write('[bdist_wheel]\nuniversal = 1\n') - else: - fp.write('[bdist_wheel]\nuniversal = 0\n') try: setup(**kw) except: @@ -633,11 +637,6 @@ class NameSpacePackager(object): return True -class BinaryDistribution(Distribution): - def is_pure(self): - return False - - # # call setup def main(): dump_kw = '--dump-kw' @@ -668,7 +667,6 @@ def main(): keywords=nsp.keywords, package_data=nsp.package_data, ext_modules=nsp.ext_modules, - distclass=BinaryDistribution, ) if '--version' not in sys.argv and ('--verbose' in sys.argv or dump_kw in sys.argv): for k in sorted(kw): @@ -189,4 +189,4 @@ class CommentToken(Token): def reset(self): if hasattr(self, 'pre_done'): - delattr(self, 'pre_done')
\ No newline at end of file + delattr(self, 'pre_done') @@ -14,7 +14,7 @@ norecursedirs = test/lib .tox [testenv:pep8] commands = - flake8 {posargs} + flake8 --exclude convert,cmd {posargs} [flake8] show-source = True |