summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2016-04-19 10:09:54 +0200
committerAnthon van der Neut <anthon@mnt.org>2016-04-19 10:09:54 +0200
commit8ab6a692cc4cea1801dcf83157c333a67ca3d200 (patch)
tree4ad5b7d14a48dd65ec604afbf3d81794263f1200
parente59d6cd34c3e9fa5df9da18448063aff96eb57f1 (diff)
downloadruamel.yaml-8ab6a692cc4cea1801dcf83157c333a67ca3d200.tar.gz
allow "indent=2, block_seq_indent=2"0.11.10
-rw-r--r--CHANGES7
-rw-r--r--__init__.py2
-rw-r--r--_doc/detail.rst12
-rw-r--r--_test/roundtrip.py6
-rw-r--r--_test/test_indentation.py25
-rw-r--r--emitter.py16
6 files changed, 53 insertions, 15 deletions
diff --git a/CHANGES b/CHANGES
index f7590e6..1a14444 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,10 @@
+
+0.11.10 2016-04-19
+
+- indent=2, block_seq_indent=2 works as expected
+
+<To be updated>
+
0.10.11: 2015-09-17
- Fix issue 13: dependency on libyaml to be installed for yaml.h
diff --git a/__init__.py b/__init__.py
index 10de7b0..7a0c6f0 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, 11, 9),
+ version_info=(0, 11, 10),
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/detail.rst b/_doc/detail.rst
index 19142e2..1449023 100644
--- a/_doc/detail.rst
+++ b/_doc/detail.rst
@@ -63,10 +63,14 @@ indentation::
- 2
-If the ``block_seq_indent`` is only one less than the indent, there is
-not enough room to put the space that has to follow the dash. In that
-case the element is pushed to the next line. If you specify ``block_seq_indent>=indent``, then the emitter adjusts the ``indent`` value to equal
-``block_seq_indent + 1``.
+If the ``block_seq_indent`` equals ``indent``, there is not enough
+room for the dash and the space that has to follow. In that case the
+element itself would normally be pushed to the next line (and older versions
+of ruamel.yaml did so). But this is
+prevented from happening. However the ``indent`` level is what is used
+for calculating the cumulative indent for deeper levels and specifying
+``indent=3`` resp. ``block_seq_indent=2``, gives correct, but counter
+intuitive results.
Positioning ':' in top level mappings, prefix in ':'
----------------------------------------------------
diff --git a/_test/roundtrip.py b/_test/roundtrip.py
index b9cc657..d82c001 100644
--- a/_test/roundtrip.py
+++ b/_test/roundtrip.py
@@ -30,9 +30,9 @@ def round_trip_load(inp):
def round_trip_dump(data, indent=None, block_seq_indent=None, top_level_colon_align=None,
prefix_colon=None):
return ruamel.yaml.round_trip_dump(data,
- indent=indent, block_seq_indent=block_seq_indent,
- top_level_colon_align=top_level_colon_align,
- prefix_colon=prefix_colon)
+ indent=indent, block_seq_indent=block_seq_indent,
+ top_level_colon_align=top_level_colon_align,
+ prefix_colon=prefix_colon)
def round_trip(inp, outp=None, extra=None, intermediate=None, indent=None,
diff --git a/_test/test_indentation.py b/_test/test_indentation.py
index 954f231..9e35091 100644
--- a/_test/test_indentation.py
+++ b/_test/test_indentation.py
@@ -124,7 +124,7 @@ class TestIndent:
- 2
""", indent=3, block_seq_indent=0)
- def test_set_indent_3_block_list_indent_2(self):
+ def Xtest_set_indent_3_block_list_indent_2(self):
round_trip("""
a:
-
@@ -137,7 +137,16 @@ class TestIndent:
2
""", indent=3, block_seq_indent=2)
- def test_set_indent_2_block_list_indent_2(self):
+ def test_set_indent_3_block_list_indent_2(self):
+ round_trip("""
+ a:
+ - b: c
+ - 1
+ - d:
+ - 2
+ """, indent=3, block_seq_indent=2)
+
+ def Xtest_set_indent_2_block_list_indent_2(self):
round_trip("""
a:
-
@@ -150,6 +159,16 @@ class TestIndent:
2
""", indent=2, block_seq_indent=2)
+ # this is how it should be: block_seq_indent stretches the indent
+ def test_set_indent_2_block_list_indent_2(self):
+ round_trip("""
+ a:
+ - b: c
+ - 1
+ - d:
+ - 2
+ """, indent=2, block_seq_indent=2)
+
class TestYpkgIndent:
def test_00(self):
@@ -159,7 +178,7 @@ class TestYpkgIndent:
release : 1
homepage : http://www.nano-editor.org
source :
- - http://www.nano-editor.org/dist/v2.3/nano-2.3.2.tar.gz : ff309248071486445609ad4269b798262a1324d7503dc09dea289f5b60106be8
+ - http://www.nano-editor.org/dist/v2.3/nano-2.3.2.tar.gz : ff30924807ea289f5b60106be8
license : GPL-2.0
summary : GNU nano is an easy-to-use text editor
builddeps :
diff --git a/emitter.py b/emitter.py
index 3365210..b754bc0 100644
--- a/emitter.py
+++ b/emitter.py
@@ -90,6 +90,7 @@ class Emitter(object):
self.column = 0
self.whitespace = True
self.indention = True
+ self.no_newline = None # set if directly after `- `
# Whether the document requires an explicit document indicator
self.open_ended = False
@@ -106,8 +107,8 @@ class Emitter(object):
self.best_indent = 2
if indent and 1 < indent < 10:
self.best_indent = indent
- if self.best_indent < self.block_seq_indent + 1:
- self.best_indent = self.block_seq_indent + 1
+ # if self.best_indent < self.block_seq_indent + 1:
+ # self.best_indent = self.block_seq_indent + 1
self.best_width = 80
if width and width > self.best_indent*2:
self.best_width = width
@@ -177,6 +178,8 @@ class Emitter(object):
self.indent = 0
elif not indentless:
self.indent += self.best_indent
+ # if self.sequence_context and (self.block_seq_indent + 2) > self.best_indent:
+ # self.indent = self.block_seq_indent + 2
# States.
@@ -440,6 +443,8 @@ class Emitter(object):
self.write_pre_comment(self.event)
self.write_indent()
self.write_indicator((u' ' * self.block_seq_indent) + u'-', True, indention=True)
+ if self.block_seq_indent + 2 > self.best_indent:
+ self.no_newline = True
self.states.append(self.expect_block_sequence_item)
self.expect_node(sequence=True)
@@ -476,7 +481,7 @@ class Emitter(object):
def expect_block_mapping_simple_value(self):
if getattr(self.event, 'style', None) != '?':
- prefix = u''
+ # prefix = u''
if self.indent == 0 and self.top_level_colon_align is not None:
# write non-prefixed colon
c = u' ' * (self.top_level_colon_align - self.column) + self.colon
@@ -898,7 +903,10 @@ class Emitter(object):
indent = self.indent or 0
if not self.indention or self.column > indent \
or (self.column == indent and not self.whitespace):
- self.write_line_break()
+ if self.no_newline:
+ self.no_newline = False
+ else:
+ self.write_line_break()
if self.column < indent:
self.whitespace = True
data = u' '*(indent-self.column)