codecraftai-taskplus 1.4.0__tar.gz → 1.4.1__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.
- {codecraftai_taskplus-1.4.0 → codecraftai_taskplus-1.4.1}/PKG-INFO +1 -1
- {codecraftai_taskplus-1.4.0 → codecraftai_taskplus-1.4.1}/pyproject.toml +1 -1
- {codecraftai_taskplus-1.4.0 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/model/flowengine.py +49 -8
- {codecraftai_taskplus-1.4.0 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/model/workflow.py +100 -1
- {codecraftai_taskplus-1.4.0 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/tasks/embeddedpython.py +17 -0
- {codecraftai_taskplus-1.4.0 → codecraftai_taskplus-1.4.1}/LICENSE.md +0 -0
- {codecraftai_taskplus-1.4.0 → codecraftai_taskplus-1.4.1}/README.md +0 -0
- {codecraftai_taskplus-1.4.0 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/__init__.py +0 -0
- {codecraftai_taskplus-1.4.0 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/cli/__init__.py +0 -0
- {codecraftai_taskplus-1.4.0 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/cli/cmdtree/__init__.py +0 -0
- {codecraftai_taskplus-1.4.0 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/cli/cmdtree/workflow.py +0 -0
- {codecraftai_taskplus-1.4.0 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/cli/taskpluscommand.py +0 -0
- {codecraftai_taskplus-1.4.0 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/entrypoints.py +0 -0
- {codecraftai_taskplus-1.4.0 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/execution.py +0 -0
- {codecraftai_taskplus-1.4.0 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/initialize.py +0 -0
- {codecraftai_taskplus-1.4.0 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/model/__init__.py +0 -0
- {codecraftai_taskplus-1.4.0 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/model/flownode.py +0 -0
- {codecraftai_taskplus-1.4.0 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/model/task.py +0 -0
- {codecraftai_taskplus-1.4.0 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/model/taskgroup.py +0 -0
- {codecraftai_taskplus-1.4.0 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/py.typed +0 -0
- {codecraftai_taskplus-1.4.0 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/tasks/__init__.py +0 -0
- {codecraftai_taskplus-1.4.0 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/tasks/createenvironment.py +0 -0
- {codecraftai_taskplus-1.4.0 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/tasks/gitcheckout.py +0 -0
- {codecraftai_taskplus-1.4.0 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/tasks/outputtext.py +0 -0
- {codecraftai_taskplus-1.4.0 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/tasks/runcommand.py +0 -0
- {codecraftai_taskplus-1.4.0 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/tasks/shellscript.py +0 -0
|
@@ -13,12 +13,16 @@ from ccai.errors.exceptions import ConfigurationError
|
|
|
13
13
|
from ccai.taskplus.model.flownode import FlowNode
|
|
14
14
|
from ccai.taskplus.model.task import Task
|
|
15
15
|
from ccai.taskplus.model.taskgroup import TaskGroup
|
|
16
|
-
from ccai.taskplus.model.workflow import Workflow
|
|
16
|
+
from ccai.taskplus.model.workflow import Workflow, collect_node_names, full_node_name, resolve_jump_target
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
class JumpContext:
|
|
20
20
|
def __init__(self):
|
|
21
|
+
# The full dotted name of the node an 'onfailure'/'onsuccess' jump is seeking, the
|
|
22
|
+
# task that jumped, and the full dotted names of every node in the flow.
|
|
21
23
|
self.seeking_node = None
|
|
24
|
+
self.seeking_from = None
|
|
25
|
+
self.node_names = []
|
|
22
26
|
return
|
|
23
27
|
|
|
24
28
|
|
|
@@ -62,6 +66,7 @@ class FlowEngine:
|
|
|
62
66
|
flowstate = {}
|
|
63
67
|
errors = []
|
|
64
68
|
jump_context = JumpContext()
|
|
69
|
+
jump_context.node_names = collect_node_names(flowitems)
|
|
65
70
|
|
|
66
71
|
# Publish the workflow 'environment' section so it takes effect in this process and in every
|
|
67
72
|
# sub-process the tasks launch, then restore the previous values once the flow has run.
|
|
@@ -79,6 +84,15 @@ class FlowEngine:
|
|
|
79
84
|
else:
|
|
80
85
|
os.environ[env_name] = prev_value
|
|
81
86
|
|
|
87
|
+
if jump_context.seeking_node is not None:
|
|
88
|
+
# The jump target was never reached (unknown, or not after the task that jumped), so the
|
|
89
|
+
# rest of the flow was skipped; that must not be reported as success.
|
|
90
|
+
failure_info = {
|
|
91
|
+
"node": jump_context.seeking_from,
|
|
92
|
+
"unreached_target": jump_context.seeking_node,
|
|
93
|
+
}
|
|
94
|
+
errors.append(failure_info)
|
|
95
|
+
|
|
82
96
|
if len(errors) > 0:
|
|
83
97
|
result_code = 1
|
|
84
98
|
|
|
@@ -86,18 +100,25 @@ class FlowEngine:
|
|
|
86
100
|
|
|
87
101
|
|
|
88
102
|
def process_flowitems(self, environment: Dict[str, str], parameters: Dict[str, Any], flowstate: Dict[str, Any], errors: List,
|
|
89
|
-
flowitems: List[FlowNode], jump_context: JumpContext):
|
|
103
|
+
flowitems: List[FlowNode], jump_context: JumpContext, name_prefix: str = ""):
|
|
90
104
|
|
|
91
105
|
for fitem in flowitems:
|
|
92
106
|
|
|
93
107
|
node_label = fitem.label
|
|
108
|
+
node_name = full_node_name(name_prefix, node_label)
|
|
94
109
|
|
|
95
|
-
# If we are seeking a specific node, skip any nodes that are not that node
|
|
110
|
+
# If we are seeking a specific node, skip any nodes that are not that node; descend into a
|
|
111
|
+
# task group that holds the node being sought (the group's 'if' does not apply to the jump).
|
|
96
112
|
if jump_context.seeking_node is not None:
|
|
97
|
-
if jump_context.seeking_node
|
|
113
|
+
if jump_context.seeking_node == node_name:
|
|
114
|
+
jump_context.seeking_node = None
|
|
115
|
+
jump_context.seeking_from = None
|
|
116
|
+
elif isinstance(fitem, TaskGroup) and jump_context.seeking_node.startswith(node_name + "."):
|
|
117
|
+
self.process_flowitems(environment, parameters, flowstate, errors, fitem.items,
|
|
118
|
+
jump_context, name_prefix=node_name)
|
|
98
119
|
continue
|
|
99
120
|
else:
|
|
100
|
-
|
|
121
|
+
continue
|
|
101
122
|
|
|
102
123
|
include_node = True
|
|
103
124
|
if fitem.if_expr is not None:
|
|
@@ -111,7 +132,7 @@ class FlowEngine:
|
|
|
111
132
|
if fitem.onfailure is not None:
|
|
112
133
|
# The failure is routed to a handler node -- treat it
|
|
113
134
|
# as handled and let the handler decide the outcome.
|
|
114
|
-
jump_context
|
|
135
|
+
self._begin_jump(jump_context, node_name, fitem.onfailure)
|
|
115
136
|
else:
|
|
116
137
|
# An unhandled task failure must surface so that
|
|
117
138
|
# execute() returns a non-zero code (CI gating).
|
|
@@ -121,14 +142,34 @@ class FlowEngine:
|
|
|
121
142
|
}
|
|
122
143
|
errors.append(failure_info)
|
|
123
144
|
elif fitem.onsuccess is not None:
|
|
124
|
-
jump_context
|
|
145
|
+
self._begin_jump(jump_context, node_name, fitem.onsuccess)
|
|
125
146
|
|
|
126
147
|
elif isinstance(fitem, TaskGroup):
|
|
127
148
|
|
|
128
149
|
group_items = fitem.items
|
|
129
150
|
|
|
130
151
|
self.process_flowitems(environment, parameters, flowstate, errors, group_items,
|
|
131
|
-
jump_context)
|
|
152
|
+
jump_context, name_prefix=node_name)
|
|
153
|
+
|
|
154
|
+
return
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def _begin_jump(self, jump_context: JumpContext, source_name: str, target: str):
|
|
158
|
+
"""
|
|
159
|
+
Starts seeking the node an ``onfailure`` / ``onsuccess`` target names. A task
|
|
160
|
+
inside a task group is targeted by its full dotted name (``group.task``); a
|
|
161
|
+
sibling inside the same group can also be named by its label. A target that
|
|
162
|
+
names no node is sought as given, so it stays pending and fails the run.
|
|
163
|
+
|
|
164
|
+
:param jump_context: The jump state of the run.
|
|
165
|
+
:param source_name: The full dotted name of the task that jumps.
|
|
166
|
+
:param target: The ``onfailure`` / ``onsuccess`` value of the task.
|
|
167
|
+
"""
|
|
168
|
+
resolved_name = resolve_jump_target(jump_context.node_names, source_name, target)
|
|
169
|
+
if resolved_name is None:
|
|
170
|
+
resolved_name = target
|
|
132
171
|
|
|
172
|
+
jump_context.seeking_node = resolved_name
|
|
173
|
+
jump_context.seeking_from = source_name
|
|
133
174
|
return
|
|
134
175
|
|
|
@@ -4,7 +4,7 @@ __author__ = "Myron Walker"
|
|
|
4
4
|
__copyright__ = "Copyright 2025, Code Craft AI LLC"
|
|
5
5
|
__credits__ = []
|
|
6
6
|
|
|
7
|
-
from typing import Any, Dict, List
|
|
7
|
+
from typing import Any, Dict, List, Optional
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
import logging
|
|
@@ -29,6 +29,76 @@ from ccai.taskplus.model.taskgroup import TaskGroup
|
|
|
29
29
|
logger = logging.getLogger()
|
|
30
30
|
|
|
31
31
|
|
|
32
|
+
def full_node_name(name_prefix: str, label: str) -> str:
|
|
33
|
+
"""
|
|
34
|
+
Builds the full dotted name of a flow node: the labels of its enclosing task
|
|
35
|
+
groups and its own label joined with ``.`` (a top-level node's full name is
|
|
36
|
+
its label).
|
|
37
|
+
|
|
38
|
+
:param name_prefix: The full dotted name of the enclosing task group, or ``""``
|
|
39
|
+
for a top-level node.
|
|
40
|
+
:param label: The label of the node.
|
|
41
|
+
|
|
42
|
+
:returns: The full dotted name of the node.
|
|
43
|
+
"""
|
|
44
|
+
rtnval = label
|
|
45
|
+
if len(name_prefix) > 0:
|
|
46
|
+
rtnval = f"{name_prefix}.{label}"
|
|
47
|
+
return rtnval
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def collect_node_names(flow_items: List[FlowNode], name_prefix: str = "") -> List[str]:
|
|
51
|
+
"""
|
|
52
|
+
Collects the full dotted names of every node in a flow, including the nodes
|
|
53
|
+
inside task groups.
|
|
54
|
+
|
|
55
|
+
:param flow_items: The flow nodes to walk.
|
|
56
|
+
:param name_prefix: The full dotted name of the task group that holds ``flow_items``.
|
|
57
|
+
|
|
58
|
+
:returns: The full dotted names in flow order.
|
|
59
|
+
"""
|
|
60
|
+
rtnval = []
|
|
61
|
+
|
|
62
|
+
for fitem in flow_items:
|
|
63
|
+
node_name = full_node_name(name_prefix, fitem.label)
|
|
64
|
+
rtnval.append(node_name)
|
|
65
|
+
|
|
66
|
+
if isinstance(fitem, TaskGroup):
|
|
67
|
+
rtnval.extend(collect_node_names(fitem.items, name_prefix=node_name))
|
|
68
|
+
|
|
69
|
+
return rtnval
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def resolve_jump_target(node_names: List[str], source_name: str, target: str) -> Optional[str]:
|
|
73
|
+
"""
|
|
74
|
+
Resolves an ``onfailure`` / ``onsuccess`` target to the full dotted name of a
|
|
75
|
+
flow node. The target is looked up relative to the task groups that enclose
|
|
76
|
+
the source task, innermost first, ending with the top level; so a top-level
|
|
77
|
+
node or a task inside a group is found by its full dotted name
|
|
78
|
+
(``group.task``) from anywhere, and a sibling inside the same group is also
|
|
79
|
+
found by its own label.
|
|
80
|
+
|
|
81
|
+
:param node_names: The full dotted names of every node in the flow.
|
|
82
|
+
:param source_name: The full dotted name of the task that jumps.
|
|
83
|
+
:param target: The ``onfailure`` / ``onsuccess`` value of the task.
|
|
84
|
+
|
|
85
|
+
:returns: The full dotted name of the target node, or ``None`` if no node matches.
|
|
86
|
+
"""
|
|
87
|
+
rtnval = None
|
|
88
|
+
|
|
89
|
+
scope_parts = source_name.split(".")[:-1]
|
|
90
|
+
while True:
|
|
91
|
+
candidate = full_node_name(".".join(scope_parts), target)
|
|
92
|
+
if candidate in node_names:
|
|
93
|
+
rtnval = candidate
|
|
94
|
+
break
|
|
95
|
+
if len(scope_parts) == 0:
|
|
96
|
+
break
|
|
97
|
+
scope_parts.pop()
|
|
98
|
+
|
|
99
|
+
return rtnval
|
|
100
|
+
|
|
101
|
+
|
|
32
102
|
class Workflow:
|
|
33
103
|
|
|
34
104
|
def __init__(self, environment: Dict[str, str], parameters: Dict[str, Any], flow: List[FlowNode]):
|
|
@@ -74,10 +144,39 @@ class Workflow:
|
|
|
74
144
|
|
|
75
145
|
flow_items = cls._process_flow_info_items(fnode_info_items)
|
|
76
146
|
|
|
147
|
+
cls._validate_jump_targets(flow_items, collect_node_names(flow_items))
|
|
148
|
+
|
|
77
149
|
workflow = Workflow(environment, parameters, flow_items)
|
|
78
150
|
|
|
79
151
|
return workflow
|
|
80
152
|
|
|
153
|
+
@classmethod
|
|
154
|
+
def _validate_jump_targets(cls, flow_items: List[FlowNode], node_names: List[str], name_prefix: str = ""):
|
|
155
|
+
"""
|
|
156
|
+
Checks that every ``onfailure`` / ``onsuccess`` target names a node of the flow.
|
|
157
|
+
|
|
158
|
+
:param flow_items: The flow nodes to check.
|
|
159
|
+
:param node_names: The full dotted names of every node in the flow.
|
|
160
|
+
:param name_prefix: The full dotted name of the task group that holds ``flow_items``.
|
|
161
|
+
|
|
162
|
+
:raises ConfigurationError: If a target does not resolve to a node of the flow.
|
|
163
|
+
"""
|
|
164
|
+
for fitem in flow_items:
|
|
165
|
+
node_name = full_node_name(name_prefix, fitem.label)
|
|
166
|
+
|
|
167
|
+
if isinstance(fitem, Task):
|
|
168
|
+
for jump_field, target in (("onfailure", fitem.onfailure), ("onsuccess", fitem.onsuccess)):
|
|
169
|
+
if target is not None and resolve_jump_target(node_names, node_name, target) is None:
|
|
170
|
+
errmsg = ("The {} target {!r} of task {!r} does not name a node of the flow; a task "
|
|
171
|
+
"inside a task group is named by its full dotted name (group.task).").format(
|
|
172
|
+
jump_field, target, node_name)
|
|
173
|
+
raise ConfigurationError(errmsg)
|
|
174
|
+
|
|
175
|
+
elif isinstance(fitem, TaskGroup):
|
|
176
|
+
cls._validate_jump_targets(fitem.items, node_names, name_prefix=node_name)
|
|
177
|
+
|
|
178
|
+
return
|
|
179
|
+
|
|
81
180
|
@classmethod
|
|
82
181
|
def _process_flow_info_items(cls, fnode_info_items: List[Dict[str, Any]], ordinal_prefix: str="") -> List[FlowNode]:
|
|
83
182
|
|
|
@@ -52,6 +52,23 @@ class EmbeddedPython(Task):
|
|
|
52
52
|
try:
|
|
53
53
|
script_code = compile(script_content, "<embedded-python %s>" % self._label, "exec")
|
|
54
54
|
exec(script_code, script_namespace)
|
|
55
|
+
except SystemExit as sexit:
|
|
56
|
+
# A workflow step is the application boundary for its script: 'sys.exit()' ends the
|
|
57
|
+
# script, never the process hosting the workflow. No code or 0 is success, a non-zero
|
|
58
|
+
# code is the task's exit status and a message is a failure (exit status 1) that is
|
|
59
|
+
# recorded in the task log, as the interpreter would print it. ConfigurationError and
|
|
60
|
+
# SemanticError are not SystemExit and keep propagating.
|
|
61
|
+
exit_code = sexit.code
|
|
62
|
+
if exit_code is None or exit_code == 0:
|
|
63
|
+
exit_status = 0
|
|
64
|
+
elif isinstance(exit_code, int):
|
|
65
|
+
exit_status = int(exit_code)
|
|
66
|
+
self._logger.error("The embedded python script of task %r (%s) exited with status %d." % (
|
|
67
|
+
self._label, self._ordinal, exit_code))
|
|
68
|
+
else:
|
|
69
|
+
exit_status = 1
|
|
70
|
+
self._logger.error("The embedded python script of task %r (%s) exited with: %s" % (
|
|
71
|
+
self._label, self._ordinal, exit_code))
|
|
55
72
|
except Exception:
|
|
56
73
|
# The task reports a failing script through its exit status; log the traceback so
|
|
57
74
|
# the cause of the failure is visible in the task log.
|
|
File without changes
|
|
File without changes
|
{codecraftai_taskplus-1.4.0 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{codecraftai_taskplus-1.4.0 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/execution.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{codecraftai_taskplus-1.4.0 → codecraftai_taskplus-1.4.1}/source/packages/ccai/taskplus/py.typed
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|