-
Notifications
You must be signed in to change notification settings - Fork 56
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
--stdout
option throws error if dash is given indicating stdin input – breaks VSCode compatibility
#523
Comments
I'm happy to attempt to open a pull request for a fix f there is agreement that this is a bug. |
On my side, darker is completely broken in vscode since the python extension removed all formating options. |
@dkeraudren I had the same issue and I believe the reason is the the new black extension is expecting the output on stdout, which darker doesn't do by default. I was able to get it to work by setting the formatter path to darker and by setting darker to output to stdout with
|
Hi @seweissman and @dkeraudren, thanks for the report and analysis! I'd love to make Darker work perfectly together with the VSCode black-formatter extension as well as other IDEs and tools. @seweissman could you share your local patch to Darker? |
--stdout
option throws error if dash is given indicating stdin input – breaks VSCode compatibility
Can confirm this works, however it was a bit confusing, so here's a step-by-step for those who want to have this working before a proper PR is created:
diff --git a/src/darker/config.py b/src/darker/config.py
index 7beb307..6db29da 100644
--- a/src/darker/config.py
+++ b/src/darker/config.py
@@ -57,7 +57,7 @@ class OutputMode:
return
if stdin_filename is None and len(src) == 1 and Path(src[0]).is_file():
return
- if stdin_filename is not None and len(src) == 0:
+ if stdin_filename is not None and len(src) == 0 or src == ["-"]:
return
raise ConfigurationError(
"Either --stdin-filename=<path> or exactly one Python source file which"
"python.editor.defaultFormatter": "ms-python.black-formatter",
"black-formatter.path": ["<path_from_4.>"],
"black-formatter.args": ["-d"], |
@Garfounkel's fix is now in PR #574. I also invited you @Garfounkel, @seweissman and @dkeraudren as collaborators to this repository. If you accept the invitation, I can assign you as reviewers for #574. I'd appreciate especially a second look at the changes I made to |
Describe the bug
-d/--stdout option should allow "-" to indicate stdin
To Reproduce
Steps to reproduce the behavior:
darker -d --stdin-filename=somefile -
stdout
option"Expected behavior
Darker should run and accept stdin input in the same way that it does without the trailing dash.
Environment (please complete the following information):
Additional context
I am trying to use darker with the new VSCode black-formatter extension. The extension sends stdin input and seems to expect stdout, which can be accomplished by configuring it to run with
-d
. The main piece keeping it from working is that darker doesn't like the dash indicating stdin, which is added by VSCode.I belive that validate_stdout_src is likely the issue. The
validate_stdin_src
function already supports the dash.The text was updated successfully, but these errors were encountered: