Community modules (#24848)

This commit is contained in:
Nick Brassel 2025-02-26 22:25:41 +11:00 committed by GitHub
parent 63b095212b
commit 1efc82403b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
37 changed files with 987 additions and 84 deletions

View file

@ -98,11 +98,14 @@ def in_virtualenv():
return active_prefix != sys.prefix
def dump_lines(output_file, lines, quiet=True):
def dump_lines(output_file, lines, quiet=True, remove_repeated_newlines=False):
"""Handle dumping to stdout or file
Creates parent folders if required
"""
generated = '\n'.join(lines) + '\n'
if remove_repeated_newlines:
while '\n\n\n' in generated:
generated = generated.replace('\n\n\n', '\n\n')
if output_file and output_file.name != '-':
output_file.parent.mkdir(parents=True, exist_ok=True)
if output_file.exists():