From c0eb66173ea9d2fd0e24d69bd23705a67b2582df Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Tue, 31 Jan 2023 15:33:14 +0100 Subject: [PATCH 1/3] restore rst_invalid function used in planemo https://github.com/galaxyproject/planemo/pull/1275 has been removed here https://github.com/galaxyproject/galaxy/pull/14588 --- lib/galaxy/tool_util/linters/help.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/galaxy/tool_util/linters/help.py b/lib/galaxy/tool_util/linters/help.py index 1d5776a8c56..c47eb848cb7 100644 --- a/lib/galaxy/tool_util/linters/help.py +++ b/lib/galaxy/tool_util/linters/help.py @@ -30,10 +30,22 @@ def lint_help(tool_xml, lint_ctx): if "TODO" in help_text: lint_ctx.warn("Help contains TODO text.", node=helps[0]) - try: - rst_to_html(help_text, error=True) - except Exception as e: - lint_ctx.warn(f"Invalid reStructuredText found in help - [{unicodify(e)}].", node=helps[0]) - return + invalid_rst = rst_invalid(help_text) + if invalid_rst: + lint_ctx.warn(f"Invalid reStructuredText found in help - [{invalid_rst}].", node=helps[0]) + else: + lint_ctx.valid("Help contains valid reStructuredText.", node=helps[0]) - lint_ctx.valid("Help contains valid reStructuredText.", node=helps[0]) + +def rst_invalid(text): + """ + Predicate to determine if text is invalid reStructuredText. + Return False if the supplied text is valid reStructuredText or + a string indicating the problem. + """ + invalid_rst = False + try: + rst_to_html(text, error=True) + except Exception as e: + invalid_rst = unicodify(e) + return invalid_rst From 8b8e0431e925bf18a4c94baf4f5f6a4abb167ffc Mon Sep 17 00:00:00 2001 From: M Bernt Date: Tue, 31 Jan 2023 15:49:45 +0100 Subject: [PATCH 2/3] Add type annotation Co-authored-by: Marius van den Beek --- lib/galaxy/tool_util/linters/help.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/galaxy/tool_util/linters/help.py b/lib/galaxy/tool_util/linters/help.py index c47eb848cb7..62c25f168f2 100644 --- a/lib/galaxy/tool_util/linters/help.py +++ b/lib/galaxy/tool_util/linters/help.py @@ -43,7 +43,7 @@ def rst_invalid(text): Return False if the supplied text is valid reStructuredText or a string indicating the problem. """ - invalid_rst = False + invalid_rst: Union[bool, str] = False try: rst_to_html(text, error=True) except Exception as e: From e0ab580e5f6b5abd0876293391e5f82641daf878 Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Tue, 31 Jan 2023 16:00:25 +0100 Subject: [PATCH 3/3] add Union import and type annotate function --- lib/galaxy/tool_util/linters/help.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/galaxy/tool_util/linters/help.py b/lib/galaxy/tool_util/linters/help.py index 62c25f168f2..0008d465662 100644 --- a/lib/galaxy/tool_util/linters/help.py +++ b/lib/galaxy/tool_util/linters/help.py @@ -1,4 +1,7 @@ """This module contains a linting function for a tool's help.""" + +from typing import Union + from galaxy.util import ( rst_to_html, unicodify, @@ -37,7 +40,7 @@ def lint_help(tool_xml, lint_ctx): lint_ctx.valid("Help contains valid reStructuredText.", node=helps[0]) -def rst_invalid(text): +def rst_invalid(text: str) -> Union[bool, str]: """ Predicate to determine if text is invalid reStructuredText. Return False if the supplied text is valid reStructuredText or