Skip to content

Commit 3ba8e33

Browse files
lambdageekKobzol
andcommitted
Rewrite for clarity
move common code to a helper function Co-Authored-By: Kobzol <berykubik@gmail.com>
1 parent b6d2130 commit 3ba8e33

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/bootstrap/configure.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -744,22 +744,24 @@ def write_uncommented(target, f):
744744
A block is a sequence of non-empty lines separated by empty lines.
745745
"""
746746
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()
748758

749759
for line in target:
750760
block.append(line)
751761
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)
763765
return f
764766

765767

0 commit comments

Comments
 (0)