From 2959e6eec230c72d10417f886179a1878cdd7143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Fri, 16 Aug 2024 14:18:48 +0200 Subject: [PATCH] feat: add `patches show ...` command I found myself in a situation where I wasn't sure if a patch was correctly added by the Indigo plugin. To troubleshoot that issue, I wanted to print that rendered patch. I thought it would make a nice addition to the CLI. --- changelog.d/20240816_141531_regis_patches_show.md | 1 + tests/commands/test_config.py | 5 +++++ tutor/commands/config.py | 12 ++++++++++++ tutor/plugins/__init__.py | 4 +--- 4 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 changelog.d/20240816_141531_regis_patches_show.md 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