Skip to content

Allow PyTA CLI to read file content from stdin - #1369

Open
rachelzUT wants to merge 4 commits into
pyta-uoft:masterfrom
rachelzUT:stdin-cli-option
Open

Allow PyTA CLI to read file content from stdin#1369
rachelzUT wants to merge 4 commits into
pyta-uoft:masterfrom
rachelzUT:stdin-cli-option

Conversation

@rachelzUT

@rachelzUT rachelzUT commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Proposed Changes

Modified PyTA CLI to optionally read file contents through standard input. This is triggered by either passing the --stdin command-line argument or passing - as the filenames argument.

...

Screenshots of your changes (if applicable)

Type of Change

(Write an X or a brief description next to the type or types that best describe your changes.)

Type Applies?
🚨 Breaking change (fix or feature that would cause existing functionality to change)
New feature (non-breaking change that adds functionality) X
🐛 Bug fix (non-breaking change that fixes an issue)
♻️ Refactoring (internal change to codebase, without changing functionality)
🚦 Test update (change that only adds or modifies tests)
📚 Documentation update (change that only updates documentation)
📦 Dependency update (change that updates a dependency)
🔧 Internal (change that only affects developers or continuous integration)

Checklist

Before opening your pull request:

  • I have performed a self-review of my changes.
    • Check that all changed files included in this pull request are intentional changes.
    • Check that all changes are relevant to the purpose of this pull request, as described above.
  • I have added tests for my changes, if applicable.
    • This is required for all bug fixes and new features.
  • I have updated the project documentation, if applicable.
    • This is required for new features.
  • I have updated the project Changelog (this is required for all changes).
  • If this is my first contribution, I have added myself to the list of contributors.

After opening your pull request:

  • I have verified that the CI tests have passed.
  • I have reviewed the test coverage changes reported by Coveralls.
  • I have requested a review from a project maintainer.

Questions and Comments

@coveralls

coveralls commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 30312876395

Coverage increased (+0.03%) to 90.865%

Details

  • Coverage increased (+0.03%) from the base build.
  • Patch coverage: 20 of 20 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 4083
Covered Lines: 3710
Line Coverage: 90.86%
Coverage Strength: 17.66 hits per line

💛 - Coveralls

@rachelzUT
rachelzUT requested a review from david-yz-liu July 26, 2026 22:13

@david-yz-liu david-yz-liu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@rachelzUT nice work; I left a few comments, but please also update the docs CLI page with this change.

use_stdin = stdin or (len(filenames) == 1 and filenames[0] == "-")

if use_stdin:
stdin_contents = sys.stdin.read()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of manually calling read/write, let's use shutil.copyfileobj. Note the comment in the documentation about calling flush on the file.

reporter = _invoke_checker(checker, paths, config, output_format)
finally:
# Clean up the temporary file
path.os.unlink(temp_file_path)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of doing this, you should be able to call _invoke_checker within the with tempfile.NamedTemporaryFile block.

stdin_contents = sys.stdin.read()
# Write the contents to a temporary file
with tempfile.NamedTemporaryFile(
mode="w", suffix=".py", delete=False, encoding="utf-8"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I assume here there's a random filename generated; does this appear to the user in the report? If so we might want a name prefix like stdin.

@rachelzUT
rachelzUT requested a review from david-yz-liu July 28, 2026 01:06
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