Skip to content

Commit

Permalink
Rebox a single-string names supplied to register().
Browse files Browse the repository at this point in the history
  • Loading branch information
LTLA committed Aug 6, 2024
1 parent 4830603 commit 73e288d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/sewerrat/register.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Optional
from typing import List, Optional, Union
import requests
import os
import warnings
Expand All @@ -7,7 +7,7 @@
from . import _utils as ut


def register(path: str, names: List[str], url: str, retry: int = 3, wait: int = 1):
def register(path: str, names: Union[str, List[str]], url: str, retry: int = 3, wait: int = 1):
"""
Register a directory into the SewerRat search index. It is assumed that
that the directory is world-readable and that the caller has write access.
Expand All @@ -21,7 +21,8 @@ def register(path: str, names: List[str], url: str, retry: int = 3, wait: int =
names:
List of strings containing the base names of metadata files inside
``path`` to be indexed.
``path`` to be indexed. Alternatively, a single string containing
the base name for a single metadata file.
url:
URL to the SewerRat REST API.
Expand All @@ -35,7 +36,9 @@ def register(path: str, names: List[str], url: str, retry: int = 3, wait: int =
Number of seconds to wait for a file write to synchronise before
requesting verification during each retry.
"""
if len(names) == 0:
if isinstance(names, str):
names = [names]
elif len(names) == 0:
raise ValueError("expected at least one entry in 'names'")

path = ut.clean_path(path)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ def test_basic():
res = sewerrat.query(url, "aaron")
assert len(res) == 0

# We can also register a string.
sewerrat.register(mydir, "metadata.json", url=url)

res = sewerrat.query(url, "aaron")
assert len(res) == 1

finally:
# Okay, stop the service:
sewerrat.stop_sewerrat()

0 comments on commit 73e288d

Please sign in to comment.