diff --git a/src/dsp_tools/cli/entry_point.py b/src/dsp_tools/cli/entry_point.py index e897f1529..fab4b1d50 100644 --- a/src/dsp_tools/cli/entry_point.py +++ b/src/dsp_tools/cli/entry_point.py @@ -38,7 +38,6 @@ def run(args: list[str]) -> None: UserError: if user input was wrong InputError: if user input was wrong InternalError: if the user cannot fix it - RetryError: if the problem may disappear when trying again later """ _check_version() default_dsp_api_url = "http://0.0.0.0:3333" diff --git a/src/dsp_tools/models/exceptions.py b/src/dsp_tools/models/exceptions.py index a3cb3cf2b..5316c2de3 100644 --- a/src/dsp_tools/models/exceptions.py +++ b/src/dsp_tools/models/exceptions.py @@ -42,29 +42,6 @@ def __init__(self, custom_msg: str | None = None, keep_default_msg: bool = True) super().__init__(default_msg) -class RetryError(BaseError): - """A class for errors where the user should try again later.""" - - def __init__(self, custom_msg: str | None = None, keep_default_msg: bool = True) -> None: - default_msg = ( - "\n\nAn internal error occurred.\n" - "Please contact the dsp-tools development team with the following information:\n" - " - Which command was used.\n" - " - If applicable, any files that were used in conjunction with the command.\n" - " - A file with the terminal output copied into.\n" - " - The log files called 'logging.log', if there are several, include all.\n" - f" They can be found at: {Path.home() / Path('.dsp-tools')}\n" - ) - match keep_default_msg, custom_msg: - case False, str(): - super().__init__(custom_msg) # type: ignore[arg-type] - case True, str(): - default_msg = f"\n\n{custom_msg}\n--------------------------{default_msg}" - super().__init__(default_msg) - case _: - super().__init__(default_msg) - - class InputError(BaseError): """Class for errors that is called when the user input is invalid.""" diff --git a/src/dsp_tools/utils/shared.py b/src/dsp_tools/utils/shared.py index f0c6fd016..0ae032886 100644 --- a/src/dsp_tools/utils/shared.py +++ b/src/dsp_tools/utils/shared.py @@ -1,7 +1,6 @@ from __future__ import annotations import copy -import glob import importlib.resources import json import unicodedata @@ -250,17 +249,3 @@ def parse_json_input(project_file_as_path_or_parsed: Union[str, Path, dict[str, else: raise BaseError("Invalid input: The input must be a path to a JSON file or a parsed JSON object.") return project_definition - - -def get_most_recent_glob_match(glob_pattern: Union[str, Path]) -> Path: - """ - Find the most recently created file that matches a glob pattern. - - Args: - glob_pattern: glob pattern, either absolute or relative to the cwd of the caller - - Returns: - the most recently created file that matches the glob pattern - """ - candidates = [Path(x) for x in glob.glob(str(glob_pattern))] - return max(candidates, key=lambda item: item.stat().st_ctime) diff --git a/test/e2e/commands/test_create_get_xmlupload.py b/test/e2e/commands/test_create_get_xmlupload.py index 98b7ac808..5ec51f942 100644 --- a/test/e2e/commands/test_create_get_xmlupload.py +++ b/test/e2e/commands/test_create_get_xmlupload.py @@ -1,8 +1,9 @@ +import glob import json import shutil import unittest from pathlib import Path -from typing import Any, Optional, cast +from typing import Any, Optional, Union, cast import regex @@ -10,7 +11,6 @@ from dsp_tools.commands.project.create.project_create import create_project from dsp_tools.commands.project.get import get_project from dsp_tools.commands.xmlupload.xmlupload import xmlupload -from dsp_tools.utils.shared import get_most_recent_glob_match # ruff: noqa: PT009 (pytest-unittest-assertion) (remove this line when pytest is used instead of unittest) @@ -68,7 +68,7 @@ def test_xml_upload_incremental(self) -> None: ) self.assertTrue(success) - mapping_file = get_most_recent_glob_match("test-data-systematic_id2iri_mapping_*.json") + mapping_file = self._get_most_recent_glob_match("test-data-systematic_id2iri_mapping_*.json") second_xml_file_orig = Path("testdata/id2iri/test-id2iri-data.xml") success = id2iri( xml_file=str(second_xml_file_orig), @@ -77,7 +77,7 @@ def test_xml_upload_incremental(self) -> None: mapping_file.unlink() self.assertTrue(success) - second_xml_file_replaced = get_most_recent_glob_match(f"{second_xml_file_orig.stem}_replaced_*.xml") + second_xml_file_replaced = self._get_most_recent_glob_match(f"{second_xml_file_orig.stem}_replaced_*.xml") success = xmlupload( input_file=second_xml_file_replaced, server=self.server, @@ -499,3 +499,17 @@ def _remove_onto_names_in_original_resources( if any(sup.startswith(onto_name) for sup in supers_as_list): res["super"] = [regex.sub(rf"^{onto_name}:", ":", sup) for sup in supers_as_list] return resources_original + + @staticmethod + def _get_most_recent_glob_match(glob_pattern: Union[str, Path]) -> Path: + """ + Find the most recently created file that matches a glob pattern. + + Args: + glob_pattern: glob pattern, either absolute or relative to the cwd of the caller + + Returns: + the most recently created file that matches the glob pattern + """ + candidates = [Path(x) for x in glob.glob(str(glob_pattern))] + return max(candidates, key=lambda item: item.stat().st_ctime)