Disable ruamel automagic line wrapping

Recent releases of ruamel have resulted in weird linewrapping. Ruamel
seems to be aware of this based on the ToDo comment in the diff that
introduced the behavior [0]. Rather than fight this by continuing to
exclude ruamel releases we simply set the width to wrap on to the max
int size. This solution was inspired by this Github comment [1].

This means that we will be responsible for line wrapping on widths
manually. I think that is a reasonable compromise if it gives us more
predictable results.

[0] 375c4db4c7/tree/emitter.py
[1] https://github.com/iterative/dvc/issues/9397#issuecomment-1534045898

Change-Id: I9a8f831009f4811b3633847094bca7b71169bedb
This commit is contained in:
Clark Boylan
2025-09-03 15:05:39 -07:00
parent 506e05fde1
commit 9b8a1f2796

View File

@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
import ruamel.yaml
@@ -27,6 +29,9 @@ class YAML(object):
self.yaml.allow_duplicate_keys = True
self.yaml.representer.add_representer(type(None), none_representer)
self.yaml.indent(mapping=2, sequence=4, offset=2)
# Ruamel does weird things with linewrapping like adding extra
# whitespace at the end of lines. Just avoid wrapping entirely.
self.yaml.width = sys.maxsize
def load(self, stream):
return self.yaml.load(stream)