Skip to content

Commit

Permalink
chore: delete dead code fragments (#792)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nora-Olivia-Ammann committed Feb 1, 2024
1 parent 24fdc9f commit c5b9872
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 43 deletions.
1 change: 0 additions & 1 deletion src/dsp_tools/cli/entry_point.py
Expand Up @@ -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"
Expand Down
23 changes: 0 additions & 23 deletions src/dsp_tools/models/exceptions.py
Expand Up @@ -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."""

Expand Down
15 changes: 0 additions & 15 deletions 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
Expand Down Expand Up @@ -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)
22 changes: 18 additions & 4 deletions test/e2e/commands/test_create_get_xmlupload.py
@@ -1,16 +1,16 @@
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

from dsp_tools.commands.id2iri import id2iri
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)

Expand Down Expand Up @@ -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),
Expand All @@ -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,
Expand Down Expand Up @@ -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)

0 comments on commit c5b9872

Please sign in to comment.