diff --git a/planemo/commands/cmd_lint.py b/planemo/commands/cmd_lint.py index c84f8f0b9..85a3c77cc 100644 --- a/planemo/commands/cmd_lint.py +++ b/planemo/commands/cmd_lint.py @@ -15,8 +15,7 @@ @options.report_level_option() @options.report_xunit() @options.fail_level_option() -@options.skip_option() -@options.lint_xsd_option() +@options.skip_options() @options.recursive_option() @click.option( "--urls", diff --git a/planemo/commands/cmd_shed_lint.py b/planemo/commands/cmd_shed_lint.py index b25ea5988..80f420b31 100644 --- a/planemo/commands/cmd_shed_lint.py +++ b/planemo/commands/cmd_shed_lint.py @@ -14,11 +14,10 @@ @options.shed_realization_options() @options.report_level_option() @options.fail_level_option() -@options.skip_option() +@options.skip_options() @options.click.option( "--tools", is_flag=True, default=False, help=("Lint tools discovered in the process of linting repositories.") ) -@options.lint_xsd_option() @options.click.option( "--ensure_metadata", is_flag=True, diff --git a/planemo/lint.py b/planemo/lint.py index 25a0a9c7f..5b85022de 100644 --- a/planemo/lint.py +++ b/planemo/lint.py @@ -4,7 +4,10 @@ from urllib.request import urlopen import requests -from galaxy.tool_util.lint import LintContext +from galaxy.tool_util.lint import ( + LintContext, + Linter, +) from planemo.io import error from planemo.shed import find_urls_for_xml @@ -20,8 +23,21 @@ def build_lint_args(ctx, **kwds): skip = ctx.global_config.get("lint_skip", "") if isinstance(skip, list): skip = ",".join(skip) - skip_types = [s.strip() for s in skip.split(",")] + + for skip_file in kwds.get("skip_file", []): + with open(skip_file) as f: + for line in f.readlines(): + line = line.strip() + if not line or line.startswith("#"): + continue + skip_types.append(line) + + linters = Linter.list_listers() + invalid_skip_types = list(set(skip_types) - set(linters)) + if len(invalid_skip_types): + error(f"Unknown linter type(s) {invalid_skip_types} in list of linters to be skipped. Known linters {linters}") + lint_args = dict( level=report_level, fail_level=fail_level, diff --git a/planemo/options.py b/planemo/options.py index eb77fb303..71f15fc81 100644 --- a/planemo/options.py +++ b/planemo/options.py @@ -1375,12 +1375,6 @@ def shed_fail_fast_option(): ) -def lint_xsd_option(): - return planemo_option( - "--xsd/--no_xsd", is_flag=True, default=True, help=("Include tool XSD validation in linting process.") - ) - - def lint_biocontainers_option(): return planemo_option( "biocontainer", @@ -1409,6 +1403,13 @@ def report_xunit(): ) +def skip_options(): + return _compose( + skip_option(), + skip_file_option(), + ) + + def skip_option(): return planemo_option( "-s", @@ -1422,6 +1423,15 @@ def skip_option(): ) +def skip_file_option(): + return planemo_option( + "--skip_file", + type=click.Path(exists=True, file_okay=True, dir_okay=False, resolve_path=True), + multiple=True, + help=("File containing a list of lint tests to skip"), + ) + + def fail_level_option(): return planemo_option("--fail_level", type=click.Choice(["warn", "error"]), default="warn") diff --git a/planemo/tool_lint.py b/planemo/tool_lint.py index 5fce052fb..9e72d2646 100644 --- a/planemo/tool_lint.py +++ b/planemo/tool_lint.py @@ -51,8 +51,6 @@ def lint_tools_on_path(ctx, paths, lint_args, **kwds): def _lint_extra_modules(**kwds): linters = [] - if kwds.get("xsd", True): - linters.append(planemo.linters.xsd) if kwds.get("doi", False): linters.append(planemo.linters.doi) diff --git a/tests/data/lint_skip_list.txt b/tests/data/lint_skip_list.txt new file mode 100644 index 000000000..acfa09ee5 --- /dev/null +++ b/tests/data/lint_skip_list.txt @@ -0,0 +1,4 @@ +# check that comments work +xml_order +# check the white spaces are ignored + citations diff --git a/tests/test_lint.py b/tests/test_lint.py index dc8ec9aff..e5a63c823 100644 --- a/tests/test_lint.py +++ b/tests/test_lint.py @@ -5,6 +5,7 @@ CliTestCase, PROJECT_TEMPLATES_DIR, skip_if_environ, + TEST_DATA_DIR, TEST_REPOS_DIR, TEST_TOOLS_DIR, ) @@ -61,6 +62,11 @@ def test_skips(self): lint_cmd = ["lint", "--skip", "xml_order, citations", fail_citation] self._check_exit_code(lint_cmd, exit_code=0) + # Check skip_file (containing the same skips) + skip_file = os.path.join(TEST_DATA_DIR, "lint_skip_list.txt") + lint_cmd = ["lint", "--skip_file", skip_file, fail_citation] + self._check_exit_code(lint_cmd, exit_code=0) + def test_recursive(self): nested_dir = os.path.join(TEST_REPOS_DIR, "multi_repos_nested") diff --git a/tests/test_utils.py b/tests/test_utils.py index 17d8b4288..98362b41e 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -55,7 +55,6 @@ TEST_DIR = os.path.dirname(__file__) TEST_DATA_DIR = os.path.join(TEST_DIR, "data") TEST_AUTOPYGEN_DATA = os.path.join(TEST_DATA_DIR, "autopygen") -TEST_DATA_DIR = os.path.join(TEST_DIR, "data") TEST_REPOS_DIR = os.path.join(TEST_DATA_DIR, "repos") TEST_TOOLS_DIR = os.path.join(TEST_DATA_DIR, "tools") PROJECT_TEMPLATES_DIR = os.path.join(TEST_DIR, os.path.pardir, "project_templates")