-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Trying to read from stdin dumps no content when stdin-filename is excluded #4609
Comments
Yay, conflicting requirements. I previously made this exact behavior not happen in #4539 , fixing #4232 , because they wanted the opposite thing for their tooling, where reading from stdin with a force excluded path wouldn't give an output. Feel free to read the issue and PR, maybe I misinterpreted what they actually wanted. Past that I don't really have an opinion/preference on which of these behaviors would be better, and I also don't know what to do in these conflict of needs situations. |
I don't think there's a conflict, i think they just didn't want formatting to happen. Outputting the original source back to stdout should be okay if I'm reading this correctly. |
FWIW i do think that if we're exiting with zero we should be outputting something, rather than nothing. |
Your original change it's ok, stdin should be excluded if stdin_filename matches any exclusion. I think when you run the cli with a path it's ok to not modify the file if it's excluded, but when you run it through a pipe, say: cat no_format.py | black - --stdin-filename no_format.py you would expect to output the original content. At least that's what's intended in #4610. That's how other formatters such as ruff or clang-format work:
|
When working in a project where some paths are not blacked yet, you may configure file discovery and run something like:
black .
Once you have this, you may need to integrate black in your editor, and some plugins end up piping from stdin:
stdin | black - --stdin-filename "$FILEPATH"
The problem is the integration will fail when trying to format a file being excluded by force-exclude directive.
You can check other tools like ruff output unformatted stdin in this case:
astral-sh/ruff#8596
So they can have editor integrations such as:
https://github.com/JoshHayes/emacs-ruff-format/blob/main/ruff-format.el#L43
Where they just pipe the content of the buffer to their cli
The text was updated successfully, but these errors were encountered: