@@ -74,6 +74,13 @@ def convert_target(self):
7474 def storevalues (self , output ):
7575 self .storevalue (output , self .convert_target ())
7676
77+ def str_representor (dumper , data ):
78+ # https://stackoverflow.com/questions/8640959/how-can-i-control-what-scalar-form-pyyaml-uses-for-my-data
79+ if len (data .splitlines ()) > 1 or '\n ' in data :
80+ return dumper .represent_scalar ('tag:yaml.org,2002:str' , data , style = '|' )
81+ if len (data ) > 60 :
82+ return dumper .represent_scalar ('tag:yaml.org,2002:str' , data , style = '>' )
83+ return dumper .represent_scalar ('tag:yaml.org,2002:str' , data , style = '"' )
7784
7885class YAMLFile (base .DictStore ):
7986 """A YAML file."""
@@ -101,6 +108,13 @@ def yaml(self):
101108 yaml = YAML ()
102109 for arg , value in self .dump_args .items ():
103110 setattr (yaml , arg , value )
111+
112+ yaml .width = 65536
113+ yaml .default_flow_style = False
114+ yaml .preserve_quotes = False
115+ yaml .indent (sequence = 2 , offset = 4 )
116+ yaml .representer .add_representer (str , str_representor )
117+
104118 return yaml
105119
106120 def serialize (self , out ):
0 commit comments