-
Notifications
You must be signed in to change notification settings - Fork 55
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
New file to stdout #164
Comments
Found one way to do it
Edit: To also have if work it there are no changes one can do for example:
If one puts this in a script file ( #!/usr/bin/bash
DIFF=$(darker --diff $@)
if [[ -z $DIFF ]]; then
cat $1
else
echo "$DIFF" | patch -p0 -s -o -
fi and in vim do
to filter and update the buffer instead of writing to file. Or automatically on save with:
|
@AckslD nice trick! There's a typo in the regular command (not in the Also, doing |
I think it would still be a nice feature :) In eg |
@levouh You mean without the |
Ok makes sense to re-use that. The only gotcha would be if Black adopted either |
@AckslD, what should the behavior of
|
@AckslD, I started working on this in #165. @AckslD & @levouh, would you like an invitation as a collaborator on this repository? I'd appreciate a code review on my changes. As noted in the first commit,
|
Sure @akaihola, happy to review. I know Grain of salt, but I think it's totally valid to only accept a single file. Not sure exactly what the use case would even be for handling multiple files through
@AcksID I was noting that I've never seen the syntax |
I think I agree here. So it would be a hard error if anything more than a single What about case 1., should I'd like to make these design choices at this point, since this requires a bit more logic than exists in the code right now. |
Yea, it'd be hard to distinguish which formatting goes with which file and whatnot without making your own format, etc. Easier for the user to just loop and know what's what it seems (unless you always output every file, but you'd still have to know where the files end).
Not home right now, but this is what I was going to look at Rather than |
I believe Also, if It's actually interesting that while
running from black import FileMode, format_str
source = "\n\n \n\t\n"
reformatted = format_str(source, mode=FileMode())
print(repr(reformatted)) So this seems to reveal a bug (?) where Darker and Black give different results when run on an edited all-whitespace file! |
I found the reason for this. As hinted in my comment to psf/black#779, we could replace (in return TextDocument.from_str(
format_str(contents_for_black, mode=mode),
encoding=src_contents.encoding,
override_newline=src_contents.newline,
) with try:
reformatted = format_file_contents(contents_for_black, fast=True, mode=mode)
except NothingChanged:
reformatted = contents_for_black
return TextDocument.from_str(
reformatted,
encoding=src_contents.encoding,
override_newline=src_contents.newline,
) to match contents_for_black = src_contents.string_with_newline("\n")
if not contents_for_black.strip():
return src_contents
return TextDocument.from_str(
format_str(contents_for_black, mode=mode),
encoding=src_contents.encoding,
override_newline=src_contents.newline,
) Which approach to choose should depend on Black's possible choice of a public Python API (psf/black#779). |
Oh yes, good spot, fix in the comment :) |
I think it should output the original file. I don't see any reason for not outputting anything in this case :) I think this flag should be "output what the file would be after running dark". |
Add the `-d` / `--stdout` option. Fixes #164.
Is it possible to pipe the new file to stdout? Would be nice so that one could use filter in vim :)
The text was updated successfully, but these errors were encountered: