File tree Expand file tree Collapse file tree 1 file changed +14
-12
lines changed Expand file tree Collapse file tree 1 file changed +14
-12
lines changed Original file line number Diff line number Diff line change @@ -744,22 +744,24 @@ def write_uncommented(target, f):
744
744
A block is a sequence of non-empty lines separated by empty lines.
745
745
"""
746
746
block = []
747
- is_comment = True
747
+
748
+ def flush (last ):
749
+ # If the block is entiry made of comments, ignore it
750
+ entire_block_comments = all (ln .startswith ("#" ) or ln == "" for ln in block )
751
+ if not entire_block_comments and len (block ) > 0 :
752
+ for line in block :
753
+ f .write (line + "\n " )
754
+ # Required to output a newline before the start of a new section
755
+ if last :
756
+ f .write ("\n " )
757
+ block .clear ()
748
758
749
759
for line in target :
750
760
block .append (line )
751
761
if len (line ) == 0 :
752
- if not is_comment :
753
- for ln in block :
754
- f .write (ln + "\n " )
755
- block = []
756
- is_comment = True
757
- continue
758
- is_comment = is_comment and line .startswith ("#" )
759
- # Write the last accumulated block
760
- if len (block ) > 0 and not is_comment :
761
- for ln in block :
762
- f .write (ln + "\n " )
762
+ flush (last = False )
763
+
764
+ flush (last = True )
763
765
return f
764
766
765
767
You can’t perform that action at this time.
0 commit comments