fix: simplify plugin loading in plugin page

This also allows us to handle missing plugins, i.e:
/plugin/missingplugin.
This commit is contained in:
Régis Behmo 2025-08-11 16:56:35 +02:00 committed by Régis Behmo
parent 6e51ee2f3c
commit 6da10d199b
2 changed files with 13 additions and 17 deletions

View File

@ -125,24 +125,13 @@ async def plugin_installed_list() -> str:
@app.get("/plugin/<name>")
async def plugin(name: str) -> Response:
# TODO check that plugin exists
index_entry = tutorclient.Client.plugin_in_store(name)
if not index_entry:
return Response("Plugin not found", status=404)
seq_command_executed = request.args.get("seq_command_executed")
author = next(
(
p.author.split("<")[0].strip()
for p in tutorclient.Client.plugins_in_store()
if p.name == name
),
"",
)
description = next(
(
markdown(p.description)
for p in tutorclient.Client.plugins_in_store()
if p.name == name
),
"",
)
author = index_entry.author.split("<")[0].strip()
description = markdown(index_entry.description)
rendered_template = await render_template(
"plugin.html",
plugin_name=name,

View File

@ -302,6 +302,13 @@ class CliPool:
class Client:
@classmethod
def plugin_in_store(cls, name: str) -> tutor.plugins.indexes.IndexEntry | None:
for plugin in cls.plugins_in_store():
if plugin.name == name:
return plugin
return None
@classmethod
def plugins_in_store(cls) -> list[tutor.plugins.indexes.IndexEntry]:
if not os.path.exists(tutor.plugins.indexes.Indexes.CACHE_PATH):