-
Notifications
You must be signed in to change notification settings - Fork 13.5k
configure.py: Write last key in each section #143606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
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
r? kobzol @lolbinarycat does it look right? :) |
I only changed |
Oh! I believe this is kinda an existing bug that just so happened to work before because the last block in a section was always the comments for the next section, while now those comments are considered technically part of the first item in a block. Still, I'm not sure if any other user of It would arguably be safer to modify In any case it would be nice to give @Kobzol I'll leave it up to you to make the final call, should we do this the "right" way (what the PR does now), or the way that is less likely to cause further regressions (making |
This comment has been minimized.
This comment has been minimized.
4ed5f06
to
b6d2130
Compare
Thanks for taking a look. I examined the function in detail and determined that it is too magical to be understood 😆 I tried to rewrite it like this, which hopefully makes it clearer: def write_uncommented(target, f):
"""Writes each block in 'target' that is not composed entirely of comments to 'f'.
A block is a sequence of non-empty lines separated by empty lines.
"""
block = []
def flush(last):
# If the block is entiry made of comments, ignore it
entire_block_comments = all(ln.startswith("#") or ln == "" for ln in block)
if not entire_block_comments and len(block) > 0:
for line in block:
f.write(line + "\n")
# Required to output a newline before the start of a new section
if last:
f.write("\n")
block.clear()
for line in target:
block.append(line)
if len(line) == 0:
flush(last=False)
flush(last=True)
return f What do you think of this? |
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