Skip to content

Commit 448ca15

Browse files
authored
Rollup merge of #143606 - lambdageek:configure-write-last-key, r=Kobzol
configure.py: Write last key in each section The loop that writes the keys in each section of bootstrap.toml accumulates all the commented lines before a given key and emits them when it reaches the next key in the section. This ends up dropping lines accumulated for the last key Fixes #143605
2 parents 9b51f63 + 3ba8e33 commit 448ca15

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/bootstrap/configure.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -739,19 +739,29 @@ def configure_file(sections, top_level_keys, targets, config):
739739

740740

741741
def write_uncommented(target, f):
742+
"""Writes each block in 'target' that is not composed entirely of comments to 'f'.
743+
744+
A block is a sequence of non-empty lines separated by empty lines.
745+
"""
742746
block = []
743-
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()
744758

745759
for line in target:
746760
block.append(line)
747761
if len(line) == 0:
748-
if not is_comment:
749-
for ln in block:
750-
f.write(ln + "\n")
751-
block = []
752-
is_comment = True
753-
continue
754-
is_comment = is_comment and line.startswith("#")
762+
flush(last=False)
763+
764+
flush(last=True)
755765
return f
756766

757767

0 commit comments

Comments
 (0)