Skip to content

Allow for reading TOML files from stdin.#239

Merged
gaborbernat merged 1 commit intotox-dev:mainfrom
fniessink:238-allow-for-reading-from-stdin
Jul 30, 2024
Merged

Allow for reading TOML files from stdin.#239
gaborbernat merged 1 commit intotox-dev:mainfrom
fniessink:238-allow-for-reading-from-stdin

Conversation

@fniessink
Copy link
Copy Markdown
Contributor

When the input filename is '-', read the toml from stdin and output to stdout.

Closes #238.



def test_cli_pyproject_toml_stdin(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr("sys.stdin", io.StringIO(""))
Copy link
Copy Markdown
Member

@gaborbernat gaborbernat Jul 30, 2024

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

gaborbernat
gaborbernat previously approved these changes Jul 30, 2024
Copy link
Copy Markdown
Member

@gaborbernat gaborbernat left a comment

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

@fniessink fniessink left a 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 to if config.pyproject_toml is None or config.stdout

There are probably other options as well.

@gaborbernat
Copy link
Copy Markdown
Member

either is fine

Copy link
Copy Markdown
Member

@gaborbernat gaborbernat left a comment

Choose a reason for hiding this comment

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

@gaborbernat gaborbernat enabled auto-merge (squash) July 30, 2024 16:23
When the input filename is '-', read the toml from stdin and output to stdout.

Closes #238.
auto-merge was automatically disabled July 30, 2024 16:35

Head branch was pushed to by a user without write access

@fniessink
Copy link
Copy Markdown
Contributor Author

Now with a signed commit.

Copy link
Copy Markdown
Member

@gaborbernat gaborbernat left a comment

Choose a reason for hiding this comment

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

@gaborbernat gaborbernat enabled auto-merge (squash) July 30, 2024 16:49
@gaborbernat gaborbernat merged commit 125f7ee into tox-dev:main Jul 30, 2024
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.

Allow for reading from stdin

2 participants