Skip to content

Commit 78da4a1

Browse files
committed
datasette-ripgrep for datasette>=1.0a20
Refs simonw/datasette#2577
1 parent d80e2d2 commit 78da4a1

4 files changed

Lines changed: 23 additions & 30 deletions

File tree

README.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,15 @@ The `rg` executable needs to be [installed](https://github.com/BurntSushi/ripgre
3333

3434
This plugin requires configuration: it needs to a `path` setting so that it knows where to run searches.
3535

36-
Create a `metadata.json` file that looks like this:
37-
38-
```json
39-
{
40-
"plugins": {
41-
"datasette-ripgrep": {
42-
"path": "/path/to/your/files"
43-
}
44-
}
45-
}
36+
Create a `datasette.yaml` file that looks like this:
37+
38+
```yaml
39+
plugins:
40+
datasette-ripgrep:
41+
path: /path/to/your/files
4642
```
4743
48-
Now run Datasette using `datasette -m metadata.json`. The plugin will add an interface at `/-/ripgrep` for running searches.
44+
Now run Datasette using `datasette --config datasette.yaml`. The plugin will add an interface at `/-/ripgrep` for running searches.
4945

5046
## Plugin configuration
5147

datasette_ripgrep/__init__.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,11 @@ async def view_file(request, datasette):
166166

167167

168168
async def check_permission(request, datasette):
169-
if (
170-
await datasette.permission_allowed(
171-
request.actor,
172-
"view-instance",
173-
default=None,
174-
)
175-
) is False:
169+
can_view = await datasette.allowed(
170+
action="view-instance",
171+
actor=request.actor,
172+
)
173+
if not can_view:
176174
raise Forbidden("view-instance denied")
177175

178176

setup.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@ def get_long_description():
2626
},
2727
license="Apache License, Version 2.0",
2828
classifiers=[
29-
"Framework :: Datasette",
30-
"License :: OSI Approved :: Apache Software License",
29+
"Framework :: Datasette"
3130
],
3231
version=VERSION,
3332
packages=["datasette_ripgrep"],
3433
entry_points={"datasette": ["ripgrep = datasette_ripgrep"]},
3534
package_data={"datasette_ripgrep": ["templates/*.html"]},
36-
install_requires=["datasette"],
35+
install_requires=["datasette>=1.0a21"],
3736
extras_require={"test": ["pytest", "pytest-asyncio", "httpx"]},
3837
tests_require=["datasette-ripgrep[test]"],
39-
python_requires=">=3.7",
38+
python_requires=">=3.10",
4039
)

tests/test_ripgrep.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def datasette(src):
2424
return Datasette(
2525
[],
2626
memory=True,
27-
metadata={
27+
config={
2828
"plugins": {
2929
"datasette-ripgrep": {
3030
"path": str(src),
@@ -212,7 +212,7 @@ async def test_menu_link(datasette):
212212

213213
@pytest.mark.asyncio
214214
@pytest.mark.parametrize(
215-
"metadata,authenticated,path,expected_status",
215+
"config_overrides,authenticated,path,expected_status",
216216
[
217217
# Deny all access
218218
({"allow": False}, False, "/-/ripgrep", 403),
@@ -231,19 +231,19 @@ async def test_menu_link(datasette):
231231
({"allow": {"id": "user"}}, True, "/-/ripgrep/view/one.txt", 200),
232232
],
233233
)
234-
async def test_permissions(src, metadata, authenticated, path, expected_status):
234+
async def test_permissions(src, config_overrides, authenticated, path, expected_status):
235235
datasette = Datasette(
236236
[],
237237
memory=True,
238-
metadata={
238+
config={
239239
**{
240240
"plugins": {
241241
"datasette-ripgrep": {
242242
"path": str(src),
243243
}
244244
},
245245
},
246-
**metadata,
246+
**config_overrides,
247247
},
248248
)
249249
cookies = {}
@@ -256,16 +256,16 @@ async def test_permissions(src, metadata, authenticated, path, expected_status):
256256
@pytest.mark.asyncio
257257
@pytest.mark.parametrize("configured", (True, False))
258258
async def test_configuration(configured):
259-
metadata = {}
259+
config = {}
260260
if configured:
261-
metadata = {
261+
config = {
262262
"plugins": {
263263
"datasette-ripgrep": {
264264
"path": "/tmp",
265265
}
266266
}
267267
}
268-
datasette = Datasette(memory=True, metadata=metadata)
268+
datasette = Datasette(memory=True, config=config)
269269
response = await datasette.client.get("/-/ripgrep")
270270
if not configured:
271271
assert response.status_code == 500

0 commit comments

Comments
 (0)