Skip to content
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 --stdout <...> - #574

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Added

Fixed
-----
- A dash (``-``) is now allowed as the single source filename when using the
``--stdout`` option. This makes the option compatible with the
`new Black extension for VSCode`__.

__ https://github.com/microsoft/vscode-black-formatter


2.1.0_ - 2024-03-27
Expand Down
18 changes: 12 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -549,15 +549,21 @@ Visual Studio Code
$ where darker
%LocalAppData%\Programs\Python\Python36-32\Scripts\darker.exe # possible location

3. Add these configuration options to VS code, ``Cmd-Shift-P``, ``Open Settings (JSON)``::
3. Make sure you have the `VSCode black-formatter extension`__ installed.

"python.formatting.provider": "black",
"python.formatting.blackPath": "<install_location_from_step_2>",
"python.formatting.blackArgs": [],
__ https://github.com/microsoft/vscode-black-formatter

4. Add these configuration options to VSCode
(``⌘ Command / Ctrl`` + ``⇧ Shift`` + ``P``
and select ``Open Settings (JSON)``)::

"python.editor.defaultFormatter": "ms-python.black-formatter",
"black-formatter.path": "<install_location_from_step_2>",
"black-formatter.args": ["-d"],

VSCode will always add ``--diff --quiet`` as arguments to Darker,
but you can also pass additional arguments in the ``blackArgs`` option
(e.g. ``["--isort", "--revision=master..."]``).
but you can also pass additional arguments in the ``black-formatter.args`` option
(e.g. ``["-d", "--isort", "--revision=master..."]``).
Be sure to *not* enable any linters here or in ``pyproject.toml``
since VSCode won't be able to understand output from them.

Expand Down
2 changes: 1 addition & 1 deletion src/darker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def validate_stdout_src(
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"
Expand Down
Loading