← 输入框|github.com|刷新
Skip to content

gh-133049: Require an input file in pygettext - #160768

Open
RajaBabu15 wants to merge 1 commit into
python:mainfrom
RajaBabu15:fix-pygettext-no-input
Open

RajaBabu15 wants to merge 1 commit into
python:mainfrom
RajaBabu15:fix-pygettext-no-input

Conversation

@RajaBabu15

@RajaBabu15 RajaBabu15 commented Oct 27, 2026 •

Copy link
Copy Markdown

Like xgettext, pygettext now prints pygettext: no input file given and exits with status 1 when no input file is given, instead of silently writing a header-only messages.pot.

This covers the first case in the issue only. As discussed there, the no-messages case keeps its current behaviour (an empty template is valid).

The check runs before getFilesForName() expands the arguments. After expansion, a mistyped path or a directory with no .py files would also be reported as "no input file", which is wrong. Those two cases keep their current behaviour, and test_missing_input_file_is_not_no_input pins that.

Tests: test_header, test_POT_Creation_Date and test_output_option ran the script without any input, so they now pass an empty file. test_no_input_file is new. Without the change it fails; with it, test_tools and test_gettext pass (160 tests).

I used an AI assistant (Claude Code) while preparing this change; I reviewed the diff and ran the tests myself.

Like xgettext, exit with status 1 and an error message when no input file is given, instead of writing a header-only messages.pot. The check runs before the arguments are expanded, so a path that matches nothing keeps its current behaviour.
Comment thread Tools/i18n/pygettext.py
Comment on lines +822 to +823
print("pygettext: no input file given\n"
"Try 'pygettext --help' for more information.",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
print("pygettext: no input file given\n"
"Try 'pygettext --help' for more information.",
print("No input file given",

For consistency with the other errors.

Comment on lines +188 to +193
def test_missing_input_file_is_not_no_input(self):
# A path that matches nothing is not the same as no path at all.
with temp_cwd(None):
res, _ = run_python_until_end(self.script, 'does_not_exist.py')
self.assertNotIn(b'no input file given', res.err)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
def test_missing_input_file_is_not_no_input(self):
# A path that matches nothing is not the same as no path at all.
with temp_cwd(None):
res, _ = run_python_until_end(self.script, 'does_not_exist.py')
self.assertNotIn(b'no input file given', res.err)

This isn't really testing anything, so let's drop it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants