mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Switch from pkg_resources to importlib.metadata in app.py, refs #2057
This commit is contained in:
parent
16f0b6d822
commit
852f501485
2 changed files with 25 additions and 3 deletions
|
|
@ -8,11 +8,11 @@ import functools
|
||||||
import glob
|
import glob
|
||||||
import hashlib
|
import hashlib
|
||||||
import httpx
|
import httpx
|
||||||
|
import importlib.metadata
|
||||||
import inspect
|
import inspect
|
||||||
from itsdangerous import BadSignature
|
from itsdangerous import BadSignature
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import pkg_resources
|
|
||||||
import re
|
import re
|
||||||
import secrets
|
import secrets
|
||||||
import sys
|
import sys
|
||||||
|
|
@ -1118,9 +1118,9 @@ class Datasette:
|
||||||
if using_pysqlite3:
|
if using_pysqlite3:
|
||||||
for package in ("pysqlite3", "pysqlite3-binary"):
|
for package in ("pysqlite3", "pysqlite3-binary"):
|
||||||
try:
|
try:
|
||||||
info["pysqlite3"] = pkg_resources.get_distribution(package).version
|
info["pysqlite3"] = importlib.metadata.version(package)
|
||||||
break
|
break
|
||||||
except pkg_resources.DistributionNotFound:
|
except importlib.metadata.PackageNotFoundError:
|
||||||
pass
|
pass
|
||||||
return info
|
return info
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1264,3 +1264,25 @@ async def test_hook_actors_from_ids():
|
||||||
}
|
}
|
||||||
finally:
|
finally:
|
||||||
pm.unregister(name="ReturnNothingPlugin")
|
pm.unregister(name="ReturnNothingPlugin")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_plugin_is_installed():
|
||||||
|
datasette = Datasette(memory=True)
|
||||||
|
|
||||||
|
class DummyPlugin:
|
||||||
|
__name__ = "DummyPlugin"
|
||||||
|
|
||||||
|
@hookimpl
|
||||||
|
def actors_from_ids(self, datasette, actor_ids):
|
||||||
|
return {}
|
||||||
|
|
||||||
|
try:
|
||||||
|
pm.register(DummyPlugin(), name="DummyPlugin")
|
||||||
|
response = await datasette.client.get("/-/plugins.json")
|
||||||
|
assert response.status_code == 200
|
||||||
|
installed_plugins = {p["name"] for p in response.json()}
|
||||||
|
assert "DummyPlugin" in installed_plugins
|
||||||
|
|
||||||
|
finally:
|
||||||
|
pm.unregister(name="DummyPlugin")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue