Skip to content

Commit

Permalink
Fix tool lint check for correct tool version
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdbeek committed Apr 11, 2024
1 parent 61c315a commit 968a6b8
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions planemo/workflow_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,15 +493,27 @@ def find_repos_from_tool_id(tool_id: str, ts: ToolShedInstance) -> Tuple[str, Di
return ("", repos)


def assert_valid_tool_id_in_tool_shed(tool_id, ts: ToolShedInstance) -> Optional[str]:
warning_msg, repos = find_repos_from_tool_id(tool_id, ts)
if warning_msg:
return warning_msg
for repo in repos.values():
tools = repo.get("tools", [])
for tool in tools:
if tool_id == tool.get("guid"):
return None
return f"The tool {tool_id} is not in the toolshed (may have been tagged as invalid)."


def _lint_tool_ids(path: str, lint_context: WorkflowLintContext) -> None:
def _lint_tool_ids_steps(lint_context: WorkflowLintContext, wf_dict: Dict, ts: ToolShedInstance) -> bool:
"""Returns whether a single tool_id was invalid"""
failed = False
steps = wf_dict.get("steps", {})
for step in steps.values():
if step.get("type", "tool") == "tool" and not step.get("run", {}).get("class") == "GalaxyWorkflow":
warning_msg, _ = find_repos_from_tool_id(step["tool_id"], ts)
if warning_msg != "":
warning_msg = assert_valid_tool_id_in_tool_shed(step["tool_id"], ts)
if warning_msg:
lint_context.error(warning_msg)
failed = True
elif step.get("type") == "subworkflow": # GA SWF
Expand All @@ -521,5 +533,5 @@ def _lint_tool_ids_steps(lint_context: WorkflowLintContext, wf_dict: Dict, ts: T
ts = toolshed.ToolShedInstance(url=MAIN_TOOLSHED_URL)
failed = _lint_tool_ids_steps(lint_context, workflow_dict, ts)
if not failed:
lint_context.valid("All tools_id appear to be valid.")
lint_context.valid("All tool ids appear to be valid.")
return None

0 comments on commit 968a6b8

Please sign in to comment.