From ca290719edc2ba508585149a3e905f5c0bb23a8d Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Fri, 4 May 2018 15:04:33 -0300 Subject: [PATCH] Show version on /-/plugins page, closes #248 --- datasette/app.py | 1 + datasette/utils.py | 9 +++++++-- tests/test_api.py | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/datasette/app.py b/datasette/app.py index a6e6f6fc..c5e6c274 100644 --- a/datasette/app.py +++ b/datasette/app.py @@ -1434,6 +1434,7 @@ class Datasette: 'name': p['name'], 'static': p['static_path'] is not None, 'templates': p['templates_path'] is not None, + 'version': p.get('version'), } for p in get_plugins(pm)]), '/-/plugins' ) diff --git a/datasette/utils.py b/datasette/utils.py index 9cf4724e..d905a97a 100644 --- a/datasette/utils.py +++ b/datasette/utils.py @@ -688,6 +688,7 @@ def module_from_path(path, name): def get_plugins(pm): plugins = [] + plugin_to_distinfo = dict(pm.list_plugin_distinfo()) for plugin in pm.get_plugins(): static_path = None templates_path = None @@ -699,9 +700,13 @@ def get_plugins(pm): except (KeyError, ImportError): # Caused by --plugins_dir= plugins - KeyError/ImportError thrown in Py3.5 pass - plugins.append({ + plugin_info = { 'name': plugin.__name__, 'static_path': static_path, 'templates_path': templates_path, - }) + } + distinfo = plugin_to_distinfo.get(plugin) + if distinfo: + plugin_info['version'] = distinfo.version + plugins.append(plugin_info) return plugins diff --git a/tests/test_api.py b/tests/test_api.py index 0030e2dc..16b1435a 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -763,7 +763,8 @@ def test_plugins_json(app_client): assert { 'name': 'my_plugin.py', 'static': False, - 'templates': False + 'templates': False, + 'version': None, } in response.json