jpipe-runner 3.2.0__tar.gz → 3.4.0__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.
- {jpipe_runner-3.2.0 → jpipe_runner-3.4.0}/PKG-INFO +4 -6
- {jpipe_runner-3.2.0 → jpipe_runner-3.4.0}/README.md +1 -4
- {jpipe_runner-3.2.0 → jpipe_runner-3.4.0}/pyproject.toml +5 -3
- jpipe_runner-3.4.0/src/jpipe_runner/framework/decorators/__init__.py +3 -0
- {jpipe_runner-3.2.0 → jpipe_runner-3.4.0}/src/jpipe_runner/framework/decorators/jpipe_decorator.py +1 -0
- jpipe_runner-3.4.0/src/jpipe_runner/framework/decorators/link_decorator.py +33 -0
- {jpipe_runner-3.2.0 → jpipe_runner-3.4.0}/src/jpipe_runner/framework/engine.py +93 -47
- {jpipe_runner-3.2.0 → jpipe_runner-3.4.0}/src/jpipe_runner/framework/validators.py +23 -45
- {jpipe_runner-3.2.0 → jpipe_runner-3.4.0}/src/jpipe_runner/runner.py +11 -10
- {jpipe_runner-3.2.0 → jpipe_runner-3.4.0}/src/jpipe_runner/runtime.py +21 -0
- jpipe_runner-3.4.0/src/jpipe_runner/schema/justification.schema.json +36 -0
- {jpipe_runner-3.2.0 → jpipe_runner-3.4.0}/LICENSE +0 -0
- {jpipe_runner-3.2.0 → jpipe_runner-3.4.0}/src/jpipe_runner/__init__.py +0 -0
- {jpipe_runner-3.2.0 → jpipe_runner-3.4.0}/src/jpipe_runner/__main__.py +0 -0
- {jpipe_runner-3.2.0 → jpipe_runner-3.4.0}/src/jpipe_runner/enums.py +0 -0
- {jpipe_runner-3.2.0 → jpipe_runner-3.4.0}/src/jpipe_runner/exceptions.py +0 -0
- {jpipe_runner-3.2.0 → jpipe_runner-3.4.0}/src/jpipe_runner/framework/__init__.py +0 -0
- {jpipe_runner-3.2.0 → jpipe_runner-3.4.0}/src/jpipe_runner/framework/context.py +0 -0
- {jpipe_runner-3.2.0 → jpipe_runner-3.4.0}/src/jpipe_runner/framework/decorators/contribution_decorator.py +0 -0
- {jpipe_runner-3.2.0 → jpipe_runner-3.4.0}/src/jpipe_runner/framework/decorators/skip_decorator.py +0 -0
- {jpipe_runner-3.2.0 → jpipe_runner-3.4.0}/src/jpipe_runner/framework/logger.py +0 -0
- {jpipe_runner-3.2.0/src/jpipe_runner/framework/decorators → jpipe_runner-3.4.0/src/jpipe_runner/schema}/__init__.py +0 -0
- {jpipe_runner-3.2.0 → jpipe_runner-3.4.0}/src/jpipe_runner/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: jpipe-runner
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.4.0
|
|
4
4
|
Summary: A Justification Runner designed for jPipe.
|
|
5
5
|
License: MIT
|
|
6
6
|
License-File: LICENSE
|
|
@@ -17,8 +17,9 @@ Classifier: Programming Language :: Python :: 3.13
|
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.14
|
|
18
18
|
Provides-Extra: docs
|
|
19
19
|
Provides-Extra: full
|
|
20
|
+
Requires-Dist: graphviz (>=0.20)
|
|
21
|
+
Requires-Dist: jsonschema (>=4.0)
|
|
20
22
|
Requires-Dist: networkx (==3.5)
|
|
21
|
-
Requires-Dist: pygraphviz (==1.14)
|
|
22
23
|
Requires-Dist: pyyaml (==6.0.2)
|
|
23
24
|
Requires-Dist: sphinx (==8.1.3) ; extra == "docs" or extra == "full"
|
|
24
25
|
Project-URL: Homepage, https://github.com/jpipe-mcscert/jpipe-runner
|
|
@@ -44,7 +45,7 @@ A Justification Runner designed for jPipe.
|
|
|
44
45
|
```bash
|
|
45
46
|
poetry run jpipe-runner [-h] [--variable NAME:VALUE] [--library LIB] \
|
|
46
47
|
[--diagram PATTERN] [--output FILE] [--dry-run] \
|
|
47
|
-
[--verbose] [--config-file PATH]
|
|
48
|
+
[--verbose] [--config-file PATH] jd_file
|
|
48
49
|
```
|
|
49
50
|
|
|
50
51
|
**Key options:**
|
|
@@ -56,8 +57,6 @@ poetry run jpipe-runner [-h] [--variable NAME:VALUE] [--library LIB] \
|
|
|
56
57
|
* `--dry-run`: Validate workflow without executing.
|
|
57
58
|
* `--verbose`, `-V`: Enable debug logging.
|
|
58
59
|
* `--config-file`: Load workflow config from a YAML file.
|
|
59
|
-
* `--gui`: Launch the Tkinter-based `GraphWorkflowVisualizer`
|
|
60
|
-
|
|
61
60
|
Example:
|
|
62
61
|
|
|
63
62
|
```bash
|
|
@@ -74,7 +73,6 @@ For detailed instructions on how to execute the project, including descriptions
|
|
|
74
73
|
* Python 3.10+
|
|
75
74
|
* [Poetry](https://python-poetry.org)
|
|
76
75
|
* [Graphviz](https://graphviz.org/) (`libgraphviz-dev`, `pkg-config`)
|
|
77
|
-
* Optional for GUI version: [Tkinter](https://docs.python.org/3/library/tkinter.html)
|
|
78
76
|
|
|
79
77
|
### From Source
|
|
80
78
|
|
|
@@ -18,7 +18,7 @@ A Justification Runner designed for jPipe.
|
|
|
18
18
|
```bash
|
|
19
19
|
poetry run jpipe-runner [-h] [--variable NAME:VALUE] [--library LIB] \
|
|
20
20
|
[--diagram PATTERN] [--output FILE] [--dry-run] \
|
|
21
|
-
[--verbose] [--config-file PATH]
|
|
21
|
+
[--verbose] [--config-file PATH] jd_file
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
**Key options:**
|
|
@@ -30,8 +30,6 @@ poetry run jpipe-runner [-h] [--variable NAME:VALUE] [--library LIB] \
|
|
|
30
30
|
* `--dry-run`: Validate workflow without executing.
|
|
31
31
|
* `--verbose`, `-V`: Enable debug logging.
|
|
32
32
|
* `--config-file`: Load workflow config from a YAML file.
|
|
33
|
-
* `--gui`: Launch the Tkinter-based `GraphWorkflowVisualizer`
|
|
34
|
-
|
|
35
33
|
Example:
|
|
36
34
|
|
|
37
35
|
```bash
|
|
@@ -48,7 +46,6 @@ For detailed instructions on how to execute the project, including descriptions
|
|
|
48
46
|
* Python 3.10+
|
|
49
47
|
* [Poetry](https://python-poetry.org)
|
|
50
48
|
* [Graphviz](https://graphviz.org/) (`libgraphviz-dev`, `pkg-config`)
|
|
51
|
-
* Optional for GUI version: [Tkinter](https://docs.python.org/3/library/tkinter.html)
|
|
52
49
|
|
|
53
50
|
### From Source
|
|
54
51
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "jpipe-runner"
|
|
3
|
-
version = "3.
|
|
3
|
+
version = "3.4.0"
|
|
4
4
|
description = "A Justification Runner designed for jPipe."
|
|
5
5
|
authors = [
|
|
6
6
|
"Jason Lyu <xjasonlyu@gmail.com>",
|
|
@@ -16,14 +16,16 @@ classifiers = [
|
|
|
16
16
|
"Operating System :: OS Independent"
|
|
17
17
|
]
|
|
18
18
|
packages = [
|
|
19
|
-
{ include = "jpipe_runner", from = "src" }
|
|
19
|
+
{ include = "jpipe_runner", from = "src" },
|
|
20
|
+
{ include = "jpipe_runner/schema", from = "src" }
|
|
20
21
|
]
|
|
21
22
|
|
|
22
23
|
[tool.poetry.dependencies]
|
|
23
24
|
python = ">=3.11"
|
|
24
25
|
networkx = "3.5"
|
|
25
|
-
|
|
26
|
+
graphviz = ">=0.20"
|
|
26
27
|
pyyaml = "6.0.2"
|
|
28
|
+
jsonschema = ">=4.0"
|
|
27
29
|
|
|
28
30
|
sphinx = { version = "8.1.3", optional = true }
|
|
29
31
|
|
{jpipe_runner-3.2.0 → jpipe_runner-3.4.0}/src/jpipe_runner/framework/decorators/jpipe_decorator.py
RENAMED
|
@@ -5,6 +5,7 @@ from functools import wraps
|
|
|
5
5
|
from typing import Any, Callable, List, Optional
|
|
6
6
|
|
|
7
7
|
from jpipe_runner.framework.context import RuntimeContext, ctx
|
|
8
|
+
from jpipe_runner.framework.decorators.link_decorator import jpipe_link # noqa: F401
|
|
8
9
|
from jpipe_runner.framework.logger import GLOBAL_LOGGER
|
|
9
10
|
|
|
10
11
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from typing import Callable, TypeVar
|
|
2
|
+
|
|
3
|
+
F = TypeVar("F", bound=Callable)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def jpipe_link(element_id: str) -> Callable[[F], F]:
|
|
7
|
+
"""
|
|
8
|
+
Decorator to explicitly bind a Python function to a JSON pipeline element by its id.
|
|
9
|
+
|
|
10
|
+
This removes the fragile label-to-function-name mapping: instead of requiring
|
|
11
|
+
the function name to match the sanitized form of the JSON label, the decorator
|
|
12
|
+
records the element id directly on the function.
|
|
13
|
+
|
|
14
|
+
Compatible with @jpipe, @skip, and @contribution in any stacking order, because
|
|
15
|
+
all three use @wraps which propagates __dict__ attributes to their wrappers.
|
|
16
|
+
|
|
17
|
+
:param element_id: The id of the JSON element this function implements (e.g. "E1").
|
|
18
|
+
:type element_id: str
|
|
19
|
+
|
|
20
|
+
Example::
|
|
21
|
+
|
|
22
|
+
@jpipe_link("E1")
|
|
23
|
+
@jpipe(consume=["file_path"], produce=["file_exists"])
|
|
24
|
+
def check_file(file_path, produce):
|
|
25
|
+
produce("file_exists", os.path.isfile(file_path))
|
|
26
|
+
return True
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
def decorator(func: F) -> F:
|
|
30
|
+
func.__jpipe_link_id__ = element_id
|
|
31
|
+
return func
|
|
32
|
+
|
|
33
|
+
return decorator
|
|
@@ -312,7 +312,12 @@ class PipelineEngine:
|
|
|
312
312
|
cycle = None
|
|
313
313
|
|
|
314
314
|
if cycle:
|
|
315
|
-
cycle_labels = [
|
|
315
|
+
cycle_labels = [
|
|
316
|
+
f"{label} ({self._qualified_id(n)})"
|
|
317
|
+
if (label := self.graph.nodes[n].get("label"))
|
|
318
|
+
else self._qualified_id(n)
|
|
319
|
+
for n in cycle
|
|
320
|
+
]
|
|
316
321
|
error_msg = (
|
|
317
322
|
"[ExecutionOrder]\n"
|
|
318
323
|
"Pipeline validation error: cycle detected in justification graph.\n"
|
|
@@ -358,6 +363,8 @@ class PipelineEngine:
|
|
|
358
363
|
"""
|
|
359
364
|
GLOBAL_LOGGER.info("Running pipeline...")
|
|
360
365
|
|
|
366
|
+
self._apply_link_registry(runtime.build_link_registry())
|
|
367
|
+
|
|
361
368
|
if not self._validate_pipeline():
|
|
362
369
|
return
|
|
363
370
|
|
|
@@ -368,6 +375,52 @@ class PipelineEngine:
|
|
|
368
375
|
for node in execution_order:
|
|
369
376
|
yield self._process_node(node, runtime, dry_run)
|
|
370
377
|
|
|
378
|
+
def _apply_link_registry(self, registry: dict[str, str]) -> None:
|
|
379
|
+
"""
|
|
380
|
+
Override the stored function_name for nodes that have an explicit @jpipe_link binding.
|
|
381
|
+
|
|
382
|
+
Called before validation so that all downstream lookups (skip checks, contribution
|
|
383
|
+
lookups, function dispatch) use the correct function name instead of the sanitized label.
|
|
384
|
+
|
|
385
|
+
Supports two id formats:
|
|
386
|
+
- Plain element id: ``"e1"``
|
|
387
|
+
- Qualified id with justification name: ``"performant:e1"``
|
|
388
|
+
|
|
389
|
+
:param registry: Mapping of link_id → attr_name produced by runtime.build_link_registry().
|
|
390
|
+
:type registry: dict[str, str]
|
|
391
|
+
"""
|
|
392
|
+
for link_id, attr_name in registry.items():
|
|
393
|
+
node_id = self._resolve_node_id(link_id)
|
|
394
|
+
if node_id is not None:
|
|
395
|
+
GLOBAL_LOGGER.debug(
|
|
396
|
+
"Linking node '%s' to function '%s' via @jpipe_link.", node_id, attr_name
|
|
397
|
+
)
|
|
398
|
+
self.graph.nodes[node_id]["function_name"] = attr_name
|
|
399
|
+
|
|
400
|
+
def _qualified_id(self, node_id: str) -> str:
|
|
401
|
+
"""Return the fully qualified node id (``justification_name:node_id``)."""
|
|
402
|
+
return f"{self.justification_name}:{node_id}"
|
|
403
|
+
|
|
404
|
+
def _resolve_node_id(self, link_id: str) -> str | None:
|
|
405
|
+
"""
|
|
406
|
+
Resolve a @jpipe_link id to a graph node id.
|
|
407
|
+
|
|
408
|
+
Accepts plain ids (``"e1"``) or qualified ids (``"justification_name:e1"``).
|
|
409
|
+
For qualified ids the justification-name prefix must match this pipeline's name.
|
|
410
|
+
|
|
411
|
+
:param link_id: The id value passed to @jpipe_link.
|
|
412
|
+
:type link_id: str
|
|
413
|
+
:return: The matching graph node id, or None if not found.
|
|
414
|
+
:rtype: str | None
|
|
415
|
+
"""
|
|
416
|
+
if link_id in self.graph.nodes:
|
|
417
|
+
return link_id
|
|
418
|
+
if ":" in link_id:
|
|
419
|
+
qualifier, element_id = link_id.rsplit(":", 1)
|
|
420
|
+
if qualifier == self.justification_name and element_id in self.graph.nodes:
|
|
421
|
+
return element_id
|
|
422
|
+
return None
|
|
423
|
+
|
|
371
424
|
def _validate_pipeline(self) -> bool:
|
|
372
425
|
"""
|
|
373
426
|
Validates the justification graph and updates visualization markers accordingly.
|
|
@@ -417,7 +470,7 @@ class PipelineEngine:
|
|
|
417
470
|
node_data = self.graph.nodes[node]
|
|
418
471
|
node_type = node_data.get("type")
|
|
419
472
|
label = node_data.get("label")
|
|
420
|
-
fn_name =
|
|
473
|
+
fn_name = node_data.get("function_name")
|
|
421
474
|
exception = None
|
|
422
475
|
|
|
423
476
|
GLOBAL_LOGGER.debug("Processing node: %s", node)
|
|
@@ -428,7 +481,7 @@ class PipelineEngine:
|
|
|
428
481
|
status = StatusType.SKIP
|
|
429
482
|
exception = skip_config.get("reason", "Skipped by context")
|
|
430
483
|
GLOBAL_LOGGER.info(
|
|
431
|
-
f"Skipping function '{fn_name}' for node '{node}' due to context: {exception}"
|
|
484
|
+
f"Skipping function '{fn_name}' for node '{self._qualified_id(node)}' due to context: {exception}"
|
|
432
485
|
)
|
|
433
486
|
|
|
434
487
|
# --- Check if predecessor failure or implicit skip should block execution ---
|
|
@@ -483,8 +536,7 @@ class PipelineEngine:
|
|
|
483
536
|
for pred in self.graph.predecessors(node):
|
|
484
537
|
pred_data = self.graph.nodes[pred]
|
|
485
538
|
status = pred_data.get("status")
|
|
486
|
-
|
|
487
|
-
fn_name = sanitize_string(pred_label)
|
|
539
|
+
fn_name = pred_data.get("function_name")
|
|
488
540
|
|
|
489
541
|
if status is None or status == StatusType.FAIL:
|
|
490
542
|
return True
|
|
@@ -524,14 +576,14 @@ class PipelineEngine:
|
|
|
524
576
|
if not isinstance(result, bool):
|
|
525
577
|
raise FunctionException(
|
|
526
578
|
f"Function '{fn_name}' returned an unexpected type: {type(result).__name__}.\n"
|
|
527
|
-
f" - The function associated with node '{node}' (label: '{label}') must return either True or False.\n"
|
|
579
|
+
f" - The function associated with node '{self._qualified_id(node)}' (label: '{label}') must return either True or False.\n"
|
|
528
580
|
f" - Received: {result!r} ({type(result).__name__})\n"
|
|
529
581
|
f" - Please ensure the function implementation returns a boolean to indicate pass/fail status correctly."
|
|
530
582
|
)
|
|
531
583
|
if not result:
|
|
532
584
|
raise FunctionException(
|
|
533
585
|
f"\nFunction '{fn_name}' returned False, indicating failure.\n"
|
|
534
|
-
f" - The function associated with node '{node}' (label: '{label}') executed but did not pass its check.\n"
|
|
586
|
+
f" - The function associated with node '{self._qualified_id(node)}' (label: '{label}') executed but did not pass its check.\n"
|
|
535
587
|
f" - Please review the implementation and input data for this function.\n"
|
|
536
588
|
f" - Returned value: {result!r}\n"
|
|
537
589
|
f" - The function must return True to indicate a successful check."
|
|
@@ -592,21 +644,24 @@ class PipelineEngine:
|
|
|
592
644
|
:param filename: Output filename (without extension).
|
|
593
645
|
:param format: Image format string (e.g. "png", "svg", "pdf").
|
|
594
646
|
"""
|
|
595
|
-
|
|
596
|
-
from networkx.drawing.nx_agraph import to_agraph
|
|
597
|
-
except ImportError as e:
|
|
598
|
-
raise ImportError("pygraphviz is required to enable this feature") from e
|
|
647
|
+
import graphviz as gv
|
|
599
648
|
|
|
600
649
|
resolved_path = self._resolve_output_path(output_path, filename)
|
|
601
650
|
|
|
602
651
|
G = self.graph.copy()
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
self._style_nodes(
|
|
607
|
-
self._style_edges(
|
|
608
|
-
|
|
609
|
-
|
|
652
|
+
dot = gv.Digraph()
|
|
653
|
+
dot.attr(rankdir="BT")
|
|
654
|
+
|
|
655
|
+
self._style_nodes(dot, G, status_dict)
|
|
656
|
+
self._style_edges(dot, G, status_dict)
|
|
657
|
+
|
|
658
|
+
dot.render(
|
|
659
|
+
str(resolved_path),
|
|
660
|
+
format=format,
|
|
661
|
+
engine="dot",
|
|
662
|
+
cleanup=True,
|
|
663
|
+
outfile=str(resolved_path.with_suffix(f".{format}")),
|
|
664
|
+
)
|
|
610
665
|
|
|
611
666
|
@staticmethod
|
|
612
667
|
def _resolve_output_path(output_path: str, filename: str) -> Path:
|
|
@@ -623,63 +678,54 @@ class PipelineEngine:
|
|
|
623
678
|
return path / filename
|
|
624
679
|
|
|
625
680
|
@staticmethod
|
|
626
|
-
def _style_nodes(
|
|
681
|
+
def _style_nodes(dot: Any, G: nx.DiGraph, status_dict: dict[str, str]) -> None:
|
|
627
682
|
"""
|
|
628
683
|
Apply visual styles to graph nodes based on their type and execution status.
|
|
629
684
|
|
|
630
|
-
:param
|
|
685
|
+
:param dot: graphviz.Digraph instance to add nodes to.
|
|
631
686
|
:param G: NetworkX DiGraph with node attribute data.
|
|
632
687
|
:param status_dict: Mapping of node id -> status string ("PASS", "FAIL", "SKIP").
|
|
633
688
|
"""
|
|
634
689
|
node_attr_map = {
|
|
635
|
-
"conclusion":
|
|
636
|
-
"
|
|
637
|
-
"
|
|
638
|
-
"evidence":
|
|
639
|
-
"support":
|
|
690
|
+
"conclusion": {"shape": "rect", "style": "filled,rounded", "fillcolor": "lightgrey"},
|
|
691
|
+
"sub-conclusion": {"shape": "rect", "color": "#0072B2"},
|
|
692
|
+
"strategy": {"shape": "hexagon", "style": "filled", "fillcolor": "#F0C27F"},
|
|
693
|
+
"evidence": {"shape": "note", "style": "filled", "fillcolor": "#9ECAE1"},
|
|
694
|
+
"support": {"shape": "rect", "style": "dotted"},
|
|
640
695
|
}
|
|
641
696
|
for node_id, attrs in G.nodes(data=True):
|
|
642
697
|
var_type = attrs.get("type", "").lower()
|
|
643
|
-
style = node_attr_map.get(
|
|
698
|
+
style = dict(node_attr_map.get(
|
|
644
699
|
var_type, dict(fillcolor="white", shape="ellipse", style="filled")
|
|
645
|
-
)
|
|
646
|
-
n = A.get_node(node_id)
|
|
647
|
-
for k, v in style.items():
|
|
648
|
-
n.attr[k] = v
|
|
700
|
+
))
|
|
649
701
|
|
|
650
702
|
status = status_dict.get(node_id, "UNKNOWN")
|
|
651
703
|
logging.info("Setting node color for %s with status %s", node_id, status)
|
|
652
704
|
if status == StatusType.FAIL.name:
|
|
653
|
-
|
|
654
|
-
n.attr["fillcolor"] = "red"
|
|
655
|
-
n.attr["fontcolor"] = "white"
|
|
656
|
-
n.attr["fontname"] = "Helvetica-Bold"
|
|
705
|
+
style.update(style="filled", fillcolor="red", fontcolor="white", fontname="Helvetica-Bold")
|
|
657
706
|
elif status == StatusType.SKIP.name:
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
n.attr["fontname"] = "Helvetica-Bold"
|
|
707
|
+
style.update(style="filled", fillcolor="#cccccc", opacity="1", fontcolor="white", fontname="Helvetica-Bold")
|
|
708
|
+
|
|
709
|
+
label = attrs.get("label", node_id)
|
|
710
|
+
dot.node(node_id, label=label, **style)
|
|
663
711
|
|
|
664
712
|
@staticmethod
|
|
665
|
-
def _style_edges(
|
|
713
|
+
def _style_edges(dot: Any, G: nx.DiGraph, status_dict: dict[str, str]) -> None:
|
|
666
714
|
"""
|
|
667
715
|
Apply visual styles to graph edges based on the execution status of their source node.
|
|
668
716
|
|
|
669
|
-
:param
|
|
717
|
+
:param dot: graphviz.Digraph instance to add edges to.
|
|
670
718
|
:param G: NetworkX DiGraph with edge data.
|
|
671
719
|
:param status_dict: Mapping of node id -> status string ("PASS", "FAIL", "SKIP").
|
|
672
720
|
"""
|
|
673
721
|
for source, target in G.edges():
|
|
674
722
|
status = status_dict.get(source, "UNKNOWN")
|
|
675
723
|
logging.info("Setting edge color for %s -> %s with status %s", source, target, status)
|
|
676
|
-
e = A.get_edge(source, target)
|
|
677
724
|
if status == StatusType.PASS.name:
|
|
678
|
-
|
|
725
|
+
dot.edge(source, target, color="black")
|
|
679
726
|
elif status == StatusType.FAIL.name:
|
|
680
|
-
|
|
727
|
+
dot.edge(source, target, color="red")
|
|
681
728
|
elif status == StatusType.SKIP.name:
|
|
682
|
-
|
|
683
|
-
e.attr["opacity"] = "1"
|
|
729
|
+
dot.edge(source, target, color="#cccccc", opacity="1")
|
|
684
730
|
else:
|
|
685
|
-
|
|
731
|
+
dot.edge(source, target, color="gray")
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
+
import importlib.resources
|
|
2
|
+
import json
|
|
1
3
|
from typing import Any
|
|
2
4
|
|
|
5
|
+
import jsonschema
|
|
3
6
|
import networkx as nx
|
|
4
7
|
|
|
5
8
|
from jpipe_runner.framework.context import RuntimeContext
|
|
6
9
|
|
|
7
10
|
from .logger import GLOBAL_LOGGER
|
|
8
11
|
|
|
12
|
+
_schema_file = importlib.resources.files("jpipe_runner.schema").joinpath("justification.schema.json")
|
|
13
|
+
JUSTIFICATION_JSON_SCHEMA = json.loads(_schema_file.read_text(encoding="utf-8"))
|
|
14
|
+
|
|
9
15
|
|
|
10
16
|
class BaseValidator:
|
|
11
17
|
"""
|
|
@@ -522,9 +528,6 @@ class JustificationSchemaValidator:
|
|
|
522
528
|
ValueError: If any structural validation check fails.
|
|
523
529
|
"""
|
|
524
530
|
|
|
525
|
-
REQUIRED_TOP_KEYS = {"name", "type", "elements", "relations"}
|
|
526
|
-
VALID_TYPES = {"evidence", "strategy", "conclusion", "sub-conclusion"}
|
|
527
|
-
|
|
528
531
|
def __init__(self, data: dict[str, Any]) -> None:
|
|
529
532
|
"""
|
|
530
533
|
Initialize the validator with parsed justification JSON data.
|
|
@@ -539,19 +542,21 @@ class JustificationSchemaValidator:
|
|
|
539
542
|
"""
|
|
540
543
|
Executes the full validation pipeline on the justification structure.
|
|
541
544
|
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
545
|
+
Structural validation (required fields, types, enums) is delegated to
|
|
546
|
+
``JUSTIFICATION_JSON_SCHEMA`` via ``jsonschema``. Semantic checks that
|
|
547
|
+
go beyond what JSON Schema can express (ID uniqueness, cross-references)
|
|
548
|
+
are handled by the private helper methods below.
|
|
546
549
|
|
|
547
|
-
:raises ValueError: If any
|
|
550
|
+
:raises ValueError: If any structural or semantic check fails.
|
|
548
551
|
"""
|
|
549
552
|
GLOBAL_LOGGER.debug("Starting justification schema validation")
|
|
550
553
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
554
|
+
try:
|
|
555
|
+
jsonschema.validate(instance=self.data, schema=JUSTIFICATION_JSON_SCHEMA)
|
|
556
|
+
except jsonschema.ValidationError as e:
|
|
557
|
+
raise ValueError(e.message) from e
|
|
558
|
+
|
|
559
|
+
GLOBAL_LOGGER.info("Top-level keys and structural constraints validated via JSON Schema")
|
|
555
560
|
|
|
556
561
|
self._validate_elements()
|
|
557
562
|
self._validate_relations()
|
|
@@ -560,53 +565,26 @@ class JustificationSchemaValidator:
|
|
|
560
565
|
|
|
561
566
|
def _validate_elements(self) -> None:
|
|
562
567
|
"""
|
|
563
|
-
|
|
568
|
+
Checks that all element IDs are unique (semantic check not expressible in JSON Schema).
|
|
564
569
|
|
|
565
|
-
|
|
566
|
-
- Be a dictionary with `id`, `label`, and `type` keys.
|
|
567
|
-
- Have a `type` that is among the allowed VALID_TYPES.
|
|
568
|
-
- Use a unique `id` across all elements.
|
|
569
|
-
|
|
570
|
-
:raises ValueError: If any element is invalid or duplicates are found.
|
|
570
|
+
:raises ValueError: If duplicate element IDs are found.
|
|
571
571
|
"""
|
|
572
|
-
|
|
573
|
-
if not isinstance(elements, list):
|
|
574
|
-
raise ValueError("'elements' must be a list")
|
|
575
|
-
|
|
576
|
-
for i, element in enumerate(elements):
|
|
577
|
-
for key in ["id", "label", "type"]:
|
|
578
|
-
if key not in element:
|
|
579
|
-
raise ValueError(f"Element {i} is missing required key '{key}'")
|
|
580
|
-
|
|
581
|
-
if element["type"] not in self.VALID_TYPES:
|
|
582
|
-
raise ValueError(f"Invalid type '{element['type']}' in element '{element['id']}'")
|
|
583
|
-
|
|
572
|
+
for element in self.data.get("elements", []):
|
|
584
573
|
if element["id"] in self.element_ids:
|
|
585
574
|
raise ValueError(f"Duplicate element id: '{element['id']}'")
|
|
586
|
-
|
|
587
575
|
self.element_ids.add(element["id"])
|
|
588
576
|
|
|
589
|
-
GLOBAL_LOGGER.debug("All
|
|
577
|
+
GLOBAL_LOGGER.debug("All element IDs validated for uniqueness: %s", self.element_ids)
|
|
590
578
|
|
|
591
579
|
def _validate_relations(self) -> None:
|
|
592
580
|
"""
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
Each relation must:
|
|
596
|
-
- Be a dictionary with `source` and `target` keys.
|
|
597
|
-
- Reference only valid element IDs defined in the `elements` section.
|
|
581
|
+
Checks that every relation source/target references an existing element ID.
|
|
598
582
|
|
|
599
|
-
:raises ValueError: If
|
|
583
|
+
:raises ValueError: If a relation references an unknown element ID.
|
|
600
584
|
"""
|
|
601
585
|
relations = self.data.get("relations", [])
|
|
602
|
-
if not isinstance(relations, list):
|
|
603
|
-
raise ValueError("'relations' must be a list")
|
|
604
|
-
|
|
605
586
|
for i, rel in enumerate(relations):
|
|
606
587
|
for key in ["source", "target"]:
|
|
607
|
-
if key not in rel:
|
|
608
|
-
raise ValueError(f"Relation {i} is missing required key '{key}'")
|
|
609
|
-
|
|
610
588
|
if rel[key] not in self.element_ids:
|
|
611
589
|
raise ValueError(f"Relation {i} refers to unknown {key} id '{rel[key]}'")
|
|
612
590
|
|
|
@@ -12,7 +12,6 @@ import logging
|
|
|
12
12
|
import os
|
|
13
13
|
import shutil
|
|
14
14
|
import sys
|
|
15
|
-
import textwrap
|
|
16
15
|
from typing import Iterable
|
|
17
16
|
|
|
18
17
|
from jpipe_runner.enums import StatusType
|
|
@@ -173,18 +172,20 @@ def pretty_display(diagrams: Iterable[tuple[str, Iterable[dict]]]) -> tuple[int,
|
|
|
173
172
|
exception = data.get("exception")
|
|
174
173
|
status = data["status"]
|
|
175
174
|
status_bar = f"| {colored_statuses[status]} |"
|
|
176
|
-
|
|
175
|
+
status_bar_visual_len = len(f"| {status.value} |")
|
|
177
176
|
|
|
178
|
-
# Format
|
|
179
|
-
line_prefix = f"{var_type}<{var_name}> :: "
|
|
177
|
+
# Format the main line, truncating with "..." if it exceeds available width
|
|
178
|
+
line_prefix = f"{var_type}<{name}:{var_name}> :: "
|
|
180
179
|
full_line = f"{line_prefix}{label}"
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
180
|
+
max_content = width - status_bar_visual_len - 1
|
|
181
|
+
if len(full_line) > max_content:
|
|
182
|
+
if max_content <= 0:
|
|
183
|
+
full_line = ""
|
|
184
|
+
elif max_content <= 3:
|
|
185
|
+
full_line = "..."[:max_content]
|
|
186
186
|
else:
|
|
187
|
-
|
|
187
|
+
full_line = full_line[: max_content - 3] + "..."
|
|
188
|
+
print(full_line.ljust(width - status_bar_visual_len) + status_bar)
|
|
188
189
|
|
|
189
190
|
if exception:
|
|
190
191
|
GLOBAL_LOGGER.warning(exception)
|
|
@@ -115,6 +115,27 @@ class PythonRuntime:
|
|
|
115
115
|
with group_github_logs():
|
|
116
116
|
return self.__getattr__(name)(*args, **kwargs)
|
|
117
117
|
|
|
118
|
+
def build_link_registry(self) -> dict[str, str]:
|
|
119
|
+
"""
|
|
120
|
+
Scan all loaded modules and return a mapping of element id to attribute name
|
|
121
|
+
for every callable decorated with @jpipe_link.
|
|
122
|
+
|
|
123
|
+
:return: Dict mapping element_id → attr_name in the loaded modules.
|
|
124
|
+
:rtype: dict[str, str]
|
|
125
|
+
"""
|
|
126
|
+
registry = {}
|
|
127
|
+
for module in self._modules:
|
|
128
|
+
for attr_name in dir(module):
|
|
129
|
+
obj = getattr(module, attr_name, None)
|
|
130
|
+
if callable(obj) and (eid := getattr(obj, "__jpipe_link_id__", None)):
|
|
131
|
+
if eid in registry and registry[eid] != attr_name:
|
|
132
|
+
raise RuntimeException(
|
|
133
|
+
f"Duplicate @jpipe_link id '{eid}': bound to both "
|
|
134
|
+
f"'{registry[eid]}' and '{attr_name}'"
|
|
135
|
+
)
|
|
136
|
+
registry[eid] = attr_name
|
|
137
|
+
return registry
|
|
138
|
+
|
|
118
139
|
def set_variable(self, name: str, value: Any) -> None:
|
|
119
140
|
"""
|
|
120
141
|
Set a variable with the given name and value in all modules where it exists.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"title": "Justification Pipeline",
|
|
4
|
+
"type": "object",
|
|
5
|
+
"required": ["name", "type", "elements", "relations"],
|
|
6
|
+
"properties": {
|
|
7
|
+
"name": {"type": "string"},
|
|
8
|
+
"type": {"type": "string", "enum": ["justification"]},
|
|
9
|
+
"elements": {
|
|
10
|
+
"type": "array",
|
|
11
|
+
"items": {
|
|
12
|
+
"type": "object",
|
|
13
|
+
"required": ["id", "label", "type"],
|
|
14
|
+
"properties": {
|
|
15
|
+
"id": {"type": "string"},
|
|
16
|
+
"label": {"type": "string"},
|
|
17
|
+
"type": {"type": "string",
|
|
18
|
+
"enum": ["evidence", "strategy", "conclusion", "sub-conclusion"]},
|
|
19
|
+
"escaped": {"type": "string"}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"relations": {
|
|
24
|
+
"type": "array",
|
|
25
|
+
"items": {
|
|
26
|
+
"type": "object",
|
|
27
|
+
"required": ["source", "target"],
|
|
28
|
+
"properties": {
|
|
29
|
+
"source": {"type": "string"},
|
|
30
|
+
"target": {"type": "string"}
|
|
31
|
+
},
|
|
32
|
+
"additionalProperties": false
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{jpipe_runner-3.2.0 → jpipe_runner-3.4.0}/src/jpipe_runner/framework/decorators/skip_decorator.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|