Fix new UP031 errors from ruff 0.4.2

This commit is contained in:
Nicola Soranzo
2024-04-29 00:09:38 +01:00
parent 0e89124a13
commit 0629908541
127 changed files with 381 additions and 425 deletions
+14 -18
View File
@@ -34,7 +34,7 @@ def main():
class Tag:
def __init__(self, line):
def __init__(self, line: str):
assert line.startswith("$tag:")
line_parts = line.split(" ")
first_part = line_parts[0]
@@ -52,12 +52,12 @@ class Tag:
@property
def _pretty_title(self):
return " > ".join("``%s``" % p for p in self.title.split("|"))
return " > ".join(f"``{p}``" for p in self.title.split("|"))
def build_help(self):
tag = xmlschema_doc.find(self.xpath)
if tag is None:
raise Exception("Could not find xpath for %s" % self.xpath)
raise Exception(f"Could not find xpath for {self.xpath}")
tag_help = StringIO()
tag_help.write("## " + self._pretty_title)
@@ -98,7 +98,7 @@ def _build_tag(tag, hide_attributes):
doc = _doc_or_none(element)
if doc is None:
doc = _doc_or_none(_type_el(element))
assert doc is not None, "Documentation for %s is empty" % element.attrib["name"]
assert doc is not None, f"Documentation for {element.attrib['name']} is empty"
doc = doc.strip()
element_el = _find_tag_el(element)
@@ -110,10 +110,9 @@ def _build_tag(tag, hide_attributes):
if best_practices := _get_bp_link(annotation_el):
tag_help.write("\n\n### Best Practices\n")
tag_help.write(
"""
Find the Intergalactic Utilities Commision suggested best practices for this
element [here](%s)."""
% best_practices
f"""
Find the Intergalactic Utilities Commission suggested best practices for this
element [here]({best_practices})."""
)
tag_help.write(_build_attributes_table(tag, attributes, hide_attributes))
@@ -140,7 +139,7 @@ def _get_bp_link(annotation_el):
anchor = annotation_el.attrib.get("{http://galaxyproject.org/xml/1.0}best_practices", None)
link = None
if anchor:
link = "https://galaxy-iuc-standards.readthedocs.io/en/latest/best_practices/tool_xml.html#%s" % anchor
link = f"https://galaxy-iuc-standards.readthedocs.io/en/latest/best_practices/tool_xml.html#{anchor}"
return link
@@ -149,7 +148,7 @@ def _build_attributes_table(tag, attributes, hide_attributes=False, attribute_na
attribute_table.write("\n\n")
if attributes and not hide_attributes:
header_prefix = "#" * header_level
attribute_table.write("\n%s Attributes\n\n" % header_prefix)
attribute_table.write(f"\n{header_prefix} Attributes\n\n")
attribute_table.write("Attribute | Details | Required\n")
attribute_table.write("--- | --- | ---\n")
for attribute in attributes:
@@ -159,7 +158,7 @@ def _build_attributes_table(tag, attributes, hide_attributes=False, attribute_na
details = _doc_or_none(attribute)
if details is None:
type_el = _type_el(attribute)
assert type_el is not None, "No details or type found for %s" % name
assert type_el is not None, f"No details or type found for {name}"
details = _doc_or_none(type_el)
annotation_el = type_el.find("{http://www.w3.org/2001/XMLSchema}annotation")
else:
@@ -170,10 +169,7 @@ def _build_attributes_table(tag, attributes, hide_attributes=False, attribute_na
details = details.replace("|", "\\|").strip()
best_practices = _get_bp_link(annotation_el)
if best_practices:
details += (
""" Find the Intergalactic Utilities Commision suggested best practices for this element [here](%s)."""
% best_practices
)
details += f""" Find the Intergalactic Utilities Commission suggested best practices for this element [here]({best_practices})."""
attribute_table.write(f"``{name}`` | {details} | {use}\n")
return attribute_table.getvalue()
@@ -204,7 +200,7 @@ def _find_attributes(tag):
for attribute_group in attribute_groups:
attribute_group_name = attribute_group.get("ref")
attribute_group_def = xmlschema_doc.find(
"//{http://www.w3.org/2001/XMLSchema}attributeGroup/[@name='%s']" % attribute_group_name
f"//{{http://www.w3.org/2001/XMLSchema}}attributeGroup/[@name='{attribute_group_name}']"
)
attributes.extend(_find_attributes(attribute_group_def))
return attributes
@@ -219,9 +215,9 @@ def _find_tag_el(tag):
def _type_el(tag):
element_type = tag.attrib["type"]
type_el = xmlschema_doc.find("//{http://www.w3.org/2001/XMLSchema}complexType/[@name='%s']" % element_type)
type_el = xmlschema_doc.find(f"//{{http://www.w3.org/2001/XMLSchema}}complexType/[@name='{element_type}']")
if type_el is None:
type_el = xmlschema_doc.find("//{http://www.w3.org/2001/XMLSchema}simpleType/[@name='%s']" % element_type)
type_el = xmlschema_doc.find(f"//{{http://www.w3.org/2001/XMLSchema}}simpleType/[@name='{element_type}']")
return type_el