Skip to content

Commit

Permalink
add comment pydantic schema
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectronicBlueberry committed Oct 25, 2023
1 parent 9453be3 commit c14a139
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/galaxy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
)
from galaxy.util.json import safe_loads
from galaxy.util.sanitize_html import sanitize_html
from lib.galaxy.schema.workflow.comments import WorkflowCommentModel

if TYPE_CHECKING:
from galaxy.schema.invocation import InvocationMessageUnion
Expand Down Expand Up @@ -8031,9 +8032,13 @@ def to_dict(self):
if self.child_comments:
comment_dict["child_comments"] = [comment.order_index for comment in self.child_comments]

WorkflowCommentModel(__root__=comment_dict)

return comment_dict

def from_dict(dict):
WorkflowCommentModel(__root__=dict)

comment = WorkflowComment()
comment.order_index = dict.get("id", 0)
comment.type = dict.get("type", "text")
Expand Down
62 changes: 62 additions & 0 deletions lib/galaxy/schema/workflow/comments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from typing import (
List,
Literal,
Optional,
Tuple,
Union,
)

from pydantic import BaseModel


class BaseComment(BaseModel):
id: int
colour: Literal["none", "black", "blue" "turquoise", "green", "lime", "orange", "yellow", "red", "pink"]
position: Tuple[float, float]
size: Tuple[float, float]


class TextCommentData(BaseModel):
bold: Optional[bool]
italic: Optional[bool]
size: int
text: str


class TextComment(BaseComment):
type: Literal["text"]
data: TextCommentData


class MarkdownCommentData(BaseModel):
text: str


class MarkdownComment(BaseComment):
type: Literal["markdown"]
data: MarkdownCommentData


class FrameCommentData(BaseModel):
title: str


class FrameComment(BaseComment):
type: Literal["frame"]
data: FrameCommentData
child_comments: Optional[List[int]]
child_steps: Optional[List[int]]


class FreehandCommentData(BaseModel):
thickness: int
line: List[Tuple[float, float]]


class FreehandComment(BaseComment):
type: Literal["freehand"]
data: FreehandCommentData


class WorkflowCommentModel(BaseModel):
__root__: Union[TextComment, MarkdownComment, FrameComment, FreehandComment]

0 comments on commit c14a139

Please sign in to comment.