From 986b752c137605985c3ccc3544cb1b3da8cf51f0 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Mon, 10 Feb 2020 16:51:46 +0100 Subject: [PATCH 1/3] If xml can't be read don't consider it a tool xml file Fixes ``` File "..\planemo\venv\lib\site-packages\galaxy\tool_util\loader_directory.py", line 174, in looks_like_xml start_contents = f.read(5 * 1024) File "..\planemo\venv\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 1713: character maps to ``` Still weird that this is cp1252 though. --- lib/galaxy/tool_util/loader_directory.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/galaxy/tool_util/loader_directory.py b/lib/galaxy/tool_util/loader_directory.py index c21937987b7..279c0c1e927 100644 --- a/lib/galaxy/tool_util/loader_directory.py +++ b/lib/galaxy/tool_util/loader_directory.py @@ -171,7 +171,10 @@ def looks_like_xml(path, regex=TOOL_REGEX): return False with open(path, "r") as f: - start_contents = f.read(5 * 1024) + try: + start_contents = f.read(5 * 1024) + except UnicodeDecodeError: + return False if regex.search(start_contents): return True From c1261948c2a4fe0600fde19882ac0297dd8ee857 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Mon, 10 Feb 2020 17:15:06 +0100 Subject: [PATCH 2/3] Fix linting error on python 3 if no version is defined Fixes ``` Traceback (most recent call last): File "/Users/mvandenb/.pyenv/versions/3.6.9/bin/planemo", line 11, in load_entry_point('planemo', 'console_scripts', 'planemo')() File "/Users/mvandenb/.pyenv/versions/3.6.9/lib/python3.6/site-packages/click/core.py", line 764, in __call__ return self.main(*args, **kwargs) File "/Users/mvandenb/.pyenv/versions/3.6.9/lib/python3.6/site-packages/click/core.py", line 717, in main rv = self.invoke(ctx) File "/Users/mvandenb/.pyenv/versions/3.6.9/lib/python3.6/site-packages/click/core.py", line 1137, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/Users/mvandenb/.pyenv/versions/3.6.9/lib/python3.6/site-packages/click/core.py", line 956, in invoke return ctx.invoke(self.callback, **ctx.params) File "/Users/mvandenb/.pyenv/versions/3.6.9/lib/python3.6/site-packages/click/core.py", line 555, in invoke return callback(*args, **kwargs) File "/Users/mvandenb/.pyenv/versions/3.6.9/lib/python3.6/site-packages/click/decorators.py", line 64, in new_func return ctx.invoke(f, obj, *args, **kwargs) File "/Users/mvandenb/.pyenv/versions/3.6.9/lib/python3.6/site-packages/click/core.py", line 555, in invoke return callback(*args, **kwargs) File "/Users/mvandenb/src/planemo/planemo/cli.py", line 190, in handle_blended_options return f(*args, **kwds) File "/Users/mvandenb/src/planemo/planemo/commands/cmd_lint.py", line 58, in cli recursive=kwds["recursive"] File "/Users/mvandenb/src/planemo/planemo/tool_lint.py", line 33, in lint_tools_on_path if not lint_tool_source(tool_xml, name=basename(tool_path), **lint_args): File "/Users/mvandenb/.pyenv/versions/3.6.9/lib/python3.6/site-packages/galaxy/tool_util/lint.py", line 18, in lint_tool_source lint_tool_source_with(lint_context, tool_source, extra_modules) File "/Users/mvandenb/.pyenv/versions/3.6.9/lib/python3.6/site-packages/galaxy/tool_util/lint.py", line 54, in lint_tool_source_with lint_context.lint(name, value, tool_source) File "/Users/mvandenb/.pyenv/versions/3.6.9/lib/python3.6/site-packages/galaxy/tool_util/lint.py", line 83, in lint lint_func(lint_target, self) File "/Users/mvandenb/.pyenv/versions/3.6.9/lib/python3.6/site-packages/galaxy/tool_util/linters/general.py", line 27, in lint_general parsed_version = packaging.version.parse(version) File "/Users/mvandenb/.pyenv/versions/3.6.9/lib/python3.6/site-packages/packaging/version.py", line 28, in parse return Version(version) File "/Users/mvandenb/.pyenv/versions/3.6.9/lib/python3.6/site-packages/packaging/version.py", line 219, in __init__ match = self._regex.search(version) TypeError: expected string or bytes-like object ``` --- lib/galaxy/tool_util/linters/general.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/galaxy/tool_util/linters/general.py b/lib/galaxy/tool_util/linters/general.py index 0c45c06ab84..c2624daca81 100644 --- a/lib/galaxy/tool_util/linters/general.py +++ b/lib/galaxy/tool_util/linters/general.py @@ -23,7 +23,7 @@ lint_tool_types = ["*"] def lint_general(tool_source, lint_ctx): """Check tool version, name, and id.""" - version = tool_source.parse_version() + version = tool_source.parse_version() or '' parsed_version = packaging.version.parse(version) if not version: lint_ctx.error(ERROR_VERSION_MSG) From a93fe361778c69e5caf33522797593959df2ae1a Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Mon, 10 Feb 2020 17:10:59 +0000 Subject: [PATCH 3/3] Use ``io.open()`` --- lib/galaxy/tool_util/loader_directory.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/galaxy/tool_util/loader_directory.py b/lib/galaxy/tool_util/loader_directory.py index 279c0c1e927..310ea7cba09 100644 --- a/lib/galaxy/tool_util/loader_directory.py +++ b/lib/galaxy/tool_util/loader_directory.py @@ -1,6 +1,7 @@ """Utilities for loading and reasoning about unparsed tools in directories.""" import fnmatch import glob +import io import logging import os import re @@ -170,7 +171,7 @@ def looks_like_xml(path, regex=TOOL_REGEX): checkers.is_zip(full_path)): return False - with open(path, "r") as f: + with io.open(path, "r", encoding='utf-8') as f: try: start_contents = f.read(5 * 1024) except UnicodeDecodeError: