jpipe-runner 3.1.0__tar.gz → 3.3.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.
Files changed (21) hide show
  1. {jpipe_runner-3.1.0 → jpipe_runner-3.3.0}/PKG-INFO +2 -4
  2. {jpipe_runner-3.1.0 → jpipe_runner-3.3.0}/pyproject.toml +26 -5
  3. {jpipe_runner-3.1.0 → jpipe_runner-3.3.0}/src/jpipe_runner/__main__.py +1 -1
  4. {jpipe_runner-3.1.0 → jpipe_runner-3.3.0}/src/jpipe_runner/enums.py +3 -0
  5. {jpipe_runner-3.1.0 → jpipe_runner-3.3.0}/src/jpipe_runner/framework/context.py +38 -25
  6. {jpipe_runner-3.1.0 → jpipe_runner-3.3.0}/src/jpipe_runner/framework/decorators/contribution_decorator.py +5 -2
  7. {jpipe_runner-3.1.0 → jpipe_runner-3.3.0}/src/jpipe_runner/framework/decorators/jpipe_decorator.py +33 -17
  8. {jpipe_runner-3.1.0 → jpipe_runner-3.3.0}/src/jpipe_runner/framework/decorators/skip_decorator.py +4 -0
  9. {jpipe_runner-3.1.0 → jpipe_runner-3.3.0}/src/jpipe_runner/framework/engine.py +185 -279
  10. {jpipe_runner-3.1.0 → jpipe_runner-3.3.0}/src/jpipe_runner/framework/logger.py +7 -2
  11. {jpipe_runner-3.1.0 → jpipe_runner-3.3.0}/src/jpipe_runner/framework/validators.py +65 -126
  12. {jpipe_runner-3.1.0 → jpipe_runner-3.3.0}/src/jpipe_runner/runner.py +93 -135
  13. {jpipe_runner-3.1.0 → jpipe_runner-3.3.0}/src/jpipe_runner/runtime.py +8 -10
  14. {jpipe_runner-3.1.0 → jpipe_runner-3.3.0}/src/jpipe_runner/utils.py +11 -14
  15. jpipe_runner-3.1.0/src/jpipe_runner/GraphWorkflowVisualizer.py +0 -284
  16. {jpipe_runner-3.1.0 → jpipe_runner-3.3.0}/LICENSE +0 -0
  17. {jpipe_runner-3.1.0 → jpipe_runner-3.3.0}/README.md +0 -0
  18. {jpipe_runner-3.1.0 → jpipe_runner-3.3.0}/src/jpipe_runner/__init__.py +0 -0
  19. {jpipe_runner-3.1.0 → jpipe_runner-3.3.0}/src/jpipe_runner/exceptions.py +0 -0
  20. {jpipe_runner-3.1.0 → jpipe_runner-3.3.0}/src/jpipe_runner/framework/__init__.py +0 -0
  21. {jpipe_runner-3.1.0 → jpipe_runner-3.3.0}/src/jpipe_runner/framework/decorators/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jpipe-runner
3
- Version: 3.1.0
3
+ Version: 3.3.0
4
4
  Summary: A Justification Runner designed for jPipe.
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -17,10 +17,8 @@ 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
- Provides-Extra: gui
21
- Requires-Dist: matplotlib (==3.10.5) ; extra == "gui" or extra == "full"
20
+ Requires-Dist: graphviz (>=0.20)
22
21
  Requires-Dist: networkx (==3.5)
23
- Requires-Dist: pygraphviz (==1.14)
24
22
  Requires-Dist: pyyaml (==6.0.2)
25
23
  Requires-Dist: sphinx (==8.1.3) ; extra == "docs" or extra == "full"
26
24
  Project-URL: Homepage, https://github.com/jpipe-mcscert/jpipe-runner
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "jpipe-runner"
3
- version = "3.1.0"
3
+ version = "3.3.0"
4
4
  description = "A Justification Runner designed for jPipe."
5
5
  authors = [
6
6
  "Jason Lyu <xjasonlyu@gmail.com>",
@@ -22,16 +22,14 @@ packages = [
22
22
  [tool.poetry.dependencies]
23
23
  python = ">=3.11"
24
24
  networkx = "3.5"
25
- pygraphviz = "1.14"
25
+ graphviz = ">=0.20"
26
26
  pyyaml = "6.0.2"
27
27
 
28
- matplotlib = { version = "3.10.5", optional = true }
29
28
  sphinx = { version = "8.1.3", optional = true }
30
29
 
31
30
  [tool.poetry.extras]
32
- gui = ["matplotlib"]
33
31
  docs = ["sphinx"]
34
- full = ["matplotlib", "sphinx"]
32
+ full = ["sphinx"]
35
33
 
36
34
  [tool.poetry.scripts]
37
35
  jpipe-runner = "jpipe_runner.runner:main"
@@ -39,6 +37,29 @@ jpipe-runner = "jpipe_runner.runner:main"
39
37
  [tool.poetry.group.dev.dependencies]
40
38
  pytest = "^8.4.1"
41
39
  pytest-mock = "^3.14.1"
40
+ pytest-cov = "^6.1"
41
+ ruff = "^0.11"
42
+
43
+ [tool.ruff]
44
+ target-version = "py311"
45
+ line-length = 100
46
+
47
+ [tool.ruff.lint]
48
+ select = ["E", "F", "W", "I"]
49
+ ignore = [
50
+ "E501", # line length enforced by ruff format, not lint
51
+ "F821", # forward-reference string annotations (e.g. "PipelineEngine")
52
+ ]
53
+
54
+ [tool.ruff.lint.per-file-ignores]
55
+ "src/jpipe_runner/runner.py" = ["W291", "W293"] # intentional trailing spaces in ASCII art
56
+
57
+ [tool.coverage.run]
58
+ source = ["src/jpipe_runner"]
59
+
60
+ [tool.coverage.report]
61
+ show_missing = true
62
+ fail_under = 60
42
63
 
43
64
  [tool.poetry.requires-plugins]
44
65
  poetry-plugin-export = ">=1.8"
@@ -1,4 +1,4 @@
1
1
  from jpipe_runner import runner
2
2
 
3
- if __name__ == '__main__':
3
+ if __name__ == "__main__":
4
4
  runner.main()
@@ -10,6 +10,7 @@ from enum import Enum
10
10
 
11
11
  class ClassType(Enum):
12
12
  """justification / pattern / composition"""
13
+
13
14
  JUSTIFICATION = "justification"
14
15
  PATTERN = "pattern"
15
16
  COMPOSITION = "composition"
@@ -17,6 +18,7 @@ class ClassType(Enum):
17
18
 
18
19
  class VariableType(Enum):
19
20
  """evidence / strategy / sub-conclusion / conclusion / @support"""
21
+
20
22
  EVIDENCE = "evidence"
21
23
  STRATEGY = "strategy"
22
24
  SUB_CONCLUSION = "sub-conclusion"
@@ -26,6 +28,7 @@ class VariableType(Enum):
26
28
 
27
29
  class StatusType(Enum):
28
30
  """PASS / FAIL / SKIP"""
31
+
29
32
  PASS = "PASS"
30
33
  FAIL = "FAIL"
31
34
  SKIP = "SKIP"
@@ -29,13 +29,21 @@ class RuntimeContext:
29
29
  },
30
30
  ...
31
31
  }
32
+
33
+ Thread safety:
34
+ This class and the module-level ``ctx`` singleton are **not thread-safe**.
35
+ All pipeline functions must run in a single thread. Concurrent access to
36
+ ``_vars`` (e.g. from threading or async execution) may produce race conditions
37
+ or data corruption. If parallel execution is needed in future, replace the
38
+ global singleton with a per-execution context passed explicitly.
32
39
  """
33
- PRODUCE = '_produce'
34
- CONSUME = '_consume'
35
- SKIP = '_skip'
36
- CONTRIBUTION = '_contribution'
37
- POSITIVE = '_positive'
38
- NEGATIVE = '_negative'
40
+
41
+ PRODUCE = "_produce"
42
+ CONSUME = "_consume"
43
+ SKIP = "_skip"
44
+ CONTRIBUTION = "_contribution"
45
+ POSITIVE = "_positive"
46
+ NEGATIVE = "_negative"
39
47
 
40
48
  def __init__(self):
41
49
  """
@@ -61,7 +69,9 @@ class RuntimeContext:
61
69
  for decorator in (self.PRODUCE, self.CONSUME):
62
70
  if key in self._vars[func].get(decorator, {}):
63
71
  value = self._vars[func][decorator][key]
64
- GLOBAL_LOGGER.debug(f"Retrieved variable '{key}' with value '{value}' from function '{func}'")
72
+ GLOBAL_LOGGER.debug(
73
+ f"Retrieved variable '{key}' with value '{value}' from function '{func}'"
74
+ )
65
75
  return value
66
76
  return None
67
77
 
@@ -91,8 +101,12 @@ class RuntimeContext:
91
101
  if decorator not in self._vars[func]:
92
102
  self._vars[func][decorator] = {}
93
103
  self._vars[func][decorator][key] = value
94
- GLOBAL_LOGGER.info(f"Set variable '{key}' to '{value}' in function '{func}' under decorator '{decorator}'")
95
- GLOBAL_LOGGER.debug(f"Set variable '{key}' to '{value}' in function '{func}' under decorator '{decorator}'")
104
+ GLOBAL_LOGGER.info(
105
+ f"Set variable '{key}' to '{value}' in function '{func}' under decorator '{decorator}'"
106
+ )
107
+ GLOBAL_LOGGER.debug(
108
+ f"Set variable '{key}' to '{value}' in function '{func}' under decorator '{decorator}'"
109
+ )
96
110
  GLOBAL_LOGGER.debug(f"Updated context: {self._vars[func]}")
97
111
 
98
112
  def set(self, key, value):
@@ -131,7 +145,9 @@ class RuntimeContext:
131
145
  """
132
146
  if func not in self._vars:
133
147
  return False
134
- return key in self._vars[func].get(self.PRODUCE, {}) or key in self._vars[func].get(self.CONSUME, {})
148
+ return key in self._vars[func].get(self.PRODUCE, {}) or key in self._vars[func].get(
149
+ self.CONSUME, {}
150
+ )
135
151
 
136
152
  def set_from_config(self, key, value, decorator=CONSUME):
137
153
  """
@@ -173,11 +189,10 @@ class RuntimeContext:
173
189
  """
174
190
  if func not in self._vars:
175
191
  self._vars[func] = {}
176
- self._vars[func][self.SKIP] = {
177
- 'value': value,
178
- 'reason': reason
179
- }
180
- GLOBAL_LOGGER.debug(f"Set skip status for function '{func}' to {value} with reason: {reason}")
192
+ self._vars[func][self.SKIP] = {"value": value, "reason": reason}
193
+ GLOBAL_LOGGER.debug(
194
+ f"Set skip status for function '{func}' to {value} with reason: {reason}"
195
+ )
181
196
 
182
197
  def set_contribution(self, func, contribution_type: str, variables: list[str]):
183
198
  """
@@ -197,12 +212,11 @@ class RuntimeContext:
197
212
  if func not in self._vars:
198
213
  self._vars[func] = {}
199
214
  if self.CONTRIBUTION not in self._vars[func]:
200
- self._vars[func][self.CONTRIBUTION] = {
201
- self.POSITIVE: [],
202
- self.NEGATIVE: []
203
- }
215
+ self._vars[func][self.CONTRIBUTION] = {self.POSITIVE: [], self.NEGATIVE: []}
204
216
  self._vars[func][self.CONTRIBUTION][contribution_type].extend(variables)
205
- GLOBAL_LOGGER.debug(f"Set {contribution_type} contribution for function '{func}' with variables: {variables}")
217
+ GLOBAL_LOGGER.debug(
218
+ f"Set {contribution_type} contribution for function '{func}' with variables: {variables}"
219
+ )
206
220
 
207
221
  def get_contributions(self, func: str) -> Dict[str, List[str]]:
208
222
  """
@@ -214,10 +228,9 @@ class RuntimeContext:
214
228
  Returns:
215
229
  dict: {'_positive': [...], '_negative': [...]} — lists may be empty.
216
230
  """
217
- return self._vars.get(func, {}).get(RuntimeContext.CONTRIBUTION, {
218
- self.POSITIVE: [],
219
- self.NEGATIVE: []
220
- })
231
+ return self._vars.get(func, {}).get(
232
+ RuntimeContext.CONTRIBUTION, {self.POSITIVE: [], self.NEGATIVE: []}
233
+ )
221
234
 
222
235
  def __repr__(self):
