Skip to content
Myr

apply Unix line endings for shell completion output for windows compat (#3466)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by GitHub · parents b8b9ffe, a3321c9 · Browse files · 3 files+20 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+20 added−2 removed

  • tests:+16 added−0 removed
  • other:+4 added−2 removed

3 files+20 added−2 removed

modified:src/click/shell_completion.py+3 added-2 removed
41 unmodified lines
42 return 14344 comp = comp_cls(cli, ctx_args, prog_name, complete_var)4546 # Write bytes, otherwise Windows text stdout translates LF to CRLF and breaks.47 if instruction == "source":47 echo(comp.source())48 echo(comp.source().encode(), nl=False)49 return 05051 if instruction == "complete":51 echo(comp.complete())52 echo(comp.complete().encode())53 return 05455 return 156
624 unmodified lines
modified:tests/test_shell_completion.py+16 added
1import io2import textwrap3import warnings4from collections.abc import Mapping5
5 unmodified lines
11from click.core import Group12from click.core import Option13from click.shell_completion import add_completion_class14from click.shell_completion import CompletionItem15from click.shell_completion import shell_complete16from click.shell_completion import ShellComplete17from click.types import Choice18from click.types import File19from click.types import Path
351 unmodified lines
371 result = runner.invoke(cli, env=env)372 assert result.output == expect373374375def test_source_uses_lf_line_endings(monkeypatch):376 stdout = io.BytesIO()377 stream = io.TextIOWrapper(stdout, encoding="utf-8", newline="\r\n")378 monkeypatch.setattr("click.utils._default_text_stdout", lambda: stream)379380 cli = Group("cli", commands=[Command("a"), Command("b")])381 assert shell_complete(cli, {}, "cli", "_CLI_COMPLETE", "zsh_source") == 0382383 stream.flush()384 output = stdout.getvalue()385 assert b"\r\n" not in output386 assert b"\n" in output387388389@pytest.mark.parametrize(390 ("env", "expect"),391 [392 (
232 unmodified lines
modified:CHANGES.rst+1 added
3 unmodified lines
4-------------56Unreleased78- Zsh completion scripts parse correctly on Windows. :issue:`3277`91011Version 8.4.012-------------
1463 unmodified lines