orchestral 0.1.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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ada Lündhé
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,40 @@
1
+ Metadata-Version: 2.2
2
+ Name: orchestral
3
+ Version: 0.1.0
4
+ Summary: A library for for orchestrating tasks asynchronously.
5
+ Author-email: Ada Lundhe <adalundhe@lundhe.audio>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 Ada Lündhé
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Keywords: pypi,cicd,python,workflows,task,runner,async
29
+ Classifier: Programming Language :: Python :: 3.11
30
+ Classifier: Programming Language :: Python :: 3.12
31
+ Classifier: Programming Language :: Python :: 3.13
32
+ Classifier: License :: OSI Approved :: MIT License
33
+ Classifier: Operating System :: OS Independent
34
+ Requires-Python: >=3.11
35
+ Description-Content-Type: text/markdown
36
+ License-File: LICENSE
37
+ Requires-Dist: taskex
38
+
39
+ # orchestral
40
+ Orchestrate and execute tasks.
@@ -0,0 +1,2 @@
1
+ # orchestral
2
+ Orchestrate and execute tasks.
@@ -0,0 +1 @@
1
+ from .orchestral import Orchestral as Orchestral
@@ -0,0 +1,85 @@
1
+ import functools
2
+ from typing import Any, Literal, TypeVar
3
+
4
+ from .step import Step, WorkflowTask
5
+
6
+ T = TypeVar("T")
7
+
8
+
9
+ class Group:
10
+ def __init__(
11
+ self,
12
+ group_id: int,
13
+ ):
14
+ self.id = group_id
15
+ self._steps: list[Step[T]] = []
16
+
17
+ def __iter__(self):
18
+ for step in self._steps:
19
+ yield step
20
+
21
+ def add_task(
22
+ self,
23
+ step: WorkflowTask[T],
24
+ *args: tuple[Any, ...],
25
+ alias: str | None = None,
26
+ timeout: str | int | float | None = None,
27
+ schedule: str | None = None,
28
+ trigger: Literal["MANUAL", "ON_START"] = "MANUAL",
29
+ repeat: int | Literal["NEVER", "ALWAYS"] = "NEVER",
30
+ keep: int | None = None,
31
+ max_age: str | None = None,
32
+ keep_policy: Literal["COUNT", "AGE", "COUNT_AND_AGE"] = "COUNT",
33
+ **kwargs: dict[str, Any],
34
+ ):
35
+ self._steps.append(
36
+ Step(
37
+ functools.partial(
38
+ step,
39
+ *args,
40
+ **kwargs,
41
+ ),
42
+ alias=alias,
43
+ timeout=timeout,
44
+ schedule=schedule,
45
+ trigger=trigger,
46
+ repeat=repeat,
47
+ keep=keep,
48
+ max_age=max_age,
49
+ keep_policy=keep_policy,
50
+ )
51
+ )
52
+
53
+ def add_command(
54
+ self,
55
+ step: str,
56
+ *args: tuple[str],
57
+ alias: str | None = None,
58
+ env: dict[str, Any] | None = None,
59
+ cwd: str | None = None,
60
+ shell: bool = False,
61
+ timeout: str | int | float | None = None,
62
+ schedule: str | None = None,
63
+ trigger: Literal["MANUAL", "ON_START"] = "MANUAL",
64
+ repeat: int | Literal["NEVER", "ALWAYS"] = "NEVER",
65
+ keep: int | None = None,
66
+ max_age: str | None = None,
67
+ keep_policy: Literal["COUNT", "AGE", "COUNT_AND_AGE"] = "COUNT",
68
+ ):
69
+ self._steps.append(
70
+ Step(
71
+ step,
72
+ shell_args=args,
73
+ env=env,
74
+ cwd=cwd,
75
+ shell=shell,
76
+ alias=alias,
77
+ timeout=timeout,
78
+ schedule=schedule,
79
+ trigger=trigger,
80
+ repeat=repeat,
81
+ keep=keep,
82
+ max_age=max_age,
83
+ keep_policy=keep_policy,
84
+ )
85
+ )
@@ -0,0 +1,140 @@
1
+ import asyncio
2
+ from collections import defaultdict
3
+ from typing import Dict, List
4
+
5
+ from taskex import Env
6
+ from taskex.run import Run
7
+
8
+ from .step_type import StepType
9
+ from .workflow import Workflow
10
+
11
+
12
+ class Orchestral:
13
+ def __init__(
14
+ self,
15
+ config: Env | None = None,
16
+ ) -> None:
17
+ self._workflow = Workflow(config=config)
18
+
19
+ self._execution_orders: Dict[str, List[List[str]]] = {}
20
+ self._batch_results: list[Run] = []
21
+ self._results_waiter = asyncio.Event()
22
+ self._run_task: asyncio.Task | None = None
23
+ self._execute_next = False
24
+
25
+ self.results: dict[str, dict[int, Run]] = defaultdict(dict)
26
+
27
+ def __enter__(self):
28
+ self._workflow = Workflow()
29
+ return self._workflow
30
+
31
+ def __exit__(self, type, value, traceback):
32
+ pass
33
+
34
+ async def __aiter__(self):
35
+ # Before we yield results wait
36
+ if self._results_waiter.is_set() is False:
37
+ await self._results_waiter.wait()
38
+
39
+ results = list(self._batch_results)
40
+
41
+ yield results
42
+
43
+ def create(self):
44
+ self._workflow = Workflow()
45
+ return self._workflow
46
+
47
+ async def run(
48
+ self,
49
+ wait: bool = False,
50
+ ):
51
+ if wait:
52
+ await self._run_workflow()
53
+
54
+ else:
55
+ self._run_task = asyncio.create_task(
56
+ self._run_workflow(),
57
+ )
58
+
59
+ async def _run_workflow(self):
60
+ self._execute_next = True
61
+ for group in self._workflow:
62
+ self._batch_results.clear()
63
+
64
+ group_runs = [
65
+ self._workflow.runner.command(
66
+ step.call,
67
+ *step.shell_args,
68
+ alias=step.alias,
69
+ env=step.env,
70
+ cwd=step.cwd,
71
+ shell=step.shell,
72
+ timeout=step.timeout,
73
+ schedule=step.schedule,
74
+ trigger=step.trigger,
75
+ repeat=step.repeat,
76
+ keep=step.keep,
77
+ max_age=step.max_age,
78
+ keep_policy=step.keep_policy,
79
+ )
80
+ if step.type == StepType.SHELL
81
+ else self._workflow.runner.run(
82
+ step.call,
83
+ alias=step.alias,
84
+ timeout=step.timeout,
85
+ schedule=step.schedule,
86
+ trigger=step.trigger,
87
+ repeat=step.repeat,
88
+ keep=step.keep,
89
+ max_age=step.max_age,
90
+ keep_policy=step.keep_policy,
91
+ )
92
+ for step in group
93
+ ]
94
+
95
+ group_results = await self._workflow.runner.wait_all(
96
+ [run.token for run in group_runs],
97
+ )
98
+
99
+ self._batch_results.extend(group_results)
100
+
101
+ for res in group_results:
102
+ self.results[res.task_name][res.run_id] = res
103
+
104
+ if self._results_waiter.is_set() is False:
105
+ self._results_waiter.set()
106
+
107
+ if self._execute_next is False:
108
+ break
109
+
110
+ async def stop(self):
111
+ self._execute_next = False
112
+ await self._workflow.runner.stop()
113
+
114
+ async def shutdown(self):
115
+ self._execute_next = False
116
+ await self._workflow.runner.shutdown()
117
+
118
+ if self._run_task:
119
+ await self._run_task
120
+
121
+ if self._results_waiter.is_set() is False:
122
+ self._results_waiter.set()
123
+
124
+ def abort(self):
125
+ self._execute_next = False
126
+
127
+ try:
128
+ self._run_task.cancel()
129
+
130
+ except (
131
+ asyncio.CancelledError,
132
+ asyncio.InvalidStateError,
133
+ asyncio.TimeoutError,
134
+ ):
135
+ pass
136
+
137
+ if self._results_waiter.is_set() is False:
138
+ self._results_waiter.set()
139
+
140
+ self._workflow.runner.abort()
@@ -0,0 +1,73 @@
1
+ import inspect
2
+ from typing import (
3
+ Any,
4
+ Awaitable,
5
+ Callable,
6
+ Generic,
7
+ Literal,
8
+ TypeVar,
9
+ )
10
+
11
+ from .step_type import StepType
12
+
13
+ T = TypeVar("T")
14
+
15
+ WorkflowTask = Callable[..., Awaitable[T]] | Callable[..., T]
16
+ WorkflowStep = str | WorkflowTask[T]
17
+
18
+
19
+ class Step(Generic[T]):
20
+ def __init__(
21
+ self,
22
+ step: WorkflowStep[T],
23
+ *dependencies: list[WorkflowStep[T]],
24
+ shell_args: tuple[str, ...],
25
+ env: dict[str, Any] | None = None,
26
+ cwd: str | None = None,
27
+ shell: bool = False,
28
+ alias: str | None = None,
29
+ timeout: str | int | float | None = None,
30
+ schedule: str | None = None,
31
+ trigger: Literal["MANUAL", "ON_START"] = "MANUAL",
32
+ repeat: int | Literal["NEVER", "ALWAYS"] = "NEVER",
33
+ keep: int | None = None,
34
+ max_age: str | None = None,
35
+ keep_policy: Literal["COUNT", "AGE", "COUNT_AND_AGE"] = "COUNT",
36
+ ):
37
+ self.call = step
38
+ self.dependencies = [
39
+ dependency
40
+ if isinstance(
41
+ dependency,
42
+ str,
43
+ )
44
+ else dependency.__name__
45
+ for dependency in dependencies
46
+ ]
47
+
48
+ self.alias = alias
49
+ self.timeout = timeout
50
+ self.schedule = schedule
51
+ self.trigger = trigger
52
+ self.repeat = repeat
53
+ self.keep = keep
54
+ self.max_age = max_age
55
+ self.keep_policy = keep_policy
56
+
57
+ self.env = env
58
+ self.cwd = cwd
59
+ self.shell = shell
60
+ self.shell_args = shell_args
61
+
62
+ if isinstance(step, str):
63
+ self.type = StepType.SHELL
64
+
65
+ elif (
66
+ inspect.iscoroutine(step)
67
+ or inspect.iscoroutinefunction(step)
68
+ or inspect.isawaitable(step)
69
+ ):
70
+ self.type = StepType.ASYNC
71
+
72
+ else:
73
+ self.type = StepType.SYNC
@@ -0,0 +1,7 @@
1
+ from enum import Enum
2
+
3
+
4
+ class StepType(Enum):
5
+ SHELL = "SHELL"
6
+ SYNC = "SYNC"
7
+ ASYNC = "ASYNC"
@@ -0,0 +1,26 @@
1
+ from typing import Dict, List, TypeVar
2
+
3
+ from taskex import Env, TaskRunner
4
+
5
+ from .group import Group
6
+
7
+ T = TypeVar("T")
8
+
9
+
10
+ class Workflow:
11
+ def __init__(
12
+ self,
13
+ config: Env | None = None,
14
+ ) -> None:
15
+ self._groups: list[Group] = []
16
+ self._execution_orders: Dict[str, List[List[str]]] = {}
17
+ self.runner = TaskRunner(config=config)
18
+
19
+ def __iter__(self):
20
+ for group in self._groups:
21
+ yield group
22
+
23
+ def group(self):
24
+ group = Group(self.runner._snowflake_generator.generate())
25
+ self._groups.append(group)
26
+ return group
@@ -0,0 +1,40 @@
1
+ Metadata-Version: 2.2
2
+ Name: orchestral
3
+ Version: 0.1.0
4
+ Summary: A library for for orchestrating tasks asynchronously.
5
+ Author-email: Ada Lundhe <adalundhe@lundhe.audio>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 Ada Lündhé
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Keywords: pypi,cicd,python,workflows,task,runner,async
29
+ Classifier: Programming Language :: Python :: 3.11
30
+ Classifier: Programming Language :: Python :: 3.12
31
+ Classifier: Programming Language :: Python :: 3.13
32
+ Classifier: License :: OSI Approved :: MIT License
33
+ Classifier: Operating System :: OS Independent
34
+ Requires-Python: >=3.11
35
+ Description-Content-Type: text/markdown
36
+ License-File: LICENSE
37
+ Requires-Dist: taskex
38
+
39
+ # orchestral
40
+ Orchestrate and execute tasks.
@@ -0,0 +1,14 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ orchestral/__init__.py
5
+ orchestral/group.py
6
+ orchestral/orchestral.py
7
+ orchestral/step.py
8
+ orchestral/step_type.py
9
+ orchestral/workflow.py
10
+ orchestral.egg-info/PKG-INFO
11
+ orchestral.egg-info/SOURCES.txt
12
+ orchestral.egg-info/dependency_links.txt
13
+ orchestral.egg-info/requires.txt
14
+ orchestral.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ taskex
@@ -0,0 +1 @@
1
+ orchestral
@@ -0,0 +1,34 @@
1
+ [project]
2
+ name = "orchestral"
3
+ version = "0.1.0"
4
+ description = "A library for for orchestrating tasks asynchronously."
5
+ readme = "README.md"
6
+ requires-python = ">=3.11"
7
+ authors = [
8
+ {name = "Ada Lundhe", email = "adalundhe@lundhe.audio"}
9
+ ]
10
+ classifiers = [
11
+ "Programming Language :: Python :: 3.11",
12
+ "Programming Language :: Python :: 3.12",
13
+ "Programming Language :: Python :: 3.13",
14
+ "License :: OSI Approved :: MIT License",
15
+ "Operating System :: OS Independent",
16
+ ]
17
+ keywords = [
18
+ 'pypi',
19
+ 'cicd',
20
+ 'python',
21
+ 'workflows',
22
+ 'task',
23
+ 'runner',
24
+ 'async',
25
+ ]
26
+ license = { file = "LICENSE" }
27
+ dependencies = [
28
+ 'taskex',
29
+ ]
30
+
31
+ [build-system]
32
+ requires = ["setuptools>=61.0"]
33
+ build-backend = "setuptools.build_meta"
34
+
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+