Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent long lines getting wrapped in ruamel.yaml

I use the load_yaml_guess_indent(f, preserve_quotes=True) to read a YAML file, then modify it and write it back. I noticed long lines are getting wrapped when they are written back. (A line break is inserted after 80-85 characters.) Is there a parameter I can pass to stop this from happening?

like image 466
keheliya Avatar asked Feb 11 '17 00:02

keheliya


1 Answers

These are the parameters you can hand in to round_trip_dump():

def round_trip_dump(data, stream=None, Dumper=RoundTripDumper,
                default_style=None, default_flow_style=None,
                canonical=None, indent=None, width=None,
                allow_unicode=None, line_break=None,
                encoding=enc, explicit_start=None, explicit_end=None,
                version=None, tags=None, block_seq_indent=None,
                top_level_colon_align=None, prefix_colon=None):

The one you are looking for is width

If you are using the new (ruamel.yaml >= 0.15 ) API, most of these parameters directly translate to attributes on the YAML instance you create, so in that case you would do:

yaml = ruamel.yaml.YAML()
yaml.width = 4096  # or some other big enough value to prevent line-wrap
yaml.dump(data, stream=your_stream)
like image 73
Anthon Avatar answered Sep 19 '22 02:09

Anthon