Skip to content

Commit 48e4d11

Browse files
committed
Fix autoupdate.py type errors
1 parent 86abc5b commit 48e4d11

1 file changed

Lines changed: 20 additions & 15 deletions

File tree

planemo/autoupdate.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
TYPE_CHECKING,
1616
Union,
1717
)
18-
from xml.etree.ElementTree import ElementTree
18+
from xml.etree.ElementTree import (
19+
Element,
20+
ElementTree,
21+
)
1922

2023
import requests
2124
import yaml
@@ -64,7 +67,7 @@ def bump_version(version_str: str) -> str:
6467
return ".".join(map(str, base_version))
6568

6669

67-
def find_macros(xml_tree: ElementTree) -> List[Any]:
70+
def find_macros(xml_tree: ElementTree[Element[str]]) -> List[Any]:
6871
"""
6972
Get macros from the XML tree
7073
"""
@@ -74,7 +77,7 @@ def find_macros(xml_tree: ElementTree) -> List[Any]:
7477
return macros
7578

7679

77-
def get_requirements(xml_tree: ElementTree) -> Tuple[Dict[str, Dict[str, Optional[str]]], Optional[str]]:
80+
def get_requirements(xml_tree: ElementTree[Element[str]]) -> Tuple[Dict[str, Dict[str, Optional[str]]], Optional[str]]:
7881
"""
7982
Get requirements from the XML tree
8083
"""
@@ -92,7 +95,7 @@ def get_requirements(xml_tree: ElementTree) -> Tuple[Dict[str, Dict[str, Optiona
9295
return requirements, main_req
9396

9497

95-
def get_tokens(xml_tree: ElementTree) -> Dict[str, Dict[str, Optional[str]]]:
98+
def get_tokens(xml_tree: ElementTree[Element[str]]) -> Dict[str, Dict[str, Optional[str]]]:
9699
"""
97100
Get tokens from the XML tree
98101
"""
@@ -124,7 +127,7 @@ def check_conda(package_name: str, ctx: "PlanemoCliContext", **kwds) -> str:
124127

125128
def update_xml(
126129
tool_path: str,
127-
xml_tree: ElementTree,
130+
xml_tree: ElementTree[Element[str]],
128131
tags_to_update: List[Dict[str, str]],
129132
wrapper_version_token: Optional[Union[int, str]],
130133
is_macro: bool = False,
@@ -162,7 +165,7 @@ def update_requirement(xml_text, tag, requirement_value):
162165

163166

164167
def create_requirement_dict(
165-
xml_files: Dict[str, ElementTree], skip_reqs: List[str]
168+
xml_files: Dict[str, ElementTree[Element[str]]], skip_reqs: List[str]
166169
) -> Tuple[Dict[str, Dict[str, Dict[str, Optional[str]]]], Optional[Tuple[str, str]]]:
167170
"""
168171
Create dict with requirements and find main requirement
@@ -182,7 +185,7 @@ def create_requirement_dict(
182185

183186

184187
def create_token_dict(
185-
ctx: "PlanemoCliContext", xml_files: Dict[str, ElementTree], main_req: Tuple[str, str], **kwds
188+
ctx: "PlanemoCliContext", xml_files: Dict[str, ElementTree[Element[str]]], main_req: Tuple[str, str], **kwds
186189
) -> Tuple[
187190
Dict[str, Dict[str, Dict[str, Optional[str]]]], DefaultDict[str, List[Dict[str, str]]], Optional[str], Optional[str]
188191
]:
@@ -208,7 +211,7 @@ def create_token_dict(
208211

209212
def perform_required_update(
210213
ctx: "PlanemoCliContext",
211-
xml_files: Dict[str, ElementTree],
214+
xml_files: Dict[str, ElementTree[Element[str]]],
212215
tool_path: str,
213216
requirements: Dict[str, Dict[str, Dict[str, Optional[str]]]],
214217
tokens: Dict[str, Dict[str, Dict[str, Optional[str]]]],
@@ -253,9 +256,9 @@ def autoupdate_tool(ctx: "PlanemoCliContext", tool_path: str, modified_files: Se
253256
xml_files = {tool_path: ET.parse(tool_path)}
254257

255258
# get name of token which defines the wrapper version; if just an integer, None
256-
versions = xml_files[tool_path].getroot().attrib.get("version")
257-
if versions:
258-
versions = versions.split("+galaxy")
259+
version_str = xml_files[tool_path].getroot().attrib.get("version")
260+
if version_str:
261+
versions = version_str.split("+galaxy")
259262
if versions[0] != "@TOOL_VERSION@":
260263
error("Tool version does not contain @TOOL_VERSION@ as required by autoupdate.")
261264
return None
@@ -265,14 +268,16 @@ def autoupdate_tool(ctx: "PlanemoCliContext", tool_path: str, modified_files: Se
265268
if versions[1][0] == versions[1][-1] == "@":
266269
wrapper_version_token = versions[1]
267270
else:
268-
wrapper_version_token = 0 # assume an int, reset to 0
271+
wrapper_version_token = "0" # assume an int, reset to 0
269272
else:
270273
wrapper_version_token = None
271274

272275
# add macros to xml_files
273-
for macro in find_macros(xml_files[tool_path]):
274-
macro_path = "/".join(tool_path.split("/")[:-1] + [macro])
275-
xml_files[macro_path] = ET.parse(macro_path)
276+
macro_paths = xml_files[tool_path]
277+
if macro_paths:
278+
for macro in find_macros(macro_paths):
279+
macro_path = "/".join(tool_path.split("/")[:-1] + [macro])
280+
xml_files[macro_path] = ET.parse(macro_path)
276281

277282
requirements, main_req = create_requirement_dict(xml_files, kwds.get("skip_requirements", "").split(","))
278283
if main_req is None:

0 commit comments

Comments
 (0)