-
Notifications
You must be signed in to change notification settings - Fork 0
Add CLI tool for listing patches available from installed plugins #50
Comments
I can take this issue if you agree, @kdmccormick :D |
All yours! Heads up @regisb that @MaferMazu will be working on this. |
Hi, I want to ask about the implementation of this feature. At first moment I thought it interesting to extract the info for this command from the patches.rst, and I found two approaches: Another approach I had was like have another doc with a simple structure that provides the patch names and files, but we would maintain two docs of patch documentation. What do you think @kdmccormick @rgraber @Carlos-Muniz ? Which is the best approach? Another question I have is about the column output. Do you know a better way to do it than ljust() or {: >20}.format() ? I would appreciate any feedback 😊 |
EDIT: My answer only allows you to list the existing patches, by name, but not to document them or to figure out in which templates they occur. I need to think about this a little more. |
From Slack:
|
What do you think @regisb ? Personally, I cannot think of any way to do this other than recursively scanning each directory in |
I was trying to iterate over ENV_PATCHES, and I need to populate the Filter. So I was thinking about a pre-load, like reading the config with The other way, I think, is the idea of Kyle, is doing something with the Am I on the right path? |
For a start, I've just realized something: we will not be able to list the file associated to For instance, if a plugin implements the "caddyfile" patch, and in this patch there is a This is a relatively minor detail, but let's keep it in mind. Now, to our initial problem. We want to print a list of Thus, all we need to do is to find in which template the patch function was called. Let's create a quick-and-dirty proof of concept. There are different ways to make this work, here is one. First, we create a custom
Then, we render the full environment with our custom renderer:
This should print all patch statements, unsorted. They should be de-duplicated, sorted and nicely formatted. And of course the code should be nicer -- maybe with custom filters?
That was my initial proposal, but I was completely confused. It would help us find all the patches introduced by plugins, but not the |
@regisb Your approach sounds great to me. Zooming in on the patches-within-patches minor detail for a bit:
The inner def patch(self, name: str, separator: str = "\n", suffix: str = "") -> str:
print(name, self.current_template)
# Store the template's name, and replace it with the name of this patch.
# This handles the case where patches themselves include patches.
original_template = self.current_template
self.current_template = f"within patch: {name}"
rendered_patch = super().patch(name, separator=separator, suffix=suffix)
self.current_template = original_template # Restore the template's name from before.
return rendered_patch which would yield an output like:
If you were to make the |
Damn, I wish I had thought of that myself. Looks rad! |
I was thinking of adding About the @kdmccormick comment, I haven't used patches-within-patches; if you have an example, I appreciate it for better understanding. ✨ |
Sorry for the slow response @MaferMazu. Saving the list to a file is an interesting idea, but I do not prefer it because it would persist state between commands. When we rely on state, there is extra room for errors. For example, if someone installed a plugin and then ran Instead, I recommend following Régis's advice above, which is to subclass the |
Yes, it makes sense. So I'm going to start working on that. I only have a question, and it's about where patches include patches; if you have an example, that would be helpful. |
@MaferMazu , I could have sworn that some plugins had patches that included other patches, but to be honest I cannot find any examples. Sorry about that! When we extract LMS & CMS into a plugin, I expect that we will have plenty of examples, but for now I'll just have to invent one: Consider tutor-mfe's implement of the caddyfile patch, which adds routing for the
Now, imagine we create a tutor-mfe-custom plugin. That plugin could implement our new caddyfile-mfe patch as this:
then To summarize:
At the moment, this is an edge case. If handling it is causing problems in your implementation, I would say go ahead and ignore the patch-within-a-patch edge case. If the edge case becomes common in the future, we can always come back and add support for it 😄 |
Kyle, thanks for your answer. |
@MaferMazu Great! We want to list all patches, whether they are used or not, and whether they are from the core or from plugins. That way, when somebody is a developing a new plugin, they can use this tool in order to see all patches that are available for them to use. |
@kdmccormick, the PR for this issue is ready for review. Maybe it's a good idea to link this issue with that PR and set this card in review status. |
I don't have permission to link the PR to this issue unfortunately, but I've marked it as In Review. |
@kdmccormick I think we can close this issue; the PR overhangio/tutor#798 was merged. |
🎉 |
Context
Originally proposed in https://github.com/overhangio/2u-tutor-adoption/issues/5 was an in-code documentation system for patches accompanied by a CLI tool like this:
We decided that the implementation and maintenance of this would not justify its worth.
Instead, we will document patches manually (as described in https://github.com/overhangio/2u-tutor-adoption/issues/5). Then, we could make a command-line tool just to list the patches and the locations that they will render (relative to the Tutor root), like this:
Blockers
Plugin API v1: #32
Acceptance
The text was updated successfully, but these errors were encountered: