Skip to content

Commit

Permalink
capture ROBOT errors, validate result graph IRI
Browse files Browse the repository at this point in the history
  • Loading branch information
muddymudskipper committed Jun 25, 2024
1 parent 26bafcf commit 0867e4e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion TaskfileCustom.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions cmem_plugin_robotreason/plugin_robotreason.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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"""
Expand Down
13 changes: 12 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 0867e4e

Please sign in to comment.