From 0867e4e72b3f69d58c823998cf4f2eae70f73964 Mon Sep 17 00:00:00 2001 From: muddymudskipper Date: Tue, 25 Jun 2024 10:02:35 +0100 Subject: [PATCH] capture ROBOT errors, validate result graph IRI --- TaskfileCustom.yaml | 2 +- cmem_plugin_robotreason/plugin_robotreason.py | 10 ++++++++-- poetry.lock | 13 ++++++++++++- pyproject.toml | 1 + 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/TaskfileCustom.yaml b/TaskfileCustom.yaml index dd3bf72..a073589 100644 --- a/TaskfileCustom.yaml +++ b/TaskfileCustom.yaml @@ -7,7 +7,7 @@ vars: tasks: download_robot: - desc: Download ROBOT jar and bash script + desc: Download ROBOT jar cmds: - mkdir -p {{.ROBOT_DIR}} - curl -L -C - -o {{.ROBOT_DIR}}/robot.jar https://github.com/ontodev/robot/releases/download/v1.9.6/robot.jar diff --git a/cmem_plugin_robotreason/plugin_robotreason.py b/cmem_plugin_robotreason/plugin_robotreason.py index 5b17d53..93e5761 100644 --- a/cmem_plugin_robotreason/plugin_robotreason.py +++ b/cmem_plugin_robotreason/plugin_robotreason.py @@ -16,6 +16,7 @@ tostring, ) +import validators.url from cmem.cmempy.dp.proxy.graph import get, get_graph_import_tree, post_streamed from cmem_plugin_base.dataintegration.context import ExecutionContext from cmem_plugin_base.dataintegration.description import Icon, Plugin, PluginParameter @@ -257,6 +258,8 @@ def __init__( # noqa: PLR0913 raise ValueError("Result graph IRI cannot be the same as the data graph IRI.") if result_iri == ontology_graph_iri: raise ValueError("Result graph IRI cannot be the same as the ontology graph IRI.") + if not validators.url(result_iri): + raise ValueError("Result graph IRI is invalid") def create_xml_catalog_file(self, graphs: dict) -> None: """Create XML catalog file""" @@ -354,8 +357,11 @@ def reason(self, graphs: dict) -> None: f'--typed-annotation dc:created "{utctime}" xsd:dateTime ' f'--output "{self.temp}/result.ttl"' ) - - run(shlex.split(cmd), check=False) # noqa: S603 + response = run(shlex.split(cmd), check=False, capture_output=True) # noqa: S603 + if response.stdout: + raise OSError(response.stdout.decode()) + if response.stderr: + raise OSError(response.stderr.decode()) def send_result(self) -> None: """Send result""" diff --git a/poetry.lock b/poetry.lock index 6f25017..c4a98a0 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1092,7 +1092,18 @@ h2 = ["h2 (>=4,<5)"] socks = ["pysocks (>=1.5.6,!=1.5.7,<2.0)"] zstd = ["zstandard (>=0.18.0)"] +[[package]] +name = "validators" +version = "0.28.3" +description = "Python Data Validation for Humans™" +optional = false +python-versions = ">=3.8" +files = [ + {file = "validators-0.28.3-py3-none-any.whl", hash = "sha256:53cafa854f13850156259d9cc479b864ee901f6a96e6b109e6fc33f98f37d99f"}, + {file = "validators-0.28.3.tar.gz", hash = "sha256:c6c79840bcde9ba77b19f6218f7738188115e27830cbaff43264bc4ed24c429d"}, +] + [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "58096571d5b79f1ffc9be4534d0af8e1d55938cab558a9f616bdf9269ed70aa8" +content-hash = "0c296294a0aa055cea39bcd72f980f91a716f321a1900c738f6b8f3f830029f5" diff --git a/pyproject.toml b/pyproject.toml index d37d9c6..d6b0b41 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,6 +21,7 @@ homepage = "https://github.com/eccenca/cmem-plugin-robotreason" # if you need to change python version here, change it also in .python-version python = "^3.11" defusedxml = "^0.7.1" +validators = "^0.28.3" [tool.poetry.dependencies.cmem-plugin-base] version = "^4.5.0"