Skip to content

Commit

Permalink
added python cli
Browse files Browse the repository at this point in the history
  • Loading branch information
yindia committed Oct 16, 2024
1 parent 7c25c4c commit 1e7fd66
Show file tree
Hide file tree
Showing 14 changed files with 1,822 additions and 291 deletions.
2 changes: 2 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ managed:
- buf.build/envoyproxy/protoc-gen-validate
- buf.build/bufbuild/protovalidate
plugins:
- plugin: buf.build/protocolbuffers/python:v28.2
out: modules/
- plugin: buf.build/connectrpc/go:v1.11.1
out: pkg/gen/
opt:
Expand Down
57 changes: 57 additions & 0 deletions example/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from typing import TypedDict, List
from enum import Enum
from modules.task import task, TaskType, TaskSpec
from modules.workflow import Workflow, WorkflowSpec

@task(TaskSpec(
name="hello_world",
type=TaskType.PYTHON,
description="This is a test task",
dependencies="This is a test task",
metadata={
"author": "Yuvraj Singh",
"version": "1.0.0",
},
base_image="python:3.12",
entrypoint="python",
args=[],
env={}
))
def hello_world(a : int, b : int) -> bool:
print("Hello, World!")
return True


@task(TaskSpec(
name="hello_world",
type=TaskType.PYTHON,
description="This is a test task",
dependencies="This is a test task",
metadata={
"author": "Yuvraj Singh",
"version": "1.0.0",
},
base_image="python:3.12",
entrypoint="python",
args=[],
env={}
))
def hello_world_2(a : int, b : int) -> bool:
print("Hello, World!")
return True


@Workflow(WorkflowSpec(
name="hello_world",
description="This is a test workflow",
metadata={
"author": "Yuvraj Singh",
"version": "1.0.0",
},
))
def hello_world_workflow(a : int, b : int)-> bool:
return hello_world(a=a, b=b) or hello_world(a=a, b=b)


if __name__ == "__main__":
hello_world()
44 changes: 44 additions & 0 deletions idl/cloud/v1/cloud.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ package cloud.v1;

import "validate/validate.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";


// Enum for Task statuses
enum TaskStatusEnum {
Expand Down Expand Up @@ -99,8 +101,50 @@ message Task {
string description = 9 [(validate.rules).string = {
max_len: 5000
}];
repeated string dependencies = 10; // IDs of tasks that must complete before this task
string base_image = 11;
string entrypoint = 12;
repeated string args = 13;
map<string, string> env = 14;
}

// Workflow represents a collection of tasks organized in a DAG
message Workflow {
string id = 1;
string name = 2;
string description = 3;
repeated Task tasks = 4;
map<string, string> metadata = 5;
}

// ExecutionStatus represents the current state of a task or workflow execution
enum ExecutionStatus {
EXECUTION_STATUS_UNSPECIFIED = 0;
EXECUTION_STATUS_PENDING = 1;
EXECUTION_STATUS_RUNNING = 2;
EXECUTION_STATUS_COMPLETED = 3;
EXECUTION_STATUS_FAILED = 4;
}

// TaskExecution represents the execution of a task
message TaskExecution {
string task_id = 1;
ExecutionStatus status = 2;
google.protobuf.Timestamp created_at = 3;
google.protobuf.Timestamp updated_at = 4;
map<string, string> execution_metadata = 5;
}

// WorkflowExecution represents the execution of a workflow
message WorkflowExecution {
string workflow_id = 1;
ExecutionStatus status = 2;
repeated TaskExecution task_executions = 3;
google.protobuf.Timestamp created_at = 4;
google.protobuf.Timestamp updated_at = 5;
map<string, string> execution_metadata = 6;
}

// Message for Task history
message TaskHistory {
// Unique identifier for the history entry. Must be >= 0.
Expand Down
Empty file added modules/__init__.py
Empty file.
172 changes: 172 additions & 0 deletions modules/cloud/v1/cloud_pb2.py

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions modules/task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

from typing import TypedDict, List
from enum import Enum
from functools import wraps
from modules.cloud.v1.cloud_pb2 import Task

class TaskType(Enum):
PYTHON = "python"

class TaskMetadata(TypedDict):
author: str
version: str

class TaskSpec(TypedDict):
name: str
type: TaskType
description: str
dependencies: List[str]
metadata: TaskMetadata
base_image: str
entrypoint: str
86 changes: 86 additions & 0 deletions modules/validate/validate_pb2.py

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions modules/workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

from typing import TypedDict, List, Dict
from enum import Enum
from functools import wraps
from modules.cloud.v1.cloud_pb2 import Workflow

class WorkflowType(Enum):
PYTHON = "python"

class WorkflowMetadata(TypedDict):
author: str
version: str

class WorkflowSpec(TypedDict):
name: str
type: WorkflowType
description: str
dependencies: List[str]
metadata: WorkflowMetadata
base_image: str
entrypoint: str
args: List[str]
env: Dict[str, str]
Loading

0 comments on commit 1e7fd66

Please sign in to comment.