You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am currently inheriting the Emitter class and injecting it in my YAML instance
importruamel.yamlasyamlfromruamel.yaml.emitterimportEmitterasBaseEmitterfromruamel.yaml.eventsimportSequenceEndEvent# This inheritance is made in order to add leading and trealing spaces in sequences# [item] -> [ item ]classEmitter(BaseEmitter):
defexpect_first_flow_sequence_item(self) ->None:
ifisinstance(self.event, SequenceEndEvent):
self.indent=self.indents.pop()
popped=self.flow_context.pop()
assertpopped=="["# noqaself.write_indicator(self.flow_seq_end, True) # EDITED <-----------------------------------------------ifself.event.commentandself.event.comment[0]:
# eol comment on empty flow sequenceself.write_post_comment(self.event)
elifself.flow_level==0:
self.write_line_break()
self.state=self.states.pop()
else:
self.write_indicator("", True) # ADDED <-----------------------------------------------ifself.canonicalorself.column>self.best_width:
self.write_indent()
self.states.append(self.expect_flow_sequence_item)
self.expect_node(sequence=True)
defexpect_flow_sequence_item(self) ->None:
ifisinstance(self.event, SequenceEndEvent):
self.indent=self.indents.pop()
popped=self.flow_context.pop()
assertpopped=="["# noqaifself.canonical:
# ToDo: so-39595807, maybe add a space to the flow_seq_separator# and strip the last space, if space then indent, else do not# not sure that [1,2,3] is a valid YAML seqself.write_indicator(self.flow_seq_separator, False)
self.write_indent()
self.write_indicator(self.flow_seq_end, True) # EDITED <-----------------------------------------------ifself.event.commentandself.event.comment[0]:
# eol comment on flow sequenceself.write_post_comment(self.event)
else:
self.no_newline=Falseself.state=self.states.pop()
else:
self.write_indicator(self.flow_seq_separator, False)
ifself.canonicalorself.column>self.best_width:
self.write_indent()
self.states.append(self.expect_flow_sequence_item)
self.expect_node(sequence=True)
ruamel=yaml.YAML(typ=typ)
ruamel.Emitter=Emitter
Modification proposal
As we can see, the correction to do is very small. I would like to add an option to control the number of spaces at the start/end of the sequence that would only be used here. I can make the PR but I want to confirm that someone will be checking, hopefully approving it, and that the names chosen will be validated.
Thank you
The text was updated successfully, but these errors were encountered:
Issue Description
Dumping a flow sequence does not allow much control over the spacing.
I can for example generate this sequence:
[item1, item2, item3]
but this is not compliant with a possible yamllint configuration like this one:
We need to be able to generate the following
[ item1, item2, item3 ]
Workaround
I am currently inheriting the Emitter class and injecting it in my
YAML
instanceModification proposal
As we can see, the correction to do is very small. I would like to add an option to control the number of spaces at the start/end of the sequence that would only be used here. I can make the PR but I want to confirm that someone will be checking, hopefully approving it, and that the names chosen will be validated.
Thank you
The text was updated successfully, but these errors were encountered: