Skip to content

Commit

Permalink
Rework ParsedTool for reuse outside of the tool shed.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Jul 10, 2024
1 parent 309cf5a commit 96db4a8
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 57 deletions.
74 changes: 74 additions & 0 deletions lib/galaxy/tool_util/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""Define the ParsedTool model representing metadata extracted from a tool's source.
This is abstraction exported by newer tool shed APIS (circa 2024) and should be sufficient
for reasoning about tool state externally from Galaxy.
"""

from typing import (
List,
Optional,
)

from pydantic import BaseModel

from .parameters import (
input_models_for_tool_source,
ToolParameterT,
)
from .parser.interface import (
Citation,
ToolSource,
XrefDict,
)
from .parser.output_models import (
from_tool_source,
ToolOutput,
)


class ParsedTool(BaseModel):
id: str
version: Optional[str]
name: str
description: Optional[str]
inputs: List[ToolParameterT]
outputs: List[ToolOutput]
citations: List[Citation]
license: Optional[str]
profile: Optional[str]
edam_operations: List[str]
edam_topics: List[str]
xrefs: List[XrefDict]
help: Optional[str]


def parse_tool(tool_source: ToolSource) -> ParsedTool:
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).input_models
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 ParsedTool(
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,
)
61 changes: 4 additions & 57 deletions lib/tool_shed/managers/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
Tuple,
)

from pydantic import BaseModel

from galaxy import exceptions
from galaxy.exceptions import (
InternalServerError,
Expand All @@ -21,18 +19,14 @@
clone_repository,
get_changectx_for_changeset,
)
from galaxy.tool_util.parameters import (
input_models_for_tool_source,
ToolParameterT,
from galaxy.tool_util.models import (
parse_tool,
ParsedTool,
)
from galaxy.tool_util.parser import (
get_tool_source,
ToolSource,
)
from galaxy.tool_util.parser.interface import (
Citation,
XrefDict,
)
from galaxy.tools.stock import stock_tool_sources
from tool_shed.context import (
ProvidesRepositoriesContext,
Expand All @@ -46,53 +40,6 @@
STOCK_TOOL_SOURCES: Optional[Dict[str, Dict[str, ToolSource]]] = None


# parse the tool source with galaxy.util abstractions to provide a bit richer
# information about the tool than older tool shed abstractions.
class ParsedTool(BaseModel):
id: str
version: Optional[str]
name: str
description: Optional[str]
inputs: List[ToolParameterT]
citations: List[Citation]
license: Optional[str]
profile: Optional[str]
edam_operations: List[str]
edam_topics: List[str]
xrefs: List[XrefDict]
help: Optional[str]


def _parse_tool(tool_source: ToolSource) -> ParsedTool:
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).input_models
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 ParsedTool(
id=id,
version=version,
name=name,
description=description,
profile=profile,
inputs=inputs,
license=license,
citations=citations,
edam_operations=edam_operations,
edam_topics=edam_topics,
xrefs=xrefs,
help=help,
)


def search(trans: SessionRequestContext, q: str, page: int = 1, page_size: int = 10) -> dict:
"""
Perform the search over TS tools index.
Expand Down Expand Up @@ -165,7 +112,7 @@ def parsed_tool_model_for(
trans: ProvidesRepositoriesContext, trs_tool_id: str, tool_version: str, repository_clone_url: Optional[str] = None
) -> ParsedTool:
tool_source = tool_source_for(trans, trs_tool_id, tool_version, repository_clone_url=repository_clone_url)
return _parse_tool(tool_source)
return parse_tool(tool_source)


def tool_source_for(
Expand Down

0 comments on commit 96db4a8

Please sign in to comment.