From dfaf6c806b5c11c7beb76d4d9208dda950cc27db Mon Sep 17 00:00:00 2001 From: Corentin de Boisset Date: Wed, 11 Feb 2026 14:53:55 +0100 Subject: [PATCH] Remove double newline at EOF of po files --- babel/messages/pofile.py | 22 +++++++++++++++++----- tests/messages/frontend/test_cli.py | 6 ------ tests/messages/frontend/test_extract.py | 4 ---- tests/messages/frontend/test_init.py | 6 ------ tests/messages/test_checkers.py | 6 ------ tests/messages/test_pofile_read.py | 1 - tests/messages/test_pofile_write.py | 2 -- 7 files changed, 17 insertions(+), 30 deletions(-) diff --git a/babel/messages/pofile.py b/babel/messages/pofile.py index b9678a924..03c0de271 100644 --- a/babel/messages/pofile.py +++ b/babel/messages/pofile.py @@ -665,10 +665,19 @@ def _format_message(message, prefix=''): yield f"{prefix}msgid {normalize(message.id, prefix=prefix, width=width)}\n" yield f"{prefix}msgstr {normalize(message.string or '', prefix=prefix, width=width)}\n" + first_message = True + for message in _sort_messages(catalog, sort_by=sort_by): - if not message.id: # This is the header "message" - if omit_header: - continue + is_header = not message.id + if is_header and omit_header: + continue + + if first_message: + first_message = False + else: + yield '\n' + + if is_header: comment_header = catalog.header_comment if width and width > 0: lines = [] @@ -718,17 +727,20 @@ def _format_message(message, prefix=''): yield from _format_comment(f'msgid_plural {norm_previous_id}', prefix='|') yield from _format_message(message) - yield '\n' if not ignore_obsolete: for message in _sort_messages( catalog.obsolete.values(), sort_by=sort_by, ): + if first_message: + first_message = False + else: + yield '\n' + for comment in message.user_comments: yield from _format_comment(comment) yield from _format_message(message, prefix='#~ ') - yield '\n' def _sort_messages( diff --git a/tests/messages/frontend/test_cli.py b/tests/messages/frontend/test_cli.py index 200632ec3..a09d8398e 100644 --- a/tests/messages/frontend/test_cli.py +++ b/tests/messages/frontend/test_cli.py @@ -164,7 +164,6 @@ def test_extract_with_default_mapping(cli, pot_file): msgid_plural "FooBars" msgstr[0] "" msgstr[1] "" - """ assert expected_content == pot_file.read_text() @@ -213,7 +212,6 @@ def test_extract_with_mapping_file(cli, pot_file): msgid_plural "foobars" msgstr[0] "" msgstr[1] "" - """ assert expected_content == pot_file.read_text() @@ -260,7 +258,6 @@ def test_extract_with_exact_file(cli, pot_file): msgid_plural "foobars" msgstr[0] "" msgstr[1] "" - """ assert expected_content == pot_file.read_text() @@ -308,7 +305,6 @@ def test_init_with_output_dir(cli): msgid_plural "foobars" msgstr[0] "" msgstr[1] "" - """ with open(po_file) as f: actual_content = f.read() @@ -357,7 +353,6 @@ def test_init_singular_plural_forms(cli): msgid "foobar" msgid_plural "foobars" msgstr[0] "" - """ with open(po_file) as f: actual_content = f.read() @@ -409,7 +404,6 @@ def test_init_more_than_2_plural_forms(cli): msgstr[0] "" msgstr[1] "" msgstr[2] "" - """ with open(po_file) as f: actual_content = f.read() diff --git a/tests/messages/frontend/test_extract.py b/tests/messages/frontend/test_extract.py index 712200fbb..295c114b5 100644 --- a/tests/messages/frontend/test_extract.py +++ b/tests/messages/frontend/test_extract.py @@ -148,7 +148,6 @@ def test_extraction_with_default_mapping(extract_cmd, pot_file): msgid_plural "FooBars" msgstr[0] "" msgstr[1] "" - """ assert expected_content == pot_file.read_text() @@ -196,7 +195,6 @@ def test_extraction_with_mapping_file(extract_cmd, pot_file): msgid_plural "foobars" msgstr[0] "" msgstr[1] "" - """ assert expected_content == pot_file.read_text() @@ -250,7 +248,6 @@ def test_extraction_with_mapping_dict(extract_cmd, pot_file, ignore_pattern): msgid_plural "foobars" msgstr[0] "" msgstr[1] "" - """ assert expected_content == pot_file.read_text() @@ -278,7 +275,6 @@ def test_extraction_add_location_file(extract_cmd, pot_file): msgid_plural "foobars" msgstr[0] "" msgstr[1] "" - """ assert expected_content == pot_file.read_text() diff --git a/tests/messages/frontend/test_init.py b/tests/messages/frontend/test_init.py index e69e5cce3..4287c5807 100644 --- a/tests/messages/frontend/test_init.py +++ b/tests/messages/frontend/test_init.py @@ -101,7 +101,6 @@ def test_with_output_dir(init_cmd): msgid_plural "foobars" msgstr[0] "" msgstr[1] "" - """ with open(get_po_file_path('en_US')) as f: actual_content = f.read() @@ -150,7 +149,6 @@ def test_keeps_catalog_non_fuzzy(init_cmd): msgid_plural "foobars" msgstr[0] "" msgstr[1] "" - """ with open(get_po_file_path('en_US')) as f: actual_content = f.read() @@ -201,7 +199,6 @@ def test_correct_init_more_than_2_plurals(init_cmd): msgstr[0] "" msgstr[1] "" msgstr[2] "" - """ with open(get_po_file_path('lv_LV')) as f: actual_content = f.read() @@ -249,7 +246,6 @@ def test_correct_init_singular_plural_forms(init_cmd): msgid "foobar" msgid_plural "foobars" msgstr[0] "" - """ with open(get_po_file_path('ja_JP')) as f: actual_content = f.read() @@ -307,7 +303,6 @@ def test_supports_no_wrap(init_cmd): msgid_plural "foobars" msgstr[0] "" msgstr[1] "" - """ with open(get_po_file_path('en_US')) as f: actual_content = f.read() @@ -364,7 +359,6 @@ def test_supports_width(init_cmd): msgid_plural "foobars" msgstr[0] "" msgstr[1] "" - """ with open(get_po_file_path('en_US')) as f: actual_content = f.read() diff --git a/tests/messages/test_checkers.py b/tests/messages/test_checkers.py index 8d4b1a77d..1a76f2d36 100644 --- a/tests/messages/test_checkers.py +++ b/tests/messages/test_checkers.py @@ -68,7 +68,6 @@ def test_1_num_plurals_checkers(): msgid "foobar" msgid_plural "foobars" msgstr[0] "" - """).encode('utf-8') # This test will fail for revisions <= 406 because so far @@ -130,7 +129,6 @@ def test_2_num_plurals_checkers(): msgstr[0] "" msgstr[1] "" msgstr[2] "" - """.encode('utf-8') # we should be adding the missing msgstr[0] @@ -177,7 +175,6 @@ def test_3_num_plurals_checkers(): msgid_plural "foobars" msgstr[0] "" msgstr[1] "" - """.encode('utf-8') # This test will fail for revisions <= 406 because so far @@ -225,7 +222,6 @@ def test_4_num_plurals_checkers(): msgstr[0] "" msgstr[1] "" msgstr[2] "" - """.encode('utf-8') # This test will fail for revisions <= 406 because so far @@ -274,7 +270,6 @@ def test_5_num_plurals_checkers(): msgstr[1] "" msgstr[2] "" msgstr[3] "" - """.encode('utf-8') # This test will fail for revisions <= 406 because so far @@ -324,7 +319,6 @@ def test_6_num_plurals_checkers(): msgstr[2] "" msgstr[3] "" msgstr[4] "" - """.encode('utf-8') # This test will fail for revisions <= 406 because so far diff --git a/tests/messages/test_pofile_read.py b/tests/messages/test_pofile_read.py index d17f5d4af..1c8e629dc 100644 --- a/tests/messages/test_pofile_read.py +++ b/tests/messages/test_pofile_read.py @@ -363,7 +363,6 @@ def test_obsolete_messages_roundtrip(): #~ msgctxt "orange" #~ msgid "foo" #~ msgstr "Bar" - ''') generated_po_file = ''.join(pofile.generate_po(pofile.read_po(buf), omit_header=True)) assert buf.getvalue() == generated_po_file diff --git a/tests/messages/test_pofile_write.py b/tests/messages/test_pofile_write.py index 0145f7928..e8c0e7cdb 100644 --- a/tests/messages/test_pofile_write.py +++ b/tests/messages/test_pofile_write.py @@ -136,7 +136,6 @@ def test_no_wrap_and_width_behaviour_on_comments(): #: fake.py:29 msgid "pretty dam long message id, which must really be big to test this wrap behaviour, if not it won't work." msgstr "" - """ buf = BytesIO() pofile.write_po(buf, catalog, width=100, omit_header=True) @@ -149,7 +148,6 @@ def test_no_wrap_and_width_behaviour_on_comments(): "pretty dam long message id, which must really be big to test this wrap behaviour, if not it won't" " work." msgstr "" - """