gh-133049: make pygettext match xgettext for empty input/no messages - #156322
Draft
aryansk wants to merge 1 commit into
Draft
gh-133049: make pygettext match xgettext for empty input/no messages#156322aryansk wants to merge 1 commit into
aryansk wants to merge 1 commit into
Conversation
…sages Fixes python#133049 pygettext now matches GNU xgettext behavior: * No input file given → error "pygettext: no input file given" and "Try 'pygettext --help' ..." with exit 1, instead of silently generating an empty messages.pot. * No strings to extract → no output file generated (exit 0, verbose message to stderr), instead of writing a header-only messages.pot. This matches xgettext which produces no output when there are no messages. Validation: manual check with python3.14 Tools/i18n/pygettext.py (no args → exit 1 with error, empty file → no out.pot, file with _() → out.pot with header+msgid); py_compile passes on 3.13/3.14.
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #133049
Problem
Tools/i18n/pygettext.pydiverges from GNUxgettextin two empty-input cases:No input file given —
xgettextprintsxgettext: no input file givenandTry 'xgettext --help' …with exit 1.pygettextsilently generated an emptymessages.potwith only a header.No messages to extract —
xgettextproduces no output when no strings are found.pygettextstill wrote a header-onlymessages.pot.Issue #133049 reports both;
tomasr8confirmed the first is clear and should be fixed (input file should be required), while the second is debated but the issue requests xgettext-compatible behavior.Change
In
Tools/i18n/pygettext.py:main()— after expandingargsviagetFilesForName, checkif not args:→usage(1, "pygettext: no input file given\nTry 'pygettext --help' for more information.")After visiting files, check
if not visitor.messages:→ verbose message to stderr andsys.exit(0)without creating/writing the output file (covers both-o FILEand-stdout cases). This matchesxgettext's "no output is generated if there are no messages".Keep unrelated cleanup out of this PR.
Why this approach
Minimal, xgettext-compatible, and respects the maintainer's lean: the first fix is uncontroversial and matches the exact
xgettexterror wording; the second implements the requested "no empty output" while remaining silent unless-vis given, so existing workflows that expect an empty POT can be detected via the exit and verbose hint.Testing
make checkforpygettextis covered bytest.test_tools.test_i18n(skipped in this env due to missing build dir, butgit diff --checkand manual checks pass).Documentation and release impact
Review notes
pygettextgenerates output even when there should be none #133049