diff --git a/changelog.d/20240816_141531_regis_patches_show.md b/changelog.d/20240816_141531_regis_patches_show.md new file mode 100644 index 0000000000..fef5b5d972 --- /dev/null +++ b/changelog.d/20240816_141531_regis_patches_show.md @@ -0,0 +1 @@ +- [Feature] Add a `patches show my-patch-name`. This is a convenient command for the troubleshooting of plugins. (by @regisb) diff --git a/tests/commands/test_config.py b/tests/commands/test_config.py index d62d2a9550..4a1ab796a7 100644 --- a/tests/commands/test_config.py +++ b/tests/commands/test_config.py @@ -111,3 +111,8 @@ def test_config_patches_list(self) -> None: result = self.invoke_in_root(root, ["config", "patches", "list"]) self.assertFalse(result.exception) self.assertEqual(0, result.exit_code) + + def test_config_patches_show(self) -> None: + result = self.invoke(["config", "patches", "show", "mypatch"]) + self.assertEqual(0, result.exit_code) + self.assertEqual("", result.stdout) diff --git a/tutor/commands/config.py b/tutor/commands/config.py index 6c927d2c67..e261a526e6 100644 --- a/tutor/commands/config.py +++ b/tutor/commands/config.py @@ -230,8 +230,20 @@ def patches_list(context: Context) -> None: renderer.print_patches_locations() +@click.command(name="show", help="Print the rendered contents of a template patch") +@click.argument("name") +@click.pass_obj +def patches_show(context: Context, name: str) -> None: + config = tutor_config.load_full(context.root) + renderer = env.Renderer(config) + rendered = renderer.patch(name) + if rendered: + print(rendered) + + config_command.add_command(save) config_command.add_command(printroot) config_command.add_command(printvalue) patches_command.add_command(patches_list) +patches_command.add_command(patches_show) config_command.add_command(patches_command) diff --git a/tutor/plugins/__init__.py b/tutor/plugins/__init__.py index 5771c4d00d..b46106ad10 100644 --- a/tutor/plugins/__init__.py +++ b/tutor/plugins/__init__.py @@ -4,12 +4,10 @@ from __future__ import annotations -import functools import typing as t -from copy import deepcopy from tutor import exceptions, fmt, hooks -from tutor.types import Config, get_typed +from tutor.types import Config # Import modules to trigger hook creation from . import openedx, v0, v1