Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-85012: Properly reset msgctxt when compiling messages with msgfmt #130525

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

Merged
merged 8 commits into from
Mar 13, 2025

Conversation

tomasr8
Copy link
Member

@tomasr8 tomasr8 commented Feb 24, 2025

I realized that the downside of only having binary snapshots is that it's much more difficult to review any changes. So I added human-readable snapshots as well in this PR.

These snapshots are just JSON dumps of GNUTranslations._catalog when the MO file is read back. (I thought about using PO files for the snapshots but that would require some additional changes in pygettext so I opted for this for now)

I first generated the new snapshots and then applied the fix so you can see the diff in the snapshots here: 69402a5

What you're looking for is correct msgctxt (the part before \u0004 in each message). This is the source file for reference:
https://github.com/python/cpython/blob/main/Lib/test/test_tools/msgfmt_data/general.po

@tomasr8
Copy link
Member Author

tomasr8 commented Feb 24, 2025

cc @StanFromIreland @m-aciek just in case

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 69402a5 changeset does not look particularly readable. For some reasons this change causes changing the order of the _catalog items, so it is difficult to see changes in values if the items are reordered. Do you know why is it? Can the order be made more stable?

There are no new tests, so we can only visually control that the behavior is correct. But if in future the order will be change unpredictably, we can miss a regression. Please add a test for the change, preferably a translation test that does not depend on implementation details of GNUTranslations.

@tomasr8
Copy link
Member Author

tomasr8 commented Feb 25, 2025

Do you know why is it?

It was sorted, the issue was that the message context was/is part of the message and so fixing that resulted in many messages being reordered. I changed the sorting to always put plurals at the end which produces IMO a much more readable diff: 8295b2b

Please add a test for the change, preferably a translation test that does not depend on implementation details of GNUTranslations

Added in 97d0a0f. It tests all mesages from the source PO file.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@serhiy-storchaka serhiy-storchaka merged commit 7ea6e88 into python:main Mar 13, 2025
43 checks passed
@serhiy-storchaka serhiy-storchaka added needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes labels Mar 13, 2025
@miss-islington-app
Copy link

Thanks @tomasr8 for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Thanks @tomasr8 for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Sorry, @tomasr8 and @serhiy-storchaka, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 7ea6e88eb490635518c63c3305c03baf3e151555 3.12

@miss-islington-app
Copy link

Sorry, @tomasr8 and @serhiy-storchaka, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 7ea6e88eb490635518c63c3305c03baf3e151555 3.13

serhiy-storchaka pushed a commit to serhiy-storchaka/cpython that referenced this pull request Mar 13, 2025
… with msgfmt (pythonGH-130525)

Add also human-readable snapshots for tests.
(cherry picked from commit 7ea6e88)

Co-authored-by: Tomas R. <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Mar 13, 2025

GH-131205 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Mar 13, 2025
serhiy-storchaka pushed a commit to serhiy-storchaka/cpython that referenced this pull request Mar 13, 2025
… with msgfmt (pythonGH-130525)

Add also human-readable snapshots for tests.
(cherry picked from commit 7ea6e88)

Co-authored-by: Tomas R. <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Mar 13, 2025

GH-131206 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 only security fixes label Mar 13, 2025
@tomasr8
Copy link
Member Author

tomasr8 commented Mar 13, 2025

Thanks for dealing with the backports Serhiy, I was going to do it but you beat me to it 😄

@tomasr8 tomasr8 deleted the msgfmt-ctxt branch March 13, 2025 19:08
serhiy-storchaka added a commit that referenced this pull request Mar 13, 2025
…msgfmt (GH-130525) (GH-131206)

Add also human-readable snapshots for tests.
(cherry picked from commit 7ea6e88)

Co-authored-by: Tomas R <[email protected]>
serhiy-storchaka added a commit that referenced this pull request Mar 13, 2025
…msgfmt (GH-130525) (GH-131205)

Add also human-readable snapshots for tests.
(cherry picked from commit 7ea6e88)

Co-authored-by: Tomas R <[email protected]>
@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot aarch64 Android 3.13 (tier-3) has failed when building commit 78f75d3.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1590/builds/507) and take a look at the build logs.
  4. Check if the failure is related to this commit (78f75d3) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1590/builds/507

Failed tests:

  • test_os

Failed subtests:

  • test_fpathconf - test.test_os.TestInvalidFD.test_fpathconf

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/data/user/0/org.python.testbed/files/python/lib/python3.13/test/test_os.py", line 2402, in test_fpathconf
    self.check(os.pathconf, "PC_NAME_MAX")
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/user/0/org.python.testbed/files/python/lib/python3.13/test/test_os.py", line 2325, in check
    f(os_helper.make_bad_fd(), *args, **kwargs)
    ~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: unrecognized configuration name

mikec9 pushed a commit to mikec9/cpython that referenced this pull request Mar 14, 2025
… with msgfmt (pythonGH-130525) (pythonGH-131206)

Add also human-readable snapshots for tests.
(cherry picked from commit 7ea6e88)

Co-authored-by: Tomas R <[email protected]>
plashchynski pushed a commit to plashchynski/cpython that referenced this pull request Mar 17, 2025
seehwan pushed a commit to seehwan/cpython that referenced this pull request Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants