cmem-plugin-validation 1.3.1__tar.gz → 1.3.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cmem-plugin-validation
3
- Version: 1.3.1
3
+ Version: 1.3.3
4
4
  Summary: Validate graph and data structures.
5
5
  License: Apache-2.0
6
6
  License-File: LICENSE
@@ -14,6 +14,7 @@ Classifier: License :: OSI Approved :: Apache Software License
14
14
  Classifier: Programming Language :: Python :: 3
15
15
  Classifier: Programming Language :: Python :: 3.13
16
16
  Classifier: Programming Language :: Python :: 3.14
17
+ Classifier: Programming Language :: Python :: 3.15
17
18
  Requires-Dist: cmem-client (>=1.0.0,<2.0.0)
18
19
  Requires-Dist: cmem-plugin-base (>=4.20.0,<5.0.0)
19
20
  Requires-Dist: httpx (>=0.27.0,<0.28.0)
@@ -39,32 +39,26 @@ The used JSON Schema needs to be provided as a JSON Dataset in the project.
39
39
 
40
40
  ### Input Modes
41
41
 
42
- The plugin supports two input modes for validation:
43
-
44
- 1. **Validate Entities**: Validates entities received from the input port in the workflow.
45
- 2. **Validate JSON Dataset**: Validates a JSON dataset stored in the project.
46
- - If the JSON dataset is a JSON array, the schema will validate each object inside the array.
47
- - If the JSON dataset is a JSON object, it will be validated against the schema directly.
48
-
49
- Validated data objects can be sent to an output port for further processing in the workflow
50
- or saved in a JSON dataset in the project.
42
+ Entities arrive on the input port by default. Switching the input mode to a JSON dataset
43
+ removes the input port, and the resources to validate are instead read from a JSON dataset in
44
+ the project. A JSON array in that dataset has each of its objects validated individually; a
45
+ JSON object is validated directly.
51
46
 
52
47
  ### Output Modes
53
48
 
54
- 1. **Valid JSON objects sent to Output Port**: Valid JSON objects can be sent as entities
55
- to the output port.
56
- 2. **Saved in JSON Dataset**: Valid JSON objects can be stored in a specified JSON dataset
57
- in the project.
49
+ Valid JSON objects are sent to an output port by default, ready for further processing in the
50
+ workflow. Switching the output mode to a JSON dataset removes the output port, and the valid
51
+ JSON objects are instead saved to a JSON dataset in the project, replacing its existing content.
58
52
 
59
53
  ### Error Handling
60
54
 
61
- The task can either:
55
+ Every entity or object is validated regardless of the outcome. The task can then either:
62
56
 
63
- - Fail instantly if there is a data violation, halting the workflow.
64
- - Provide warnings in the workflow report, allowing follow-up tasks to run based on the
57
+ - Fail once validation completes if any entity has violations, halting the workflow.
58
+ - Report violations only as warnings, allowing follow-up tasks to run based on the
65
59
  validated data.
66
60
 
67
- The error handling behavior is configurable through the `Fail on violations` parameter.
61
+ The error handling behavior is configurable through the **Fail on violations** parameter.
68
62
  """
69
63
 
70
64
 
@@ -88,9 +82,9 @@ TARGET.dataset = "dataset"
88
82
  TARGET.options = OrderedDict(
89
83
  {
90
84
  TARGET.dataset: f"{TARGET.dataset}: "
91
- "Valid JSON objects will be is saved in a JSON dataset (see advanced options).",
85
+ "Valid JSON objects are saved in a JSON dataset (see advanced options).",
92
86
  TARGET.entities: f"{TARGET.entities}: "
93
- "Valid JSON objects will be send as entities to the output port.",
87
+ "Valid JSON objects are sent as entities to the output port.",
94
88
  }
95
89
  )
96
90
 
@@ -105,21 +99,24 @@ TARGET.options = OrderedDict(
105
99
  PluginParameter(
106
100
  name="source_mode",
107
101
  label="Source / Input Mode",
108
- description="",
102
+ description="Selects where entities to validate come from: the input port or"
103
+ " a JSON dataset.",
109
104
  param_type=ChoiceParameterType(SOURCE.options),
110
105
  default_value=SOURCE.entities,
111
106
  ),
112
107
  PluginParameter(
113
108
  name="target_mode",
114
109
  label="Target / Output Mode",
115
- description="",
110
+ description="Selects where valid JSON objects are written to: the output port"
111
+ " or a JSON dataset.",
116
112
  param_type=ChoiceParameterType(TARGET.options),
117
113
  default_value=TARGET.entities,
118
114
  ),
119
115
  PluginParameter(
120
116
  name="source_dataset",
121
117
  label="Source JSON Dataset",
122
- description="This dataset holds the resources you want to validate.",
118
+ description="This dataset holds the resources you want to validate. Required when"
119
+ " Source / Input Mode is set to dataset; leave it empty when using entities.",
123
120
  param_type=DatasetParameterType(dataset_type="json"),
124
121
  advanced=True,
125
122
  default_value="",
@@ -127,8 +124,9 @@ TARGET.options = OrderedDict(
127
124
  PluginParameter(
128
125
  name="target_dataset",
129
126
  label="Target JSON Dataset",
130
- description="This dataset will be used to store the valid JSON objects"
131
- " after validation.",
127
+ description="This dataset stores the valid JSON objects after validation,"
128
+ " replacing any existing content. Required when Target / Output Mode is set to"
129
+ " dataset; leave it empty when using entities.",
132
130
  param_type=DatasetParameterType(dataset_type="json"),
133
131
  default_value="",
134
132
  advanced=True,
@@ -142,7 +140,9 @@ TARGET.options = OrderedDict(
142
140
  PluginParameter(
143
141
  name="fail_on_violations",
144
142
  label="Fail on violations",
145
- description="If enabled, the task will fail on the first data violation.",
143
+ description="If enabled, the workflow fails once validation completes if any"
144
+ " entity has violations. All entities are validated either way; disabling this"
145
+ " instead reports the violations as warnings.",
146
146
  default_value=DEFAULT_FAIL_ON_VIOLATION,
147
147
  ),
148
148
  ],
@@ -286,7 +286,9 @@ class ValidateEntity(WorkflowPlugin):
286
286
  Client.from_context(context=context).datasets.post_file_resource(
287
287
  project_id=context.task.project_id(),
288
288
  dataset_id=self.target_dataset,
289
- file_resource=io.BytesIO(json.dumps(valid_json_objects).encode("utf-8")),
289
+ file_resource=io.BytesIO(
290
+ json.dumps(valid_json_objects, ensure_ascii=False).encode("utf-8")
291
+ ),
290
292
  )
291
293
  return None
292
294
 
@@ -14,6 +14,7 @@ class State:
14
14
  total: int
15
15
  with_violations: int
16
16
  violations: int
17
+ error: str | None
17
18
 
18
19
  def __init__(self, client: Client, id_: str):
19
20
  self.client = client
@@ -29,3 +30,4 @@ class State:
29
30
  self.total = aggregation.resource_count
30
31
  self.with_violations = aggregation.resources_with_violations_count
31
32
  self.violations = aggregation.violations_count
33
+ self.error = aggregation.error
@@ -6,7 +6,12 @@ from time import sleep
6
6
 
7
7
  from cmem_client.client import Client
8
8
  from cmem_client.models.query_catalog import Query
9
- from cmem_client.models.validation import STATUS_RUNNING, STATUS_SCHEDULED, ValidationViolation
9
+ from cmem_client.models.validation import (
10
+ STATUS_FINISHED,
11
+ STATUS_RUNNING,
12
+ STATUS_SCHEDULED,
13
+ ValidationViolation,
14
+ )
10
15
  from cmem_plugin_base.dataintegration.context import ExecutionContext, ExecutionReport
11
16
  from cmem_plugin_base.dataintegration.description import Icon, Plugin, PluginParameter
12
17
  from cmem_plugin_base.dataintegration.entity import (
@@ -27,8 +32,25 @@ from httpx import HTTPStatusError
27
32
  from cmem_plugin_validation.validate_graph.state import State
28
33
 
29
34
  DOCUMENTATION = """
30
- Start a graph validation process which verifies, that resources in a specific graph are valid
31
- according to the node shapes in a shape catalog graph.
35
+ Starts a graph validation process which verifies that resources in a specific graph are valid
36
+ according to the node shapes in a shape catalog graph. The task waits for the validation to
37
+ finish before completing.
38
+
39
+ The task has no input port. Violations found during validation are always summarized in the
40
+ workflow report, and can also be materialized into a result graph in the project. Sending each
41
+ violation as an entity to an output port is optional; when that is disabled, the task has no
42
+ output port either.
43
+
44
+ ### Error Handling
45
+
46
+ Every resource is validated regardless of the outcome. The task can then either:
47
+
48
+ - Fail once validation completes if any resource has violations, halting the workflow.
49
+ - Report violations only as warnings, allowing follow-up tasks to run based on the results.
50
+
51
+ The error handling behavior is configurable through the **Fail workflow on violations**
52
+ parameter. If the validation process itself ends with an error or is cancelled on the server,
53
+ the task fails regardless of this parameter.
32
54
  """
33
55
 
34
56
  CONTEXT_GRAPH_CLASSES = [
@@ -92,23 +114,30 @@ WHERE { ?resource a ?class . FILTER isIRI(?resource) }
92
114
  PluginParameter(
93
115
  name="clear_result_graph",
94
116
  label="Clear result graph before validation",
117
+ description="If enabled, the existing content of the result graph is deleted"
118
+ " before validation starts. Has no effect when Result graph is left empty.",
95
119
  default_value=DEFAULT_CLEAR_RESULT_GRAPH,
96
120
  ),
97
121
  PluginParameter(
98
122
  name="fail_on_violations",
99
123
  label="Fail workflow on violations",
124
+ description="If enabled, the workflow fails once validation completes if any"
125
+ " resource has violations. All resources are validated either way; disabling this"
126
+ " instead reports the violations as warnings.",
100
127
  default_value=DEFAULT_FAIL_ON_VIOLATION,
101
128
  ),
102
129
  PluginParameter(
103
130
  name="output_results",
104
131
  label="Output violations as entities",
132
+ description="If enabled, each violation is sent as an entity to an output port"
133
+ " for further processing in the workflow. Disabling this removes the output port.",
105
134
  default_value=DEFAULT_OUTPUT_RESULTS,
106
135
  ),
107
136
  PluginParameter(
108
137
  name="sparql_query",
109
138
  label="Resource Selection Query",
110
139
  description="The query to select the resources to validate. "
111
- "Use {{context_graph}} as a placeholder for the select context graph for validation.",
140
+ "Use `{{context_graph}}` as a placeholder for the selected Context Graph.",
112
141
  default_value=DEFAULT_SPARQL_QUERY,
113
142
  advanced=True,
114
143
  ),
@@ -206,13 +235,26 @@ class ValidateGraph(WorkflowPlugin):
206
235
  continue
207
236
  # when reported as finished, error or cancelled break out
208
237
  break
238
+ if state.status != STATUS_FINISHED:
239
+ failure = state.error or f"Validation process ended in state {state.status}."
240
+ context.report.update(
241
+ ExecutionReport(
242
+ entity_count=state.completed,
243
+ operation="read",
244
+ operation_desc=f"/ {state.total} Resources validated",
245
+ error=failure,
246
+ )
247
+ )
248
+ raise RuntimeError(failure)
209
249
  summary: list[tuple[str, str]] = [
210
250
  (data_key, str(state.data[data_key])) for data_key in state.data
211
251
  ]
212
- validation_message = (
213
- f"Found {state.violations} Violations "
214
- f"in {state.with_violations} / {state.total} Resources."
215
- )
252
+ validation_message = None
253
+ if state.with_violations:
254
+ validation_message = (
255
+ f"Found {state.violations} Violations "
256
+ f"in {state.with_violations} / {state.total} Resources."
257
+ )
216
258
  context.report.update(
217
259
  ExecutionReport(
218
260
  entity_count=state.with_violations,
@@ -220,7 +262,9 @@ class ValidateGraph(WorkflowPlugin):
220
262
  operation_desc=f"/ {state.total} Resources have violations",
221
263
  summary=summary,
222
264
  error=validation_message if self.fail_on_violations else None,
223
- warnings=[validation_message] if not self.fail_on_violations else [],
265
+ warnings=[validation_message]
266
+ if validation_message and not self.fail_on_violations
267
+ else [],
224
268
  )
225
269
  )
226
270
  if not self.output_results:
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "cmem-plugin-validation"
3
- version = "1.3.1"
3
+ version = "1.3.3"
4
4
  license = "Apache-2.0"
5
5
  description = "Validate graph and data structures."
6
6
  authors = ["eccenca GmbH <cmempy-developer@eccenca.com>"]
@@ -42,7 +42,7 @@ pytest-dotenv = "^0.5.2"
42
42
  pytest-html = "^4.2.0"
43
43
  pytest-memray = { version = "^1.10.0", markers = "platform_system != 'Windows'" }
44
44
  ruff = "^0.16.2"
45
- trivy-py-ecc = "^0.73.0.1"
45
+ trivy-py-ecc = "^0.76.0.1"
46
46
 
47
47
  [build-system]
48
48
  requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning"]
@@ -103,10 +103,12 @@ ignore = [
103
103
  "ISC001", # single-line-implicit-string-concatenation
104
104
  "PD", # opinionated linting for pandas code
105
105
  "TRY003", # Avoid specifying long messages outside the exception class
106
+ "TRY400", # PluginLogger has no exception(), so error() is the only option
106
107
  ]
107
108
 
108
109
  [tool.ruff.lint.per-file-ignores]
109
110
  "tests/**/*.py" = [
110
111
  "S101", # asserts allowed in tests
111
112
  "ARG", # unused function args (pytest fixtures)
113
+ "PLR2004", # in an assertion the expected value is the literal
112
114
  ]