From aa7ae99a47b819442bf344adf3fc9d5d7b618913 Mon Sep 17 00:00:00 2001 From: Kevin Deldycke Date: Thu, 24 Sep 2026 11:12:14 +0400 Subject: [PATCH] Remove local workaround to display `^D` in `CliRunner`, requires Click 8.6.0 Refs https://github.com/pallets/click/pull/3878 --- CHANGES.md | 8 ++++ pyproject.toml | 9 +++- .../themes/click/domain.py | 42 ------------------- uv.lock | 15 ++----- 4 files changed, 19 insertions(+), 55 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 4032fec..6be3ae8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,11 @@ +## Version 2.6.0 + +Unreleased + +- Remove local workaround to display `^D` in `CliRunner`. Requires + Click >= 8.6.0. + [pallets/click#3878](https://github.com/pallets/click/pull/3878) + ## Version 2.5.0 Released 2026-02-25 diff --git a/pyproject.toml b/pyproject.toml index a01f490..c501180 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,7 +35,7 @@ jinja = "pallets_sphinx_themes.themes.jinja:JinjaStyle" [dependency-groups] dev = [ - "click>=8.3.1", + "click>=8.6.0.dev", "ruff", "tox", "tox-uv", @@ -58,7 +58,7 @@ tests = [ "pytest", ] typing = [ - "click>=8.3.1", + "click>=8.6.0.dev", "mypy", "pyright", "types-pygments>=2.19.0.20251121", @@ -83,6 +83,11 @@ exclude = [ [tool.uv] default-groups = ["dev", "pre-commit", "tests", "typing"] +# XXX Temporary, until the `^D` echo reaches a Click release: drop this +# source and pin `click>=8.6.0`. https://github.com/pallets/click/pull/3878 +[tool.uv.sources] +click = { git = "https://github.com/kdeldycke/click", rev = "f8c5a8efc17d01a9fb10bba961def4c3215ce369" } + [tool.pytest] testpaths = ["tests"] filterwarnings = [ diff --git a/src/pallets_sphinx_themes/themes/click/domain.py b/src/pallets_sphinx_themes/themes/click/domain.py index a98709f..8243a81 100644 --- a/src/pallets_sphinx_themes/themes/click/domain.py +++ b/src/pallets_sphinx_themes/themes/click/domain.py @@ -1,42 +1,17 @@ import contextlib import shlex import subprocess -import sys import tempfile from functools import partial import click from click.testing import CliRunner -from click.testing import EchoingStdin from docutils import nodes from docutils.parsers.rst import Directive from docutils.statemachine import ViewList from sphinx.domains import Domain -class EofEchoingStdin(EchoingStdin): - """Like :class:`click.testing.EchoingStdin` but adds a visible - ``^D`` in place of the EOT character (``\x04``). - - :meth:`ExampleRunner.invoke` adds ``\x04`` when - ``terminate_input=True``. - """ - - def _echo(self, rv): - eof = rv[-1] == b"\x04"[0] - - if eof: - rv = rv[:-1] - - if not self._paused: - self._output.write(rv) - - if eof: - self._output.write(b"^D\n") - - return rv - - @contextlib.contextmanager def patch_modules(): """Patch modules to work better with :meth:`ExampleRunner.invoke`. @@ -68,23 +43,6 @@ def __init__(self): super().__init__(echo_stdin=True) self.namespace = {"click": click, "__file__": "dummy.py"} - @contextlib.contextmanager - def isolation(self, *args, **kwargs): - iso = super().isolation(*args, **kwargs) - - with iso as streams: - try: - buffer = sys.stdin.buffer - except AttributeError: - buffer = sys.stdin - - # FIXME: We need to replace EchoingStdin with our custom - # class that outputs "^D". At this point we know sys.stdin - # has been patched so it's safe to reassign the class. - # Remove this once EchoingStdin is overridable. - buffer.__class__ = EofEchoingStdin - yield streams - def invoke( self, cli, diff --git a/uv.lock b/uv.lock index b8044cb..c4b77d2 100644 --- a/uv.lock +++ b/uv.lock @@ -166,15 +166,8 @@ wheels = [ [[package]] name = "click" -version = "8.3.1" -source = { registry = "https://pypi.org/simple" } -dependencies = [ - { name = "colorama", marker = "sys_platform == 'win32'" }, -] -sdist = { url = "https://files.pythonhosted.org/packages/3d/fa/656b739db8587d7b5dfa22e22ed02566950fbfbcdc20311993483657a5c0/click-8.3.1.tar.gz", hash = "sha256:12ff4785d337a1bb490bb7e9c2b1ee5da3112e94a8622f26a6c77f5d2fc6842a", size = 295065, upload-time = "2025-11-15T20:45:42.706Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/98/78/01c019cdb5d6498122777c1a43056ebb3ebfeef2076d9d026bfe15583b2b/click-8.3.1-py3-none-any.whl", hash = "sha256:981153a64e25f12d547d3426c367a4857371575ee7ad18df2a6183ab0545b2a6", size = 108274, upload-time = "2025-11-15T20:45:41.139Z" }, -] +version = "8.6.0.dev0" +source = { git = "https://github.com/kdeldycke/click?rev=f8c5a8efc17d01a9fb10bba961def4c3215ce369#f8c5a8efc17d01a9fb10bba961def4c3215ce369" } [[package]] name = "colorama" @@ -730,7 +723,7 @@ requires-dist = [ [package.metadata.requires-dev] dev = [ - { name = "click", specifier = ">=8.3.1" }, + { name = "click", git = "https://github.com/kdeldycke/click?rev=f8c5a8efc17d01a9fb10bba961def4c3215ce369" }, { name = "ruff" }, { name = "tox" }, { name = "tox-uv" }, @@ -747,7 +740,7 @@ pre-commit = [ ] tests = [{ name = "pytest" }] typing = [ - { name = "click", specifier = ">=8.3.1" }, + { name = "click", git = "https://github.com/kdeldycke/click?rev=f8c5a8efc17d01a9fb10bba961def4c3215ce369" }, { name = "mypy" }, { name = "pyright" }, { name = "types-pygments", specifier = ">=2.19.0.20251121" },