-
-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow for reading TOML files from stdin. #239
Allow for reading TOML files from stdin. #239
Conversation
fcea87e
to
44e1ece
Compare
586b5ab
to
8eb6d9c
Compare
ea09cc5
to
8b68b82
Compare
tests/test_cli.py
Outdated
@@ -65,6 +66,15 @@ def test_cli_inputs_ok(tmp_path: Path) -> None: | |||
assert len(result) == 3 | |||
|
|||
|
|||
def test_cli_pyproject_toml_stdin(monkeypatch: pytest.MonkeyPatch) -> None: | |||
monkeypatch.setattr("sys.stdin", io.StringIO("")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use pytest-mock
instead like the rest of the codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
8b68b82
to
7a28ba3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would you like me to deal with the typing error in __main__.py
?
In _handle_one
, after the if config.stdout
block, config.pyproject_toml
is never None
, but the type checker can't detect that:
def _handle_one(config: Config) -> bool:
formatted = format_toml(config.toml, config.settings)
before = config.toml
changed = before != formatted
if config.stdout: # stdout just prints new format to stdout
print(formatted, end="") # noqa: T201
return changed
if before != formatted and not config.check:
config.pyproject_toml.write_text(formatted, encoding="utf-8")
I see a few options:
- casting to
Path
- changing the
if config.stdout
toif config.pyproject_toml is None or config.stdout
There are probably other options as well.
either is fine |
7a28ba3
to
c14a149
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the input filename is '-', read the toml from stdin and output to stdout. Closes #238.
Head branch was pushed to by a user without write access
c14a149
to
5248682
Compare
Now with a signed commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the input filename is '-', read the toml from stdin and output to stdout.
Closes #238.