Skip to content

Conversation

@anlambert
Copy link
Contributor

@anlambert anlambert commented May 22, 2025

Commit 262bdf0 ensured to raise an EOFError exception on end of input to simulate tty behavior and avoid blocking prompt during tests when no more input is available.

However the introduced implementation has a side effect when testing a click command having a File type option or argument and when it is set to stdin: the command ends up with error due to the Abort exception being raised when the stdin EOFError exception is caught.

To prevent this undesirable side effect, prefer to raise the EOFError exceptions directly from the prompts functions inside the CliRunner class instead of doing it in the method overriding the iterator protcol for the _NamedTextIOWrapper class.

Restore previous implementation of a test broken by changes of 262bdf0.

Fixes #2939.

@anlambert anlambert force-pushed the fix-cli-runner-prompt-eof-handling branch 2 times, most recently from fddeafc to ab23822 Compare May 24, 2025 17:00
Commit 262bdf0 ensured to raise an EOFError exception on end of input
to simulate tty behavior and avoid blocking prompt during tests when
no more input is available.

However the introduced implementation has a side effect when testing a
click command having a File type option or argument and when it is set
to stdin: the command ends up with error due to the Abort exception
being raised when the stdin EOFError exception is caught.

To prevent this undesirable side effect, prefer to raise the EOFError
exceptions directly from the prompts functions inside the CliRunner
class instead of doing it in the method overriding the iterator protcol
for the _NamedTextIOWrapper class.

Restore previous implementation of a test broken by changes of 262bdf0.

Fixes pallets#2939.
@anlambert anlambert force-pushed the fix-cli-runner-prompt-eof-handling branch from ab23822 to 93c6966 Compare May 28, 2025 15:41
@davidism davidism mentioned this pull request Sep 2, 2025
16 tasks
@Rowlando13 Rowlando13 requested a review from kdeldycke September 5, 2025 07:06
@Rowlando13 Rowlando13 added this to the 8.3.0 milestone Sep 5, 2025
@Rowlando13 Rowlando13 added the bug label Sep 5, 2025
QuLogic added a commit to QuLogic/rasterio that referenced this pull request Sep 7, 2025
Due to pallets/click#2939, input from a file is broken. This should be
fixed by pallets/click#2940, which is scheduled to be in click 8.3.0.
snowman2 pushed a commit to rasterio/rasterio that referenced this pull request Sep 7, 2025
Due to pallets/click#2939, input from a file is broken. This should be
fixed by pallets/click#2940, which is scheduled to be in click 8.3.0.
@Rowlando13 Rowlando13 merged commit 2a0e3ba into pallets:main Sep 13, 2025
10 checks passed
@kdeldycke
Copy link
Collaborator

Sorry @Rowlando13 for the late answer following your review request. But good call for merging this. I could not find a regression with the actual main branch .

sirosen added a commit to sirosen/pip-tools that referenced this pull request Sep 19, 2025
The latest `click` release makes two changes which are visible in
`pip-tools`, one of which is only seen in the testsuite.

1.  The default for `Parameter.default` is now an internal `UNSET`
    sentinel.

    Because `UNSET` isn't in the public API, checking `Option.default`
    is not the right way to check if an option has no explicit default
    value. We could use `Option.to_info_dict()`, but we're *also*
    checking for a falsy value right now -- the simple fix is to check
    for a parsed value of `None`.

2.  Changes to EOF handling in `CliRunner.isolation()` result in the
    stream being closed on exit.

    Between pallets/click#2934 and pallets/click#2940, we now get the
    intended behavior for `CliRunner.isolation()`, in that it outputs an
    EOF when the context manager exits. To solve, update a test to read
    stderr before exiting the context manager.
sirosen added a commit to sirosen/pip-tools that referenced this pull request Sep 19, 2025
The latest `click` release makes two changes which are visible in
`pip-tools`, one of which is only seen in the testsuite.

1.  The default for `Parameter.default` is now an internal `UNSET`
    sentinel.

    Because `UNSET` isn't in the public API, checking `Option.default`
    is not the right way to check if an option has no explicit default
    value. We could use `Option.to_info_dict()`, but we're *also*
    checking for a falsy value right now -- the simple fix is to check
    for a parsed value of `None`.

2.  Changes to EOF handling in `CliRunner.isolation()` result in the
    stream being closed on exit.

    Between pallets/click#2934 and pallets/click#2940, we now get the
    intended behavior for `CliRunner.isolation()`, in that it outputs an
    EOF when the context manager exits. To solve, update a test to read
    stderr before exiting the context manager.
- Lazily import ``shutil``. :pr:`3023`
- Properly forward exception information to resources registered with
``click.core.Context.with_resource()``. :issue:`2447` :pr:`3058`
- Fix regression related to EOF handling in CliRunner. :issue:`2939`:pr:`2940`
Copy link
Contributor

Choose a reason for hiding this comment

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

Lacking whitespace in between two refs ^

Copy link
Contributor

Choose a reason for hiding this comment

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

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Click 8.2.1 CliRunner raises SystemExit(1) when using click.File's stdin support

5 participants