Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+35 added−13 removed
tests:+22 added−12 removed
other:+13 added−1 removed
Provenance
Commit
65386d9
Tree
4399ee0
Author
David Lord <davidism@gmail.com>
Committer
GitHub <noreply@github.com>
Parent 1
d053249
Parent 2
06d0308
2 files changed+35 added−13 removed
modified:click/_compat.py+13 added-1 removed
568 unmodified lines
569def strip_ansi(value):570 return _ansi_re.sub('', value)571572573+def _is_jupyter_kernel_output(stream):574+ if WIN:575+ # TODO: Couldn't test on Windows, should't try to support until576+ # someone tests the details wrt colorama.577+ return578+579+ while isinstance(stream, (_FixupStream, _NonClosingTextIOWrapper)):580+ stream = stream._stream581+582+ return stream.__class__.__module__.startswith("ipykernel.")583+584+585def should_strip_ansi(stream=None, color=None):586 if color is None:587 if stream is None:588 stream = sys.stdin577- return not isatty(stream)589+ return not isatty(stream) and not _is_jupyter_kernel_output(stream)590 return not color591592593# If we're on Windows, we provide transparent integration through
121 unmodified lines
modified:tests/test_compat.py+22 added-12 removed
1import click2import pytest3+from click._compat import should_strip_ansi, WIN455-if click.__version__ >= '3.0':6- def test_legacy_callbacks(runner):7- def legacy_callback(ctx, value):8- return value.upper()6+def test_legacy_callbacks(runner):7+ def legacy_callback(ctx, value):8+ return value.upper()910- @click.command()11- @click.option('--foo', callback=legacy_callback)12- def cli(foo):13- click.echo(foo)10+ @click.command()11+ @click.option('--foo', callback=legacy_callback)12+ def cli(foo):13+ click.echo(foo)1415- with pytest.warns(Warning, match='Invoked legacy parameter callback'):16- result = runner.invoke(cli, ['--foo', 'wat'])17- assert result.exit_code == 018- assert 'WAT' in result.output15+ with pytest.warns(Warning, match='Invoked legacy parameter callback'):16+ result = runner.invoke(cli, ['--foo', 'wat'])17+ assert result.exit_code == 018+ assert 'WAT' in result.output192021def test_bash_func_name():22 from click._bashcomplete import get_completion_script23 script = get_completion_script('foo-bar baz_blah', '_COMPLETE_VAR', 'bash').strip()24 assert script.startswith('_foo_barbaz_blah_completion()')25 assert '_COMPLETE_VAR=complete $1' in script26+27+28+@pytest.mark.xfail(WIN, reason="Jupyter not tested/supported on Windows")29+def test_is_jupyter_kernel_output():30+ class JupyterKernelFakeStream(object):31+ pass32+33+ # implementation detail, aka cheapskate test34+ JupyterKernelFakeStream.__module__ = "ipykernel.faked"35+ assert not should_strip_ansi(stream=JupyterKernelFakeStream())