From 1371d00203c7052c5f86e5682ee1d20267cf6897 Mon Sep 17 00:00:00 2001 From: Andreas Eisenbarth Date: Wed, 3 Apr 2024 19:12:15 +0200 Subject: [PATCH 1/3] Pass commands to filter to recursive call --- sphinx_click/ext.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sphinx_click/ext.py b/sphinx_click/ext.py index f398aad..c501872 100644 --- a/sphinx_click/ext.py +++ b/sphinx_click/ext.py @@ -533,12 +533,16 @@ def _generate_nodes( ) ) else: - commands = _filter_commands(ctx, commands) - for command in commands: + command_objs = _filter_commands(ctx, commands) + for command in command_objs: parent = ctx if not semantic_group else ctx.parent section.extend( self._generate_nodes( - command.name, command, parent=parent, nested=nested + command.name, + command, + parent=parent, + nested=nested, + commands=commands, ) ) From b15a5dda87a90f968dbb9e7e186f7e94af593eb4 Mon Sep 17 00:00:00 2001 From: Andreas Eisenbarth Date: Wed, 3 Apr 2024 19:12:42 +0200 Subject: [PATCH 2/3] Extend test case to filtered commands --- tests/roots/nested-full/greet.py | 26 +++++++++++++++++++++++++- tests/roots/nested-full/index.rst | 1 + tests/test_extension.py | 27 +++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/tests/roots/nested-full/greet.py b/tests/roots/nested-full/greet.py index 8981828..c6a481a 100644 --- a/tests/roots/nested-full/greet.py +++ b/tests/roots/nested-full/greet.py @@ -16,7 +16,31 @@ def hello(user): click.echo('Hello %s' % user) -@greet.command() +@greet.group() def world(): """Greet the world.""" click.echo('Hello world!') + + +@world.command() +def peace(): + """Greet the world peace.""" + click.echo('Hello world peace!') + + +@world.command() +def traveler(): + """Greet a globetrotter.""" + click.echo('Hello world traveler!') + + +@world.group() +def wide(): + """Greet all world wide things.""" + click.echo('Hello world wide ...!') + + +@wide.command() +def web(): + """Greet the internet.""" + click.echo('Hello world wide web!') diff --git a/tests/roots/nested-full/index.rst b/tests/roots/nested-full/index.rst index ca32dd3..1e56735 100644 --- a/tests/roots/nested-full/index.rst +++ b/tests/roots/nested-full/index.rst @@ -4,3 +4,4 @@ Nested (full) .. click:: greet:greet :prog: greet :nested: full + :commands: hello, world, wide, web, peace diff --git a/tests/test_extension.py b/tests/test_extension.py index 4dfd12d..59dae70 100644 --- a/tests/test_extension.py +++ b/tests/test_extension.py @@ -144,3 +144,30 @@ def test_nested_full(make_app, rootdir): assert isinstance(subsection_b[1], nodes.paragraph) assert subsection_b[1].astext() == 'Greet the world.' assert isinstance(subsection_b[2], nodes.literal_block) + + subsection_b_a = subsection_b[3] + assert isinstance(subsection_b_a, nodes.section) + + assert isinstance(subsection_b_a[0], nodes.title) + assert subsection_b_a[0].astext() == 'wide' + assert isinstance(subsection_b_a[1], nodes.paragraph) + assert subsection_b_a[1].astext() == 'Greet all world wide things.' + assert isinstance(subsection_b_a[2], nodes.literal_block) + + subsection_b_a_a = subsection_b_a[3] + assert isinstance(subsection_b_a_a, nodes.section) + + assert isinstance(subsection_b_a_a[0], nodes.title) + assert subsection_b_a_a[0].astext() == 'web' + assert isinstance(subsection_b_a_a[1], nodes.paragraph) + assert subsection_b_a_a[1].astext() == 'Greet the internet.' + assert isinstance(subsection_b_a_a[2], nodes.literal_block) + + subsection_b_b = subsection_b[4] + assert isinstance(subsection_b_b, nodes.section) + + assert isinstance(subsection_b_b[0], nodes.title) + assert subsection_b_b[0].astext() == 'peace' + assert isinstance(subsection_b_b[1], nodes.paragraph) + assert subsection_b_b[1].astext() == 'Greet the world peace.' + assert isinstance(subsection_b_b[2], nodes.literal_block) From 059302f4a0e11e8db3d0182b766892dcafcb614e Mon Sep 17 00:00:00 2001 From: Andreas Eisenbarth Date: Fri, 5 Apr 2024 20:48:54 +0200 Subject: [PATCH 3/3] Unload module before test --- tests/test_extension.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_extension.py b/tests/test_extension.py index 59dae70..b1cb870 100644 --- a/tests/test_extension.py +++ b/tests/test_extension.py @@ -1,4 +1,5 @@ import pickle +import sys from docutils import nodes from sphinx import addnodes as sphinx_nodes @@ -91,6 +92,10 @@ def test_commands(make_app, rootdir): def test_nested_full(make_app, rootdir): + # Make sure this sphinx-click reloads the module from this rootdir. + if "greet" in sys.modules: + del sys.modules["greet"] + srcdir = rootdir / 'nested-full' app = make_app('xml', srcdir=srcdir) app.build()