Skip to content

Commit

Permalink
feat: add patches show ... command
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
regisb committed Sep 19, 2024
1 parent 46b4016 commit 2959e6e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.d/20240816_141531_regis_patches_show.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- [Feature] Add a `patches show my-patch-name`. This is a convenient command for the troubleshooting of plugins. (by @regisb)
5 changes: 5 additions & 0 deletions tests/commands/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
12 changes: 12 additions & 0 deletions tutor/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 1 addition & 3 deletions tutor/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2959e6e

Please sign in to comment.