codecraftai-taskplus 1.3.0__py3-none-any.whl
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.
- ccai/taskplus/__init__.py +0 -0
- ccai/taskplus/cli/__init__.py +0 -0
- ccai/taskplus/cli/cmdtree/__init__.py +0 -0
- ccai/taskplus/cli/cmdtree/workflow.py +153 -0
- ccai/taskplus/cli/taskpluscommand.py +25 -0
- ccai/taskplus/entrypoints.py +68 -0
- ccai/taskplus/execution.py +132 -0
- ccai/taskplus/initialize.py +44 -0
- ccai/taskplus/model/__init__.py +0 -0
- ccai/taskplus/model/flowengine.py +106 -0
- ccai/taskplus/model/flownode.py +40 -0
- ccai/taskplus/model/task.py +61 -0
- ccai/taskplus/model/taskgroup.py +27 -0
- ccai/taskplus/model/workflow.py +142 -0
- ccai/taskplus/py.typed +0 -0
- ccai/taskplus/tasks/__init__.py +0 -0
- ccai/taskplus/tasks/createenvironment.py +96 -0
- ccai/taskplus/tasks/embeddedpython.py +49 -0
- ccai/taskplus/tasks/gitcheckout.py +28 -0
- ccai/taskplus/tasks/runcommand.py +68 -0
- ccai/taskplus/tasks/shellscript.py +85 -0
- codecraftai_taskplus-1.3.0.dist-info/METADATA +25 -0
- codecraftai_taskplus-1.3.0.dist-info/RECORD +26 -0
- codecraftai_taskplus-1.3.0.dist-info/WHEEL +4 -0
- codecraftai_taskplus-1.3.0.dist-info/entry_points.txt +3 -0
- codecraftai_taskplus-1.3.0.dist-info/licenses/LICENSE.md +204 -0
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
__author__ = "Myron Walker"
|
|
2
|
+
__copyright__ = "Copyright 2023, Myron W Walker"
|
|
3
|
+
__credits__ = []
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
from typing import Optional
|
|
7
|
+
|
|
8
|
+
import os
|
|
9
|
+
|
|
10
|
+
from datetime import datetime
|
|
11
|
+
|
|
12
|
+
import click
|
|
13
|
+
import yaml
|
|
14
|
+
|
|
15
|
+
from ccai.xmodules.xdatetime import DATETIME_FORMAT_FILESYSTEM, DATETIME_FORMAT_TIMESTAMP, parse_datetime
|
|
16
|
+
from ccai.xmodules.xlogging.levels import LOG_LEVEL_NAMES
|
|
17
|
+
|
|
18
|
+
HELP_WORK = "The file containing the workpacket detail for performing a workflow orchestration."
|
|
19
|
+
HELP_OUTPUT = "The output directory where results and artifacts are collected."
|
|
20
|
+
HELP_START = r"A time stamp to associate with the start of the run. Example: 2020-10-17T15:30:11.989120 Bash: date +%Y-%m-%dT%H:%M:%S.%N"
|
|
21
|
+
HELP_CONSOLE_LOG_LEVEL = "The logging level for console output."
|
|
22
|
+
HELP_FILE_LOG_LEVEL = "The logging level for logfile output."
|
|
23
|
+
|
|
24
|
+
START_FORMATS = [DATETIME_FORMAT_TIMESTAMP, DATETIME_FORMAT_FILESYSTEM]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def parse_start_option(start: str) -> datetime:
|
|
28
|
+
"""
|
|
29
|
+
Parses the value of the '--start' option into a :class:`datetime`. The value is parsed with the same
|
|
30
|
+
timestamp and filesystem formats that are used to resolve the 'AM_STARTTIME' runtime variable.
|
|
31
|
+
|
|
32
|
+
:param start: The time stamp string passed to the '--start' option.
|
|
33
|
+
|
|
34
|
+
:returns: The start time as a :class:`datetime`.
|
|
35
|
+
:raises: click.BadParameter
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
starttime = None
|
|
39
|
+
|
|
40
|
+
for start_format in START_FORMATS:
|
|
41
|
+
try:
|
|
42
|
+
starttime = parse_datetime(start, datetime_format=start_format)
|
|
43
|
+
break
|
|
44
|
+
except ValueError:
|
|
45
|
+
continue
|
|
46
|
+
|
|
47
|
+
if starttime is None:
|
|
48
|
+
err_msg_lines = [
|
|
49
|
+
"The '--start' option value is not a valid time stamp.",
|
|
50
|
+
f" VALUE: {start}",
|
|
51
|
+
"EXPECTED FORMATS:",
|
|
52
|
+
]
|
|
53
|
+
for start_format in START_FORMATS:
|
|
54
|
+
err_msg_lines.append(f" {start_format}")
|
|
55
|
+
errmsg = os.linesep.join(err_msg_lines)
|
|
56
|
+
raise click.BadParameter(errmsg, param_hint="'--start'")
|
|
57
|
+
|
|
58
|
+
return starttime
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@click.group("workflow", help="Contains commands that are used to work with or run workflow scripts.")
|
|
62
|
+
def group_taskplus_workflow():
|
|
63
|
+
return
|
|
64
|
+
|
|
65
|
+
@click.command("run")
|
|
66
|
+
@click.argument("workflow", required=True)
|
|
67
|
+
@click.option("--output", "-o", required=False, help=HELP_OUTPUT)
|
|
68
|
+
@click.option("--start", default=None, required=False, help=HELP_START)
|
|
69
|
+
@click.option("--console-level", default=None, required=False, type=click.Choice(LOG_LEVEL_NAMES, case_sensitive=False), help=HELP_CONSOLE_LOG_LEVEL)
|
|
70
|
+
@click.option("--logfile-level", default=None, required=False, type=click.Choice(LOG_LEVEL_NAMES, case_sensitive=False), help=HELP_FILE_LOG_LEVEL)
|
|
71
|
+
def command_taskplus_workflow_run(workflow: str, output: Optional[str] = None, start: Optional[str] = None,
|
|
72
|
+
console_level: Optional[str] = None, logfile_level: Optional[str] = None):
|
|
73
|
+
"""
|
|
74
|
+
Runs a workflow file. The '--output', '--start', '--console-level' and '--logfile-level' options are applied
|
|
75
|
+
as runtime option overrides, the same way the 'testbase' and 'testplus' run commands apply them, before the
|
|
76
|
+
'Orchestration' job profile is activated so the output directory, start time and log levels are in effect
|
|
77
|
+
for the workflow run.
|
|
78
|
+
|
|
79
|
+
:param workflow: The path of the workflow file to run.
|
|
80
|
+
:param output: The output directory where results and artifacts are collected.
|
|
81
|
+
:param start: A time stamp to associate with the start of the run.
|
|
82
|
+
:param console_level: The logging level for console output.
|
|
83
|
+
:param logfile_level: The logging level for logfile output.
|
|
84
|
+
|
|
85
|
+
:raises: click.BadParameter
|
|
86
|
+
"""
|
|
87
|
+
|
|
88
|
+
# pylint: disable=unused-import,import-outside-toplevel
|
|
89
|
+
|
|
90
|
+
# We do the imports of the automation framework code inside the action functions because
|
|
91
|
+
# we don't want to startup loggin and the processing of inputs and environment variables
|
|
92
|
+
# until we have entered an action method. Thats way we know how to setup the environment.
|
|
93
|
+
from ccai.runtime.optionoverrides import AM_RUNTIME_OPTION_OVERRIDES
|
|
94
|
+
|
|
95
|
+
from ccai.thisapp.activation import activate_profile_job
|
|
96
|
+
from ccai.thisapp.enumerations import JobType
|
|
97
|
+
from ccai.thisapp.runtimevariables import RuntimeVariables
|
|
98
|
+
|
|
99
|
+
from ccai.taskplus.initialize import initialize_taskplus_runtime
|
|
100
|
+
|
|
101
|
+
workflow_file = os.path.abspath(os.path.expanduser(os.path.expandvars(workflow)))
|
|
102
|
+
if not os.path.exists(workflow_file):
|
|
103
|
+
error_msg = "The specified workflow file does not exist. file=%s" % workflow_file
|
|
104
|
+
raise click.BadParameter(error_msg)
|
|
105
|
+
|
|
106
|
+
# Validate the start time before we make any changes to the runtime.
|
|
107
|
+
starttime = None
|
|
108
|
+
if start is not None:
|
|
109
|
+
starttime = parse_start_option(start)
|
|
110
|
+
|
|
111
|
+
workflow_info = None
|
|
112
|
+
with open(workflow_file, 'r') as wpf:
|
|
113
|
+
wpfcontent = wpf.read()
|
|
114
|
+
workflow_info = yaml.safe_load(wpfcontent)
|
|
115
|
+
|
|
116
|
+
if workflow_info is not None:
|
|
117
|
+
|
|
118
|
+
# STEP 1 - Initialize the runtime so the option overrides have a runtime to apply to.
|
|
119
|
+
initialize_taskplus_runtime()
|
|
120
|
+
|
|
121
|
+
# STEP 2 - Apply the runtime option overrides. These must be applied before the job profile
|
|
122
|
+
# is activated because the activation uses them to setup the output directory and logging.
|
|
123
|
+
if console_level is not None:
|
|
124
|
+
AM_RUNTIME_OPTION_OVERRIDES.override_loglevel_console(console_level)
|
|
125
|
+
|
|
126
|
+
if logfile_level is not None:
|
|
127
|
+
AM_RUNTIME_OPTION_OVERRIDES.override_loglevel_file(logfile_level)
|
|
128
|
+
|
|
129
|
+
if output is not None:
|
|
130
|
+
AM_RUNTIME_OPTION_OVERRIDES.override_output_directory(output)
|
|
131
|
+
|
|
132
|
+
if starttime is not None:
|
|
133
|
+
AM_RUNTIME_OPTION_OVERRIDES.override_starttime(starttime)
|
|
134
|
+
|
|
135
|
+
# STEP 3 - Activate the 'Orchestration' job profile which sets up the output directory and logging. A
|
|
136
|
+
# profile can only be activated once per process, so when the workflow is run inside of a process that
|
|
137
|
+
# has already activated a profile, such as a test run, the existing profile stays in effect.
|
|
138
|
+
activation_profile = RuntimeVariables.AM_ACTIVATION_PROFILE
|
|
139
|
+
if activation_profile is None:
|
|
140
|
+
activate_profile_job(job_type=JobType.Orchestration)
|
|
141
|
+
|
|
142
|
+
from ccai.taskplus.entrypoints import run_workflow_entrypoint
|
|
143
|
+
|
|
144
|
+
# STEP 4 - Run the work packet
|
|
145
|
+
run_workflow_entrypoint(workflow_file)
|
|
146
|
+
|
|
147
|
+
else:
|
|
148
|
+
error_msg = "Failure loading the work packet info from. file=%s" % workflow_file
|
|
149
|
+
raise click.BadParameter(error_msg)
|
|
150
|
+
|
|
151
|
+
return
|
|
152
|
+
|
|
153
|
+
group_taskplus_workflow.add_command(command_taskplus_workflow_run)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: taskpluscommand
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Defines the root ``taskplus`` command-line entry point and
|
|
5
|
+
assembles the command tree.
|
|
6
|
+
|
|
7
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
__author__ = "Myron Walker"
|
|
11
|
+
__copyright__ = "Copyright 2025, Code Craft AI LLC"
|
|
12
|
+
__credits__ = []
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
import click
|
|
16
|
+
|
|
17
|
+
from ccai.taskplus.cli.cmdtree.workflow import group_taskplus_workflow
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@click.group("taskplus", help="Code Craft AI TaskPlus workflow orchestration command-line interface.")
|
|
21
|
+
def taskplus_root_command():
|
|
22
|
+
return
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
taskplus_root_command.add_command(group_taskplus_workflow)
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: entrypoints
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: A set of standaridized entry point functions that provide standardized task orchestration
|
|
5
|
+
of workpacket jobs.
|
|
6
|
+
|
|
7
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
__author__ = "Myron Walker"
|
|
11
|
+
__copyright__ = "Copyright 2020, Myron W Walker"
|
|
12
|
+
__credits__ = []
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
import logging
|
|
16
|
+
import sys
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
from ccai.taskplus.model.flowengine import FlowEngine
|
|
20
|
+
from ccai.taskplus.model.workflow import Workflow
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
logger = logging.getLogger()
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def run_workflow_entrypoint(workflow_file: str):
|
|
27
|
+
"""
|
|
28
|
+
This is the entry point for the execution of workpackets. It provides a the execution
|
|
29
|
+
context for the execution of the orchestration steps in the workpacket.
|
|
30
|
+
|
|
31
|
+
name: Example Workflow A
|
|
32
|
+
environment:
|
|
33
|
+
AKIT_BUILD_BRANCH: somebranch
|
|
34
|
+
AKIT_BUILD_NAME: somebuild-2.1.456
|
|
35
|
+
AKIT_JOBTYPE: unknown
|
|
36
|
+
|
|
37
|
+
parameters:
|
|
38
|
+
branch: somebranch
|
|
39
|
+
build: somebuild-2.1.456
|
|
40
|
+
landscape: $HOME/ccai/config/default-landscape.yaml
|
|
41
|
+
|
|
42
|
+
tasklist:
|
|
43
|
+
- task: Print OS Name
|
|
44
|
+
tasktype: ccai.taskplus.tasks.embeddedpython@EmbeddedPython
|
|
45
|
+
script:
|
|
46
|
+
- import os
|
|
47
|
+
- print(os.name)
|
|
48
|
+
|
|
49
|
+
- task: List Directories
|
|
50
|
+
tasktype: ccai.taskplus.tasks.shellscript@BashScript
|
|
51
|
+
script:
|
|
52
|
+
- ls -al
|
|
53
|
+
|
|
54
|
+
"""
|
|
55
|
+
# We must exit with a result code, initialize it to 0 here
|
|
56
|
+
result_code = 0
|
|
57
|
+
|
|
58
|
+
workflow = None
|
|
59
|
+
|
|
60
|
+
with open(workflow_file, 'r') as wpf:
|
|
61
|
+
workflow = Workflow.parse(wpf)
|
|
62
|
+
|
|
63
|
+
flowengine = FlowEngine()
|
|
64
|
+
result_code = flowengine.execute(workflow)
|
|
65
|
+
|
|
66
|
+
sys.exit(result_code)
|
|
67
|
+
|
|
68
|
+
return
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: execution
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: A module that provides the function which implemented the execution workflow
|
|
5
|
+
of an individual workpacket.
|
|
6
|
+
|
|
7
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
__author__ = "Myron Walker"
|
|
11
|
+
__copyright__ = "Copyright 2020, Myron W Walker"
|
|
12
|
+
__credits__ = []
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
from typing import Any, Dict, List
|
|
16
|
+
|
|
17
|
+
import os
|
|
18
|
+
|
|
19
|
+
from ccai.xmodules.ximport import import_by_name
|
|
20
|
+
|
|
21
|
+
from ccai.errors.exceptions import ConfigurationError
|
|
22
|
+
|
|
23
|
+
from ccai.taskplus.model.task import Task
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class JumpContext:
|
|
27
|
+
def __init__(self) -> None:
|
|
28
|
+
self.on_failure_section = None
|
|
29
|
+
self.on_success_section = None
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def execute_tasklist(logger, jump_context: JumpContext, parameters: dict, tasklist: List[Dict[str, Any]], ordinal_prefix: str=None, **kwargs):
|
|
33
|
+
|
|
34
|
+
result_code = 0
|
|
35
|
+
|
|
36
|
+
for index, item in enumerate(tasklist):
|
|
37
|
+
|
|
38
|
+
nxt_ordinal = str(index)
|
|
39
|
+
if ordinal_prefix is not None:
|
|
40
|
+
nxt_ordinal = "{}.{}".format(ordinal_prefix, nxt_ordinal)
|
|
41
|
+
|
|
42
|
+
if "task" in item:
|
|
43
|
+
|
|
44
|
+
task_info: Dict[str, Any] = item
|
|
45
|
+
|
|
46
|
+
task_label = task_info["task"]
|
|
47
|
+
|
|
48
|
+
if jump_context.on_success_section is not None:
|
|
49
|
+
if jump_context.on_success_section != task_label:
|
|
50
|
+
continue
|
|
51
|
+
else:
|
|
52
|
+
jump_context.on_success_section = None
|
|
53
|
+
|
|
54
|
+
if jump_context.on_failure_section is not None:
|
|
55
|
+
if jump_context.on_failure_section != task_label:
|
|
56
|
+
continue
|
|
57
|
+
else:
|
|
58
|
+
jump_context.on_failure_section = None
|
|
59
|
+
|
|
60
|
+
task_type = item["tasktype"]
|
|
61
|
+
|
|
62
|
+
task_module_name, task_module_class = task_type.split("@")
|
|
63
|
+
task_module = import_by_name(task_module_name)
|
|
64
|
+
|
|
65
|
+
if hasattr(task_module, task_module_class):
|
|
66
|
+
task_class = getattr(task_module, task_module_class)
|
|
67
|
+
|
|
68
|
+
task_instance: Task = task_class(nxt_ordinal, task_label, task_info, logger)
|
|
69
|
+
|
|
70
|
+
task_result = task_instance.execute(parameters=parameters, **kwargs)
|
|
71
|
+
if task_result != 0:
|
|
72
|
+
result_code = 1
|
|
73
|
+
if task_instance.onfailure is not None:
|
|
74
|
+
jump_context.on_failure_section = task_instance.onfailure
|
|
75
|
+
elif task_instance.onsuccess is not None:
|
|
76
|
+
jump_context.on_success_section = task_instance.onsuccess
|
|
77
|
+
|
|
78
|
+
else:
|
|
79
|
+
error_msg = "The specified task module %r does not contain a class %r" % (
|
|
80
|
+
task_module_name, task_module_class)
|
|
81
|
+
raise ConfigurationError(error_msg) from None
|
|
82
|
+
|
|
83
|
+
elif "taskgroup" in item:
|
|
84
|
+
|
|
85
|
+
tg_info: dict = item
|
|
86
|
+
tg_label = tg_info["taskgroup"]
|
|
87
|
+
|
|
88
|
+
if jump_context.on_success_section is not None:
|
|
89
|
+
if jump_context.on_success_section != tg_label:
|
|
90
|
+
continue
|
|
91
|
+
else:
|
|
92
|
+
jump_context.on_success_section = None
|
|
93
|
+
|
|
94
|
+
if jump_context.on_failure_section is not None:
|
|
95
|
+
if jump_context.on_failure_section != tg_label:
|
|
96
|
+
continue
|
|
97
|
+
else:
|
|
98
|
+
jump_context.on_failure_section = None
|
|
99
|
+
|
|
100
|
+
group_prefix = nxt_ordinal
|
|
101
|
+
|
|
102
|
+
tg_items = tg_info["items"]
|
|
103
|
+
|
|
104
|
+
tg_onfailure = tg_info.get("onfailure", None)
|
|
105
|
+
tg_onsuccess = tg_info.get("onsuccess", None)
|
|
106
|
+
|
|
107
|
+
tg_result = execute_tasklist(logger, jump_context, parameters, tg_items, ordinal_prefix=group_prefix)
|
|
108
|
+
if tg_result != 0:
|
|
109
|
+
result_code = 1
|
|
110
|
+
if tg_onfailure is not None:
|
|
111
|
+
jump_context.on_failure_section = tg_onfailure
|
|
112
|
+
elif tg_onsuccess is not None:
|
|
113
|
+
jump_context.on_success_section = tg_onsuccess
|
|
114
|
+
|
|
115
|
+
else:
|
|
116
|
+
pass
|
|
117
|
+
|
|
118
|
+
return result_code
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def execute_workflow(logger, *, environment: dict, parameters: dict, workflow: list, **kwargs):
|
|
122
|
+
|
|
123
|
+
# Publish the environment variables so they will take effect in the current
|
|
124
|
+
# process and any sub-processes lauched from this process
|
|
125
|
+
for key, val in environment.items():
|
|
126
|
+
os.environ[key] = val
|
|
127
|
+
|
|
128
|
+
jump_context = JumpContext()
|
|
129
|
+
|
|
130
|
+
result_code = execute_tasklist(logger, jump_context, parameters, workflow)
|
|
131
|
+
|
|
132
|
+
return result_code
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: initialize
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Helper routines used to initialize the TaskPlus runtime.
|
|
5
|
+
|
|
6
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
__author__ = "Myron Walker"
|
|
10
|
+
__copyright__ = "Copyright 2025, Code Craft AI LLC"
|
|
11
|
+
__credits__ = []
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
import os
|
|
15
|
+
|
|
16
|
+
from ccai.thisapp.persona import establish_app_persona
|
|
17
|
+
from ccai.thisapp.runtimevariables import resolve_runtime_variables
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
TASKPLUS_APP_NAME = "ccai"
|
|
21
|
+
TASKPLUS_LOGGER_NAME = "TaskPlus"
|
|
22
|
+
TASKPLUS_LOG_BASENAME = "workflow"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def initialize_taskplus_runtime():
|
|
26
|
+
"""
|
|
27
|
+
Initializes the TaskPlus runtime by establishing the application persona and resolving the runtime
|
|
28
|
+
variables, the same way the ``testbase`` and ``testplus`` commands initialize their runtimes. The runtime
|
|
29
|
+
must be initialized before runtime option overrides such as the output directory, start time or log levels
|
|
30
|
+
can be applied.
|
|
31
|
+
|
|
32
|
+
..note: Both :func:`establish_app_persona` and :func:`resolve_runtime_variables` only take effect the first
|
|
33
|
+
time they are called in a process, so when TaskPlus is running inside a process that has already
|
|
34
|
+
initialized a runtime, such as a ``testbase`` test run, the existing runtime is used.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
home_dir = os.path.join(os.path.expanduser("~"), TASKPLUS_APP_NAME)
|
|
38
|
+
|
|
39
|
+
establish_app_persona(name=TASKPLUS_APP_NAME, presence_dir=home_dir, logger_name=TASKPLUS_LOGGER_NAME,
|
|
40
|
+
log_basename=TASKPLUS_LOG_BASENAME)
|
|
41
|
+
|
|
42
|
+
resolve_runtime_variables()
|
|
43
|
+
|
|
44
|
+
return
|
|
File without changes
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
|
|
2
|
+
__author__ = "Myron Walker"
|
|
3
|
+
__copyright__ = "Copyright 2025, Code Craft AI LLC"
|
|
4
|
+
__credits__ = []
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
from typing import Any, Dict, List
|
|
8
|
+
|
|
9
|
+
from ccai.taskplus.model.flownode import FlowNode
|
|
10
|
+
from ccai.taskplus.model.task import Task
|
|
11
|
+
from ccai.taskplus.model.taskgroup import TaskGroup
|
|
12
|
+
from ccai.taskplus.model.workflow import Workflow
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class JumpContext:
|
|
16
|
+
def __init__(self):
|
|
17
|
+
self.seeking_node = None
|
|
18
|
+
return
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class FlowEngine:
|
|
22
|
+
|
|
23
|
+
def __init__(self):
|
|
24
|
+
return
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def evaluate_expression(self, if_expr: str, environment: Dict[str, str], parameters: Dict[str, Any], flowstate: Dict[str, Any]) -> bool:
|
|
28
|
+
|
|
29
|
+
# ``flowstate`` is the per-run state threaded through ``process_flowitems``
|
|
30
|
+
# and updated by each task; an ``if:`` expression is evaluated against it
|
|
31
|
+
# (plus ``environment``/``parameters``) so conditional flow can reference
|
|
32
|
+
# accumulated state. (Previously this read the always-empty instance
|
|
33
|
+
# ``self._flowstate`` and was passed no per-run state at all.)
|
|
34
|
+
eval_result = eval(if_expr)
|
|
35
|
+
|
|
36
|
+
return eval_result
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def execute(self, workflow: Workflow) -> int:
|
|
40
|
+
|
|
41
|
+
result_code = 0
|
|
42
|
+
|
|
43
|
+
environment = workflow.environment
|
|
44
|
+
parameters = workflow.parameters
|
|
45
|
+
|
|
46
|
+
flowitems = workflow.flow
|
|
47
|
+
|
|
48
|
+
flowstate = {}
|
|
49
|
+
errors = []
|
|
50
|
+
jump_context = JumpContext()
|
|
51
|
+
|
|
52
|
+
self.process_flowitems(environment, parameters, flowstate, errors, flowitems, jump_context)
|
|
53
|
+
|
|
54
|
+
if len(errors) > 0:
|
|
55
|
+
result_code = 1
|
|
56
|
+
|
|
57
|
+
return result_code
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def process_flowitems(self, environment: Dict[str, str], parameters: Dict[str, Any], flowstate: Dict[str, Any], errors: List,
|
|
61
|
+
flowitems: List[FlowNode], jump_context: JumpContext):
|
|
62
|
+
|
|
63
|
+
for fitem in flowitems:
|
|
64
|
+
|
|
65
|
+
node_label = fitem.label
|
|
66
|
+
|
|
67
|
+
# If we are seeking a specific node, skip any nodes that are not that node
|
|
68
|
+
if jump_context.seeking_node is not None:
|
|
69
|
+
if jump_context.seeking_node != node_label:
|
|
70
|
+
continue
|
|
71
|
+
else:
|
|
72
|
+
jump_context.seeking_node = None
|
|
73
|
+
|
|
74
|
+
include_node = True
|
|
75
|
+
if fitem.if_expr is not None:
|
|
76
|
+
include_node = self.evaluate_expression(fitem.if_expr, environment, parameters, flowstate)
|
|
77
|
+
|
|
78
|
+
if include_node:
|
|
79
|
+
if isinstance(fitem, Task):
|
|
80
|
+
|
|
81
|
+
task_result = fitem.execute(environment, parameters, flowstate)
|
|
82
|
+
if task_result != 0:
|
|
83
|
+
if fitem.onfailure is not None:
|
|
84
|
+
# The failure is routed to a handler node -- treat it
|
|
85
|
+
# as handled and let the handler decide the outcome.
|
|
86
|
+
jump_context.seeking_node = fitem.onfailure
|
|
87
|
+
else:
|
|
88
|
+
# An unhandled task failure must surface so that
|
|
89
|
+
# execute() returns a non-zero code (CI gating).
|
|
90
|
+
failure_info = {
|
|
91
|
+
"node": node_label,
|
|
92
|
+
"result_code": task_result,
|
|
93
|
+
}
|
|
94
|
+
errors.append(failure_info)
|
|
95
|
+
elif fitem.onsuccess is not None:
|
|
96
|
+
jump_context.seeking_node = fitem.onsuccess
|
|
97
|
+
|
|
98
|
+
elif isinstance(fitem, TaskGroup):
|
|
99
|
+
|
|
100
|
+
group_items = fitem.items
|
|
101
|
+
|
|
102
|
+
self.process_flowitems(environment, parameters, flowstate, errors, group_items,
|
|
103
|
+
jump_context)
|
|
104
|
+
|
|
105
|
+
return
|
|
106
|
+
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
|
|
2
|
+
__author__ = "Myron Walker"
|
|
3
|
+
__copyright__ = "Copyright 2025, Code Craft AI LLC"
|
|
4
|
+
__credits__ = []
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
from typing import Any, Dict
|
|
8
|
+
|
|
9
|
+
import abc
|
|
10
|
+
|
|
11
|
+
from logging import Logger
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class FlowNode(abc.ABC):
|
|
16
|
+
|
|
17
|
+
def __init__(self, ordinal: str, label: str, node_info: Dict[str, Any], logger: Logger):
|
|
18
|
+
self._ordinal = ordinal
|
|
19
|
+
self._label = label
|
|
20
|
+
self._node_info = node_info
|
|
21
|
+
self._logger = logger
|
|
22
|
+
|
|
23
|
+
self._if_expr = node_info.get("if") # Task should run only if another task succeeds
|
|
24
|
+
return
|
|
25
|
+
|
|
26
|
+
@property
|
|
27
|
+
def if_expr(self) -> str:
|
|
28
|
+
return self._if_expr
|
|
29
|
+
|
|
30
|
+
@property
|
|
31
|
+
def label(self) -> str:
|
|
32
|
+
return self._label
|
|
33
|
+
|
|
34
|
+
@property
|
|
35
|
+
def node_info(self) -> dict:
|
|
36
|
+
return self._node_info
|
|
37
|
+
|
|
38
|
+
@property
|
|
39
|
+
def ordinal(self) -> str:
|
|
40
|
+
return self._ordinal
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: taskbase
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: A module that provides the base task object that other tasks derive
|
|
5
|
+
from.
|
|
6
|
+
|
|
7
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
__author__ = "Myron Walker"
|
|
11
|
+
__copyright__ = "Copyright 2025, Code Craft AI LLC"
|
|
12
|
+
__credits__ = []
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
from typing import Any, Dict, Optional
|
|
16
|
+
|
|
17
|
+
import abc
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
from logging import Logger
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
from ccai.errors.exceptions import AbstractMethodError
|
|
24
|
+
|
|
25
|
+
from ccai.taskplus.model.flownode import FlowNode
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class Task(FlowNode):
|
|
29
|
+
|
|
30
|
+
def __init__(self, ordinal: str, label: str, node_info: Dict[str, Any], logger: Logger):
|
|
31
|
+
super().__init__(ordinal, label, node_info, logger)
|
|
32
|
+
|
|
33
|
+
self._onfailure = node_info.get("onfailure", None)
|
|
34
|
+
self._onsuccess = node_info.get("onsuccess", None)
|
|
35
|
+
|
|
36
|
+
return
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def onfailure(self) -> Optional[str]:
|
|
41
|
+
return self._onfailure
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@property
|
|
45
|
+
def onsuccess(self) -> Optional[str]:
|
|
46
|
+
return self._onsuccess
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def execute(self, environment: Dict[str, str], parameters: Dict[str, Any], flowstate: Dict[str, Any]) -> int:
|
|
50
|
+
|
|
51
|
+
self._logger.info("STEP: %s - %s" % (self._label, self._ordinal))
|
|
52
|
+
|
|
53
|
+
result = self.perform_task(environment, parameters, flowstate)
|
|
54
|
+
|
|
55
|
+
return result
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@abc.abstractmethod
|
|
59
|
+
def perform_task(self, environment: Dict[str, str], parameters: Optional[Dict[str, Any]], flowstate: Dict[str, Any]) -> int:
|
|
60
|
+
raise AbstractMethodError("TaskBase->execute must be overloaded by derived classes.") from None
|
|
61
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
|
|
2
|
+
__author__ = "Myron Walker"
|
|
3
|
+
__copyright__ = "Copyright 2025, Code Craft AI LLC"
|
|
4
|
+
__credits__ = []
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
from typing import Any, Dict, List
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
from logging import Logger
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
from ccai.taskplus.model.flownode import FlowNode
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class TaskGroup(FlowNode):
|
|
17
|
+
|
|
18
|
+
def __init__(self, ordinal: str, label: str, node_info: Dict[str, Any], items: List[FlowNode], logger: Logger):
|
|
19
|
+
super().__init__(ordinal, label, node_info, logger)
|
|
20
|
+
|
|
21
|
+
self._items = items
|
|
22
|
+
return
|
|
23
|
+
|
|
24
|
+
@property
|
|
25
|
+
def items(self) -> List[FlowNode]:
|
|
26
|
+
return self._items
|
|
27
|
+
|