From aebc29d02356b59161ad5823582af603c17fed01 Mon Sep 17 00:00:00 2001 From: Friedrich Lindenberg Date: Wed, 17 Jul 2024 10:29:21 +0200 Subject: [PATCH] Fix utils to allow changing ENTITY_INDEX in tests --- yente/search/util.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/yente/search/util.py b/yente/search/util.py index 01da6d27..8e352eca 100644 --- a/yente/search/util.py +++ b/yente/search/util.py @@ -1,4 +1,4 @@ -from yente.settings import ENTITY_INDEX, INDEX_VERSION +from yente import settings from typing import Tuple @@ -12,15 +12,15 @@ def parse_index_name(index: str) -> Tuple[str, str]: version: str The version of the index """ # TODO: If we assert that no dashes are allowed in index names we can remove this check. - if not index.startswith(ENTITY_INDEX): + if not index.startswith(settings.ENTITY_INDEX): raise ValueError("Index created with a different prefix and cannot be parsed.") - index_end = index[len(ENTITY_INDEX) + 1 :] + index_end = index[len(settings.ENTITY_INDEX) + 1 :] if "-" not in index_end: raise ValueError("Index name does not contain a version.") dataset, index_version = index_end.split("-", 1) - if not index_version.startswith(INDEX_VERSION): + if not index_version.startswith(settings.INDEX_VERSION): raise ValueError("Index version does not start with the correct prefix.") - dataset_version = index_version[len(INDEX_VERSION) :] + dataset_version = index_version[len(settings.INDEX_VERSION) :] if len(dataset_version) < 1: raise ValueError("Index version must be at least one character long.") return (dataset, dataset_version) @@ -28,20 +28,18 @@ def parse_index_name(index: str) -> Tuple[str, str]: def construct_index_name(ds_name: str, ds_version: str | None = None) -> str: """ - Given a dataset object and optionally a version construct a properly versioned index name. + Given a dataset and optionally a version construct a properly versioned index name. """ if len(str(ds_name)) < 1: raise ValueError("Dataset name must be at least one character long.") - base = f"{ENTITY_INDEX}-{ds_name}" + base = f"{settings.ENTITY_INDEX}-{ds_name}" if ds_version is None: return base return f"{base}-{construct_index_version(ds_version)}" def construct_index_version(version: str) -> str: - """ - Given a version string, return a version string with the version prefix. - """ + """Given a version ID, return a version string with the version prefix.""" if len(version) < 1: raise ValueError("Version must be at least one character long.") - return f"{INDEX_VERSION}{version}" + return f"{settings.INDEX_VERSION}{version}"