Skip to content

Commit

Permalink
Replace to_unicode with unicodify
Browse files Browse the repository at this point in the history
Co-authored-by: Nicola Soranzo <[email protected]>
  • Loading branch information
davelopez and nsoranzo committed Nov 21, 2023
1 parent 012da97 commit 3316d84
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions lib/galaxy/tools/search/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@
CanConvertToInt = Union[str, int, float]


def to_unicode(a_string):
"""
Convert a string to unicode in utf-8 format; if string is already unicode,
does nothing because string's encoding cannot be determined by introspection.
"""
return unicodify(a_string, "utf-8")


def get_or_create_index(index_dir, schema):
"""Get or create a reference to the index."""
if not os.path.exists(index_dir):
Expand Down Expand Up @@ -289,39 +281,39 @@ def _create_doc(
def clean(string):
"""Remove hyphens as they are Whoosh wildcards."""
if "-" in string:
return (" ").join(token.text for token in self.rex(to_unicode(tool.name)))
return (" ").join(token.text for token in self.rex(unicodify(tool.name)))
else:
return string

if tool.tool_type == "manage_data":
# Do not add data managers to the public index
return {}
add_doc_kwds = {
"id": to_unicode(tool.id),
"id_exact": to_unicode(tool.id),
"id": unicodify(tool.id),
"id_exact": unicodify(tool.id),
"name": clean(tool.name),
"description": to_unicode(tool.description),
"section": to_unicode(tool.get_panel_section()[1] if len(tool.get_panel_section()) == 2 else ""),
"description": unicodify(tool.description),
"section": unicodify(tool.get_panel_section()[1] if len(tool.get_panel_section()) == 2 else ""),
"edam_operations": clean(tool.edam_operations),
"edam_topics": clean(tool.edam_topics),
"repository": to_unicode(tool.repository_name),
"owner": to_unicode(tool.repository_owner),
"help": to_unicode(""),
"repository": unicodify(tool.repository_name),
"owner": unicodify(tool.repository_owner),
"help": unicodify(""),
}
if tool.guid:
# Create a stub consisting of owner, repo, and tool from guid
slash_indexes = [m.start() for m in re.finditer("/", tool.guid)]
id_stub = tool.guid[(slash_indexes[1] + 1) : slash_indexes[4]]
add_doc_kwds["stub"] = clean(id_stub)
else:
add_doc_kwds["stub"] = to_unicode(id)
add_doc_kwds["stub"] = unicodify(id)
if tool.labels:
add_doc_kwds["labels"] = to_unicode(" ".join(tool.labels))
add_doc_kwds["labels"] = unicodify(" ".join(tool.labels))
if index_help:
raw_help = tool.raw_help
if raw_help:
try:
add_doc_kwds["help"] = to_unicode(raw_help)
add_doc_kwds["help"] = unicodify(raw_help)
except Exception:
# Don't fail to build index when help fails to parse
pass
Expand Down

0 comments on commit 3316d84

Please sign in to comment.