223
236
  """
@@ -229,4 +242,4 @@ class RuntimeContext:
229
242
  return f"RuntimeContext(vars={self._vars})"
230
243
 
231
244
 
232
- ctx = RuntimeContext()
245
+ ctx = RuntimeContext() # module-level singleton — not thread-safe (see class docstring)
@@ -1,7 +1,7 @@
1
1
  from functools import wraps
2
- from typing import Optional, List
2
+ from typing import List, Optional
3
3
 
4
- from jpipe_runner.framework.context import ctx, RuntimeContext
4
+ from jpipe_runner.framework.context import RuntimeContext, ctx
5
5
 
6
6
 
7
7
  def contribution(positive: Optional[List[str]] = None, negative: Optional[List[str]] = None):
@@ -18,8 +18,11 @@ def contribution(positive: Optional[List[str]] = None, negative: Optional[List[s
18
18
  def decorator(func):
19
19
  ctx.set_contribution(func.__name__, RuntimeContext.NEGATIVE, negative)
20
20
  ctx.set_contribution(func.__name__, RuntimeContext.POSITIVE, positive)
21
+
21
22
  @wraps(func)
22
23
  def wrapper(*args, **kwargs):
23
24
  return func(*args, **kwargs)
25
+
24
26
  return wrapper
27
+
25
28
  return decorator
@@ -2,9 +2,9 @@ import ast
2
2
  import inspect
3
3
  import textwrap
4
4
  from functools import wraps
5
- from typing import Callable, List, Optional, Any
5
+ from typing import Any, Callable, List, Optional
6
6
 
7
- from jpipe_runner.framework.context import ctx, RuntimeContext
7
+ from jpipe_runner.framework.context import RuntimeContext, ctx
8
8
  from jpipe_runner.framework.logger import GLOBAL_LOGGER
9
9
 
10
10
 
@@ -24,11 +24,11 @@ def jpipe(consume: Optional[List[str]] = None, produce: Optional[List[str]] = No
24
24
  produce_checker = _init_checker(ProducedVariableChecker, func, produce)
25
25
 
26
26
  @wraps(func)
27
- def wrapper(*args, **kwargs):
27
+ def wrapper(*args: Any, **kwargs: Any) -> Any:
28
28
  if consume_checker:
29
29
  kwargs = consume_checker.inject_arguments(kwargs)
30
30
  if produce_checker:
31
- kwargs['produce'] = produce_checker.produce
31
+ kwargs["produce"] = produce_checker.produce
32
32
 
33
33
  result = func(*args, **kwargs)
34
34
 
@@ -41,13 +41,17 @@ def jpipe(consume: Optional[List[str]] = None, produce: Optional[List[str]] = No
41
41
 
42
42
  return decorator
43
43
 
44
- def _init_checker(CheckerClass, func: Callable, params: List[str]):
44
+
45
+ def _init_checker(
46
+ CheckerClass: type, func: Callable, params: List[str]
47
+ ) -> "ConsumedVariableChecker | ProducedVariableChecker | None":
45
48
  if not params:
46
49
  return None
47
50
  checker = CheckerClass(func, params)
48
51
  checker.register_variables()
49
52
  return checker
50
53
 
54
+
51
55
  class ConsumedVariableChecker:
52
56
  """
53
57
  Validates and manages variables declared as consumed by a function.
@@ -71,14 +75,18 @@ class ConsumedVariableChecker:
71
75
  self.func = func
72
76
  self.func_name = func.__name__
73
77
  self.declared_params = declared_params
74
- GLOBAL_LOGGER.debug(f"[{self.func_name}] Initializing ConsumedVariableChecker with: {self.declared_params}")
78
+ GLOBAL_LOGGER.debug(
79
+ f"[{self.func_name}] Initializing ConsumedVariableChecker with: {self.declared_params}"
80
+ )
75
81
  self.used_params = self._get_used_variables()
76
82
 
77
83
  def register_variables(self):
78
84
  """
79
85
  Registers declared variables as consumed in the global context (`ctx`).
80
86
  """
81
- GLOBAL_LOGGER.info(f"[{self.func_name}] Registering consumed variables: {self.declared_params}")
87
+ GLOBAL_LOGGER.info(
88
+ f"[{self.func_name}] Registering consumed variables: {self.declared_params}"
89
+ )
82
90
  for param in self.declared_params:
83
91
  if not ctx.has(self.func, param):
84
92
  ctx._set(self.func_name, param, None, RuntimeContext.CONSUME)
@@ -98,7 +106,9 @@ class ConsumedVariableChecker:
98
106
  f"Consumed variable '{param}' is declared but not used in function '{self.func_name}'."
99
107
  )
