Allow PyTA CLI to read file content from stdin - #1369
Open
rachelzUT wants to merge 4 commits into
Open
Conversation
Collaborator
Coverage Report for CI Build 30312876395Coverage increased (+0.03%) to 90.865%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
david-yz-liu
left a comment
Contributor
There was a problem hiding this comment.
@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() |
Contributor
There was a problem hiding this comment.
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) |
Contributor
There was a problem hiding this comment.
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" |
Contributor
There was a problem hiding this comment.
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.
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.
Proposed Changes
Modified PyTA CLI to optionally read file contents through standard input. This is triggered by either passing the
--stdincommand-line argument or passing-as the filenames argument....
Screenshots of your changes (if applicable)
Type of Change
(Write an
Xor a brief description next to the type or types that best describe your changes.)Checklist
Before opening your pull request:
After opening your pull request:
Questions and Comments