Skip to content

Commit

Permalink
Merge pull request #1313 from mvdbeek/autoupdate_fix
Browse files Browse the repository at this point in the history
Compare versions, not tool ids to find latest tool ids
  • Loading branch information
mvdbeek committed Nov 2, 2022
2 parents c647b58 + 6a56d97 commit 96615ce
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
30 changes: 20 additions & 10 deletions planemo/autoupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,13 @@ def _update_wf(config: "LocalGalaxyConfig", workflow_id: str, instance: bool = F
config.user_gi.workflows.refactor_workflow(wf["id"], actions=[{"action_type": "upgrade_all_steps"}])


def get_newest_tool_id(tool_ids: List[str]) -> str:
return sorted(
tool_ids,
key=lambda n: packaging.version.parse(n.split("/")[-1]),
)[-1]


def outdated_tools(
ctx: "PlanemoCliContext", wf_dict: Dict[str, Any], ts: ToolShedInstance
) -> Dict[str, Dict[str, str]]:
Expand All @@ -295,16 +302,19 @@ def check_tool_step(step, ts): # return a dict with current and newest tool ver
ctx.log(warning_msg)
if len(repos) == 0:
return repos
base_id = "/".join(step["tool_id"].split("/")[:-1])
tool_ids_found = {
tool["guid"] for repo in repos.values() if type(repo) == dict for tool in repo.get("tools", [])
}
updated_tool_id = sorted(
{tool_id for tool_id in tool_ids_found if f"{base_id}/" in tool_id},
key=lambda n: packaging.version.parse(n),
)[-1]
if step["tool_id"] != updated_tool_id:
return {base_id: {"current": step["tool_id"], "updated": updated_tool_id}}
tool_id = step["tool_id"]
base_id = "/".join(tool_id.split("/")[:-1])
matching_tool_ids = []
for repo in repos.values():
if isinstance(repo, dict):
for tool in repo.get("tools") or []:
if tool["guid"].startswith(base_id):
matching_tool_ids.append(tool["guid"])
# there can only be one matching tool id in a repo
break
updated_tool_id = get_newest_tool_id(matching_tool_ids)
if tool_id != updated_tool_id:
return {base_id: {"current": tool_id, "updated": updated_tool_id}}
else:
return {}

Expand Down
9 changes: 9 additions & 0 deletions tests/test_autoupdate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from planemo.autoupdate import get_newest_tool_id


def test_get_newest_tool_id():
tool_ids = [
"toolshed.g2.bx.psu.edu/repos/iuc/rgrnastar/rna_star/2.7.8a+galaxy0",
"toolshed.g2.bx.psu.edu/repos/iuc/rgrnastar/rna_star/2.7.8a",
]
assert get_newest_tool_id(tool_ids) == tool_ids[0]

0 comments on commit 96615ce

Please sign in to comment.