100
108
  value = ctx.get(param)
101
- GLOBAL_LOGGER.debug(f"[{self.func_name}] Injecting consumed variable '{param}' = {value}")
109
+ GLOBAL_LOGGER.debug(
110
+ f"[{self.func_name}] Injecting consumed variable '{param}' = {value}"
111
+ )
102
112
  if value is None:
103
113
  GLOBAL_LOGGER.error(
104
114
  f"Consumed variable '{param}' has not been set in context before calling '{self.func_name}'."
@@ -106,7 +116,7 @@ class ConsumedVariableChecker:
106
116
  kwargs[param] = value
107
117
  return kwargs
108
118
 
109
- def _get_used_variables(self) -> set:
119
+ def _get_used_variables(self) -> set[str]:
110
120
  """
111
121
  Extracts all variable names used inside the body of the given function using AST parsing.
112
122
 
@@ -121,10 +131,10 @@ class ConsumedVariableChecker:
121
131
  tree = ast.parse(source)
122
132
 
123
133
  class VarVisitor(ast.NodeVisitor):
124
- def __init__(self):
125
- self.used_vars = set()
134
+ def __init__(self) -> None:
135
+ self.used_vars: set[str] = set()
126
136
 
127
- def visit_Name(self, node):
137
+ def visit_Name(self, node: ast.Name) -> None:
128
138
  self.used_vars.add(node.id)
129
139
 
130
140
  visitor = VarVisitor()
@@ -157,19 +167,23 @@ class ProducedVariableChecker:
157
167
  self.func_name = func.__name__
158
168
  self.declared_params = set(declared_params)
159
169
  self.produced_set = set()
160
- GLOBAL_LOGGER.debug(f"[{self.func_name}] Initializing ProducedVariableChecker with: {self.declared_params}")
170
+ GLOBAL_LOGGER.debug(
171
+ f"[{self.func_name}] Initializing ProducedVariableChecker with: {self.declared_params}"
172
+ )
161
173
 
162
174
  def register_variables(self):
163
175
  """
164
176
  Registers declared variables as produced in the global context (`ctx`).
165
177
  """
166
- GLOBAL_LOGGER.info(f"[{self.func_name}] Registering produced variables: {self.declared_params}")
178
+ GLOBAL_LOGGER.info(
179
+ f"[{self.func_name}] Registering produced variables: {self.declared_params}"
180
+ )
167
181
  for param in self.declared_params:
168
182
  if not ctx.has(self.func, param):
169
183
  ctx._set(self.func_name, param, None, RuntimeContext.PRODUCE)
170
184
  GLOBAL_LOGGER.debug(f"[{self.func_name}] Variable '{param}' registered as PRODUCE")
171
185
 
172
- def produce(self, param: str, value: Any):
186
+ def produce(self, param: str, value: Any) -> None:
173
187
  """
174
188
  Produces a variable by setting it in the context.
175
189
 
@@ -186,7 +200,7 @@ class ProducedVariableChecker:
186
200
  ctx.set(param, value)
187
201
  GLOBAL_LOGGER.info(f"[{self.func_name}] Produced variable '{param}' with value: {value}")
188
202
 
189
- def validate_produced(self):
203
+ def validate_produced(self) -> None:
190
204
  """
191
205
  Ensures all declared variables were actually produced during execution.
192
206
 
@@ -197,4 +211,6 @@ class ProducedVariableChecker:
197
211
  GLOBAL_LOGGER.error(
198
212
  f"Function '{self.func_name}' did not produce the following declared variable(s): {missing}"
199
213
  )
200
- GLOBAL_LOGGER.debug(f"[{self.func_name}] All declared produced variables were set: {self.produced_set}")
214
+ GLOBAL_LOGGER.debug(
215
+ f"[{self.func_name}] All declared produced variables were set: {self.produced_set}"
216
+ )
@@ -14,10 +14,14 @@ def skip(condition: bool = True, reason: str = "Skipped by condition") -> callab
14
14
  Returns:
15
15
  callable: A function decorator that skips the wrapped function if the condition is True.
16
16
  """
17
+
17
18
  def decorator(func):
18
19
  ctx.set_skip(func.__name__, condition, reason)
20
+
19
21
  @wraps(func)
20
22
  def wrapper(*args, **kwargs):
21
23
  return func(*args, **kwargs)
24
+
22
25
  return wrapper
26
+
23
27
  return decorator