-
Notifications
You must be signed in to change notification settings - Fork 12
feat(spider-py): Add Data, Task, and TaskGraph to core.
#180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+152
−0
Merged
Changes from all commits
Commits
Show all changes
123 commits
Select commit
Hold shift + click to select a range
d2ac198
Update yscope-dev-utils
sitaowang1998 cc8a097
Use boost install task
sitaowang1998 7f68bdc
Update install task variable names
sitaowang1998 2394649
Set CMP0074 to NEW to find boost
sitaowang1998 6ff3e33
Add uv to install script
sitaowang1998 7ae8a78
Fix cpp-lint root paths
sitaowang1998 56502f9
Fix clang-tidy file pattern
sitaowang1998 6f6becf
Limit build parallelism
sitaowang1998 a74523d
Bug fix
sitaowang1998 2345d22
Merge branch 'dep-concurrency' into yscope-dev-utils
sitaowang1998 77ee494
Bug fix
sitaowang1998 38b86c8
Merge branch 'dep-concurrency' into yscope-dev-utils
sitaowang1998 3698339
Bug fix
sitaowang1998 369e9f1
Rename variables to mirror CLP core
sitaowang1998 90aa5a2
Rename variables to mirror clp core
sitaowang1998 1769c95
Merge branch 'dep-concurrency' of github.com:sitaowang1998/spider int…
sitaowang1998 edaa834
Merge branch 'dep-concurrency' into yscope-dev-utils
sitaowang1998 7faac8f
Revert "Merge branch 'dep-concurrency' of github.com:sitaowang1998/sp…
sitaowang1998 f494a90
Add comment for deps parallelism default value
sitaowang1998 eb01bb2
Merge branch 'dep-concurrency' into yscope-dev-utils
sitaowang1998 ff2fe1c
Update yscope-dev-utils
sitaowang1998 d476e42
Merge branch 'main' into yscope-dev-utils
sitaowang1998 850126d
Merge branch 'yscope-dev-utils' into python_lint
sitaowang1998 65841a0
Add latest python lint config files
sitaowang1998 8564fc2
Update ruff lint tasks
sitaowang1998 a6e7d29
Fix ruff lint
sitaowang1998 573b448
Fix ruff lint
sitaowang1998 6ad72c3
Bug fix
sitaowang1998 ba7c6e5
Fix ruff
sitaowang1998 209acb1
Fix ruff
sitaowang1998 406b514
Reformat files
sitaowang1998 66892f5
Remove .inc from cpp linting
sitaowang1998 80f0a10
Merge branch 'yscope-dev-utils' into python_lint
sitaowang1998 3186a42
Add mypy and merge lint and test requirements.txt
sitaowang1998 0925938
Fix mysql connection type
sitaowang1998 6936a9b
Fix socket name type
sitaowang1998 7407090
Fix return type from db cursor
sitaowang1998 6a95b24
Fix db cursor return type
sitaowang1998 f29dcba
Fix mypy import untyped
sitaowang1998 453f209
Fix mypy and Popen
sitaowang1998 d1011c7
Fix generator type hint
sitaowang1998 a7dc642
Fix mypy
sitaowang1998 a7d92c2
Fix ruff
sitaowang1998 1c6213b
Simply socket return types.
sitaowang1998 0f13d07
Merge branch 'main' into python_lint
sitaowang1998 14d6326
Merge branch 'python_lint' into mypy_lint
sitaowang1998 55a727a
Add tombi lint tasks
sitaowang1998 c98fea1
Rename cpp build tasks
sitaowang1998 ef64454
Merge branch 'main' into mypy_lint
sitaowang1998 09ba8ad
Merge branch 'main' into tombi
sitaowang1998 4e7237e
Add basic python structure
sitaowang1998 1f944d0
Fix code structure
sitaowang1998 68992fc
Fix ruff lint
sitaowang1998 1127b22
Extend lint tasks to python directory
sitaowang1998 4c51c91
Add python build tasks
sitaowang1998 56878b2
Merge branch 'main' into mypy_lint
sitaowang1998 bb428c9
Merge branch 'mypy_lint' into tombi
sitaowang1998 944bd5e
Merge branch 'tombi' into build-task
sitaowang1998 d75bc15
Merge branch 'build-task' into python_structure
sitaowang1998 4b7eca2
Merge branch 'main' into tombi
sitaowang1998 8ddbda7
Merge branch 'tombi' into build-task
sitaowang1998 0d998ec
Merge branch 'build-task' into python_structure
sitaowang1998 6004d64
Fix yaml lint error
sitaowang1998 bcab5db
Fix tombi lint
sitaowang1998 a50d25a
Remove wrong mypy config
sitaowang1998 fbebb96
Fix typo and format file
sitaowang1998 0322bd5
Use typed msgpack and remove mypy config for msgpack from pyproject
sitaowang1998 2a08155
Update uv lock
sitaowang1998 dd29c23
Add task module
sitaowang1998 570cf2f
Merge branch 'python_structure' into python_task
sitaowang1998 9b2a175
Add data and improve type alias
sitaowang1998 32afe0a
Add task graph and reformat files
sitaowang1998 0b62f73
Merge branch 'main' into tombi
sitaowang1998 7384158
Merge branch 'main' into build-task
sitaowang1998 70ef90a
Merge branch 'main' into python_structure
sitaowang1998 1aae0cb
Merge branch 'main' into python_task
sitaowang1998 2f9b4a0
Fix typo
sitaowang1998 4e080ac
Fix set remove key error
sitaowang1998 b09515c
Increase min version of tombi
sitaowang1998 bad9675
Merge branch 'tombi' into build-task
sitaowang1998 e009ff4
Merge branch 'tombi' into python_structure
sitaowang1998 f11a3b6
Merge branch 'python_structure' into python_task
sitaowang1998 a0407a7
Merge branch 'main' into tombi
sitaowang1998 aa9a8de
Merge branch 'tombi' into build-task
sitaowang1998 3c7e794
Merge branch 'tombi' into python_structure
sitaowang1998 ca4ec29
Merge branch 'python_structure' into python_task
sitaowang1998 b4d6576
Add uv in README
sitaowang1998 23f31cd
Merge branch 'main' into build-task
sitaowang1998 0167ac0
Merge branch 'build-task' into python_structure
sitaowang1998 5a9cb76
Merge branch 'python_structure' into python_task
sitaowang1998 f447614
Fix redenduncy caused by merge
sitaowang1998 a84de83
Merge branch 'build-task' into python_structure
sitaowang1998 f94460f
Merge branch 'python_structure' into python_task
sitaowang1998 2d1b6fc
Merge branch 'main' into python_structure
sitaowang1998 5a35122
Merge branch 'main' into python_task
sitaowang1998 061d101
Merge branch 'main' into python_structure
sitaowang1998 451a80e
Merge branch 'main' into python_task
sitaowang1998 de149ee
Add integral types
sitaowang1998 d332dbe
Revert "Add integral types"
sitaowang1998 8c27b16
Restructure under src/spider
sitaowang1998 1b7ab77
Merge branch 'python_structure' into python_task
sitaowang1998 95b98c8
Merge branch 'main' into python_structure
sitaowang1998 e7b119c
Merge branch 'main' into python_task
sitaowang1998 8ffbd03
Fix import path
sitaowang1998 427dd6b
Merge branch 'main' into python_structure
sitaowang1998 a9c9e57
Merge branch 'main' into python_task
sitaowang1998 854cd11
Fix missing link
sitaowang1998 5565c9e
Merge branch 'python_structure' of github.com:sitaowang1998/spider in…
sitaowang1998 a9791e5
Merge branch 'python_structure' into python_task
sitaowang1998 01dd0c6
Fix task executor path
sitaowang1998 c6ccce6
Merge branch 'python_structure' into python_task
sitaowang1998 01c9c64
Merge branch 'main' into python_task
sitaowang1998 b86d47c
Merge branch 'main' into python_task
sitaowang1998 008c6fb
Export core
sitaowang1998 4d10f88
"Add default values for tasks"
sitaowang1998 f6192a3
Merge branch 'main' into python_task
sitaowang1998 ea76464
Fix merge
sitaowang1998 9448189
Fix merge
sitaowang1998 be143a7
Rename taskgraph.py to task_graph.py
sitaowang1998 c4c035a
Move class members to class docstring
sitaowang1998 fa935d1
Fix docstring
sitaowang1998 08b7965
Explicity check list not none and not empty
sitaowang1998 b07c858
Merge branch 'main' into python_task
sitaowang1998 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,32 @@ | ||
| """Spider core package.""" | ||
|
|
||
| from .data import Data, DataId | ||
| from .task import ( | ||
| Task, | ||
| TaskId, | ||
| TaskInput, | ||
| TaskInputData, | ||
| TaskInputOutput, | ||
| TaskInputValue, | ||
| TaskOutput, | ||
| TaskOutputData, | ||
| TaskOutputValue, | ||
| TaskState, | ||
| ) | ||
| from .task_graph import TaskGraph | ||
|
|
||
| __all__ = [ | ||
| "Data", | ||
| "DataId", | ||
| "Task", | ||
| "TaskGraph", | ||
| "TaskId", | ||
| "TaskInput", | ||
| "TaskInputData", | ||
| "TaskInputOutput", | ||
| "TaskInputValue", | ||
| "TaskOutput", | ||
| "TaskOutputData", | ||
| "TaskOutputValue", | ||
| "TaskState", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| """Data module for Spider.""" | ||
|
|
||
| from dataclasses import dataclass | ||
| from uuid import UUID | ||
|
|
||
| DataId = UUID | ||
|
|
||
|
|
||
| @dataclass | ||
| class Data: | ||
| """Represents a data object.""" | ||
|
|
||
| id: DataId | ||
| value: bytes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,50 @@ | ||
| """Task module for Spider.""" | ||
|
|
||
| from dataclasses import dataclass, field | ||
| from enum import IntEnum | ||
| from uuid import UUID, uuid4 | ||
|
|
||
| from spider_py.core.data import DataId | ||
|
|
||
| TaskId = UUID | ||
|
|
||
|
|
||
| @dataclass | ||
| class TaskInputOutput: | ||
| """Represents a task input that references the output of another task by its ID and position.""" | ||
|
|
||
| task_id: TaskId | ||
| position: int | ||
|
|
||
|
|
||
| TaskInputValue = bytes | ||
| TaskInputData = DataId | ||
| TaskInput = TaskInputOutput | TaskInputValue | TaskInputData | ||
|
|
||
| TaskOutputValue = bytes | ||
| TaskOutputData = DataId | ||
| TaskOutput = TaskOutputValue | TaskOutputData | ||
|
|
||
|
|
||
| class TaskState(IntEnum): | ||
| """Represents the state of a task""" | ||
|
|
||
| Pending = 0 | ||
| Ready = 1 | ||
| Running = 2 | ||
| Succeeded = 3 | ||
| Failed = 4 | ||
| Cancelled = 5 | ||
|
|
||
|
|
||
| @dataclass | ||
| class Task: | ||
| """Represents a task in Spider.""" | ||
|
|
||
| task_id: TaskId = field(default_factory=uuid4) | ||
| function_name: str = "" | ||
| state: TaskState = TaskState.Pending | ||
| timeout: float = 0 | ||
| max_retries: int = 0 | ||
| task_inputs: list[TaskInput] = field(default_factory=list) | ||
| task_outputs: list[TaskOutput] = field(default_factory=list) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| """TaskGraph module for Spider.""" | ||
|
|
||
| from spider_py.core.task import Task, TaskId | ||
|
|
||
|
|
||
| class TaskGraph: | ||
| """ | ||
| Represents a task graph in Spider. | ||
| TaskGraph represents a directed acyclic graph (DAG) of tasks. | ||
| It stores: | ||
| - tasks: A dictionary mapping task ids to Task objects. | ||
| - dependencies: A list of tuples representing the dependencies between tasks. Each tuple | ||
| contains: | ||
| - parent task id | ||
| - child task id | ||
| - input_tasks: A set of task ids that have no parents (input tasks). | ||
| - output_tasks: A set of task ids that have no children (output tasks). | ||
| """ | ||
|
|
||
| def __init__(self) -> None: | ||
| """Initializes an empty task graph.""" | ||
| self.tasks: dict[TaskId, Task] = {} | ||
| self.dependencies: list[tuple[TaskId, TaskId]] = [] | ||
| self.input_tasks: set[TaskId] = set() | ||
| self.output_tasks: set[TaskId] = set() | ||
|
|
||
| def add_task( | ||
| self, task: Task, parents: list[TaskId] | None = None, children: list[TaskId] | None = None | ||
| ) -> None: | ||
| """ | ||
| Adds a task to the graph. | ||
| :param task: The task to add. | ||
| :param parents: The parent ids of the task. Must be already in the task graph. | ||
| :param children: The children ids of the task. Must be already in the task graph. | ||
| """ | ||
| self.tasks[task.task_id] = task | ||
| if parents is not None and len(parents) > 0: | ||
| for parent in parents: | ||
| self.dependencies.append((parent, task.task_id)) | ||
| self.output_tasks.discard(parent) | ||
| else: | ||
| self.input_tasks.add(task.task_id) | ||
| if children is not None and len(children) > 0: | ||
| for child in children: | ||
| self.dependencies.append((task.task_id, child)) | ||
| self.input_tasks.discard(child) | ||
| else: | ||
| self.output_tasks.add(task.task_id) | ||
|
|
||
| def get_parents(self, task_id: TaskId) -> list[Task]: | ||
| """ | ||
| :param task_id: | ||
| :return: Parent tasks of the task identified by `task_id`. | ||
| """ | ||
| return [self.tasks[parent] for (parent, child) in self.dependencies if child == task_id] | ||
|
|
||
| def get_children(self, task_id: TaskId) -> list[Task]: | ||
| """ | ||
| :param task_id: | ||
| :return: Child tasks of the task identified by `task_id`. | ||
| """ | ||
| return [self.tasks[child] for (parent, child) in self.dependencies if parent == task_id] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Validate basic Task invariants (non-negative timeout and retries)
Prevent obviously invalid state early.
@dataclass class Task: @@ task_outputs: list[TaskOutput] = field(default_factory=list) + + def __post_init__(self) -> None: + if self.timeout < 0: + raise ValueError("timeout must be non-negative") + if self.max_retries < 0: + raise ValueError("max_retries must be non-negative")🤖 Prompt for AI Agents