Skip to content

Add --batch option as an alternative to STDIN#1723

Open
rolandwalker wants to merge 1 commit intomainfrom
RW/add-batch-option-for-scripting
Open

Add --batch option as an alternative to STDIN#1723
rolandwalker wants to merge 1 commit intomainfrom
RW/add-batch-option-for-scripting

Conversation

@rolandwalker
Copy link
Contributor

@rolandwalker rolandwalker commented Mar 17, 2026

Description

Add --batch option as an alternative to STDIN, factoring out a statements_from_filehandle() function which can also be used to improve the functionality of the source command.

The initial behavior when both STDIN is not-a-tty and --batch is in effect is to warn, and use --batch. Similarly, the priority of the --execute option was clarified with warnings. These may be revisited: we could consider different behavior, as well as exiting with an error in case of warning.

Motivation: display of a prompt_toolkit progress bar during batch execution. If the input is from STDIN, we can't know how many statements are the goal, at least without creating a tempfile. As mentioned above, this also lays the basis to improve the source command, which reads the entire file into memory.

Checklist

  • I added this contribution to the changelog.md file.
  • I added my name to the AUTHORS file (or it's already there).
  • To lint and format the code, I ran
    uv run ruff check && uv run ruff format && uv run mypy --install-types .

factoring out a statements_from_filehandle() function which can also be
used to improve the functionality of the "source" command.

The initial behavior when both STDIN is not-a-tty and --batch is in
effect is to warn, and use --batch.  Similarly, the priority of the
--execute option was clarified with warnings.  These may be revisited:
we could consider different behavior, as well as exiting with an error
in case of warning.

Motivation: display of a prompt_toolkit progress bar during batch
execution.  If the input is from STDIN, we can't know how many
statements are the goal, at least without creating a tempfile.  As
mentioned above, this also lays the basis to improve the "source"
command, which reads the entire file into memory.
@rolandwalker rolandwalker self-assigned this Mar 17, 2026
@github-actions
Copy link

No correctness or security regressions stood out in the PR diff.

Residual testing gaps (worth adding before merge):

  1. Missing coverage for --batch - (explicit STDIN path), including precedence behavior when STDIN is non-tty.

  2. Missing coverage for the new MAX_MULTILINE_BATCH_STATEMENT guard raising ValueError in the factored parser.

  3. No direct unit tests for statements_from_filehandle() splitting behavior across multi-statement input and trailing non-terminated statement.

I couldn’t run tests locally because pytest/uv aren’t installed in this environment.

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.

1 participant