Skip to content

Commit

Permalink
Merge pull request #574 from akaihola/stdout-allow-dash
Browse files Browse the repository at this point in the history
Allow `--stdout <...> -`
  • Loading branch information
akaihola authored Mar 28, 2024
2 parents cfb1626 + 5ee30ac commit 26e423e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
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

0 comments on commit 26e423e

Please sign in to comment.