Skip to content

Commit

Permalink
Add a few annotations to test out schema info rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdbeek committed Jan 31, 2025
1 parent 7d53fba commit a0c1e15
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
9 changes: 8 additions & 1 deletion lib/galaxy/tool_util/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,14 @@ class UserToolSource(BaseModel):
description: Optional[str] = None
container: str
requirements: Optional[List[Union[JavascriptRequirement, ResourceRequirement, ContainerRequirement]]] = []
shell_command: str
shell_command: Annotated[
str,
Field(
title="shell_command",
description="A string that contains the command to be executed. Parameters can be referenced inside $().",
examples=["head -n '$(inputs.n_lines)' '$(inputs.data_input.path)'"],
),
]
inputs: List[GalaxyToolParameterModel] = []
outputs: List[IncomingToolOutput] = []
citations: Optional[List[Citation]] = None
Expand Down
27 changes: 25 additions & 2 deletions lib/galaxy/tool_util/parser/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from enum import Enum
from os.path import join
from typing import (
Annotated,
Any,
cast,
Dict,
Expand All @@ -19,7 +20,10 @@
)

import packaging.version
from pydantic import BaseModel
from pydantic import (
BaseModel,
Field,
)
from typing_extensions import (
Literal,
NotRequired,
Expand Down Expand Up @@ -90,7 +94,26 @@ class ResourceRequirement(BaseModel):

class JavascriptRequirement(BaseModel):
type: Literal["javascript"]
expression_lib: Optional[List[str]]
expression_lib: Optional[
List[
Annotated[
str,
Field(
title="expression_lib",
description="Provide Javascript/ECMAScript 5.1 code here that will be available for expressions inside the `shell_command` field.",
examples=[
r"""function pickValue() {
if (inputs.conditional_parameter.test_parameter == "a") {
return inputs.conditional_parameter.integer_parameter
} else {
return inputs.conditional_parameter.boolean_parameter
}
}"""
],
),
]
]
]


class AssertionDict(TypedDict):
Expand Down
18 changes: 14 additions & 4 deletions lib/galaxy/tool_util/parser/output_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@


class ToolOutputBaseModelG(BaseModel, Generic[IncomingNotRequiredBoolT, IncomingNotRequiredStringT]):
name: IncomingNotRequiredStringT
label: Optional[str] = None
name: Annotated[
IncomingNotRequiredStringT, Field(description="Parameter name. Used when referencing parameter in workflows.")
]
label: Optional[Annotated[str, Field(description="Output label. Will be used as dataset name in history.")]] = None
hidden: IncomingNotRequiredBoolT


Expand All @@ -49,11 +51,19 @@ class ToolOutputDatasetG(
Generic[IncomingNotRequiredBoolT, IncomingNotRequiredStringT],
):
type: Literal["data"]
format: IncomingNotRequiredStringT
format: Annotated[IncomingNotRequiredStringT, Field(description="The short name for the output datatype.")]
format_source: Optional[str] = None
metadata_source: Optional[str] = None
discover_datasets: Optional[List["DatasetCollectionDescriptionT"]] = None
from_work_dir: Optional[str] = None
from_work_dir: Optional[
Annotated[
str,
Field(
title="from_work_dir",
description="Relative path to a file produced by the tool in its working directory. Output’s contents are set to this file’s contents.",
),
]
] = None


ToolOutputDataset = ToolOutputDatasetG[bool, str]
Expand Down

0 comments on commit a0c1e15

Please sign in to comment.