forked from galaxyproject/galaxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New packages galaxy-tool-util-models, galaxy-tool-shed-schema.
The galaxy-tool-shed-schema package is basically pydantic models for the whole tool shed API. It is used by both the backend code for the new tool shed and the testing code that runs on both the old and new tool shed. The creation of galaxy-tool-util-models package is something I've wanted to do for a while - it should solve some TODOs I've left in the base. I think beyond enabling galaxy-tool-shed-schema package - the other nice thing is that galaxy-schema code can now rely on various tool stuff without requiring dependency on any of the parser or runtime code. This should also fix things for the new record types in galaxyproject#19377. I've introduced a type that can be used tools and is included schema for collection creation. The galaxy-tool-util-models packages can now be dependended on by galaxy-schema and galaxy-tool-util and these two packages do not need to depend on each other - either direction of that dependency would make me uncomfortable. xref https://github.com/galaxyproject/galaxy/actions/runs/13704893929/job/38327692654?pr=19377
- Loading branch information
Showing
63 changed files
with
1,051 additions
and
754 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,51 @@ | ||
|
||
from typing import ( | ||
Type, | ||
TypeVar, | ||
) | ||
|
||
from galaxy.tool_util_models import ParsedTool | ||
from .parameters import input_models_for_tool_source | ||
from .parser.interface import ( | ||
ToolSource, | ||
) | ||
from .parser.output_objects import from_tool_source | ||
|
||
|
||
def parse_tool(tool_source: ToolSource) -> ParsedTool: | ||
return parse_tool_custom(tool_source, ParsedTool) | ||
|
||
|
||
P = TypeVar("P", bound=ParsedTool) | ||
|
||
|
||
def parse_tool_custom(tool_source: ToolSource, model_type: Type[P]) -> P: | ||
id = tool_source.parse_id() | ||
version = tool_source.parse_version() | ||
name = tool_source.parse_name() | ||
description = tool_source.parse_description() | ||
inputs = input_models_for_tool_source(tool_source).parameters | ||
outputs = from_tool_source(tool_source) | ||
citations = tool_source.parse_citations() | ||
license = tool_source.parse_license() | ||
profile = tool_source.parse_profile() | ||
edam_operations = tool_source.parse_edam_operations() | ||
edam_topics = tool_source.parse_edam_topics() | ||
xrefs = tool_source.parse_xrefs() | ||
help = tool_source.parse_help() | ||
|
||
return model_type( | ||
id=id, | ||
version=version, | ||
name=name, | ||
description=description, | ||
profile=profile, | ||
inputs=inputs, | ||
outputs=outputs, | ||
license=license, | ||
citations=citations, | ||
edam_operations=edam_operations, | ||
edam_topics=edam_topics, | ||
xrefs=xrefs, | ||
help=help, | ||
) |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,57 @@ | ||
from typing import ( | ||
Any, | ||
Dict, | ||
Optional, | ||
Type, | ||
) | ||
|
||
from pydantic import ( | ||
BaseModel, | ||
ValidationError, | ||
) | ||
from typing_extensions import ( | ||
Protocol, | ||
) | ||
|
||
from galaxy.exceptions import RequestParameterInvalidException | ||
from galaxy.tool_util_models.parameters import ( | ||
DEFAULT_MODEL_NAME, | ||
create_field_model, | ||
ToolParameterBundle, | ||
RawStateDict, | ||
StateRepresentationT, | ||
) | ||
|
||
def validate_against_model(pydantic_model: Type[BaseModel], parameter_state: Dict[str, Any]) -> None: | ||
try: | ||
pydantic_model(**parameter_state) | ||
except ValidationError as e: | ||
# TODO: Improve this or maybe add a handler for this in the FastAPI exception | ||
# handler. | ||
raise RequestParameterInvalidException(str(e)) | ||
|
||
|
||
class ValidationFunctionT(Protocol): | ||
|
||
def __call__(self, tool: ToolParameterBundle, request: RawStateDict, name: Optional[str] = None) -> None: ... | ||
|
||
|
||
def validate_model_type_factory(state_representation: StateRepresentationT) -> ValidationFunctionT: | ||
|
||
def validate_request(tool: ToolParameterBundle, request: Dict[str, Any], name: Optional[str] = None) -> None: | ||
name = name or DEFAULT_MODEL_NAME | ||
pydantic_model = create_field_model(tool.parameters, name=name, state_representation=state_representation) | ||
validate_against_model(pydantic_model, request) | ||
|
||
return validate_request | ||
|
||
|
||
validate_request = validate_model_type_factory("request") | ||
validate_internal_request = validate_model_type_factory("request_internal") | ||
validate_internal_request_dereferenced = validate_model_type_factory("request_internal_dereferenced") | ||
validate_landing_request = validate_model_type_factory("landing_request") | ||
validate_internal_landing_request = validate_model_type_factory("landing_request_internal") | ||
validate_internal_job = validate_model_type_factory("job_internal") | ||
validate_test_case = validate_model_type_factory("test_case_xml") | ||
validate_workflow_step = validate_model_type_factory("workflow_step") | ||
validate_workflow_step_linked = validate_model_type_factory("workflow_step_linked") |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.