Skip to content

Commit

Permalink
Merge pull request #1420 from bernt-matthias/linting-news
Browse files Browse the repository at this point in the history
Tool linting add `--skip_file` and remove lxml schema validation
  • Loading branch information
mvdbeek authored May 8, 2024
2 parents cd7a7a1 + cb9d50f commit cb2321b
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 15 deletions.
3 changes: 1 addition & 2 deletions planemo/commands/cmd_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions planemo/commands/cmd_shed_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 18 additions & 2 deletions planemo/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
22 changes: 16 additions & 6 deletions planemo/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -1409,6 +1403,13 @@ def report_xunit():
)


def skip_options():
return _compose(
skip_option(),
skip_file_option(),
)


def skip_option():
return planemo_option(
"-s",
Expand All @@ -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")

Expand Down
2 changes: 0 additions & 2 deletions planemo/tool_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions tests/data/lint_skip_list.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# check that comments work
xml_order
# check the white spaces are ignored
citations
6 changes: 6 additions & 0 deletions tests/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
CliTestCase,
PROJECT_TEMPLATES_DIR,
skip_if_environ,
TEST_DATA_DIR,
TEST_REPOS_DIR,
TEST_TOOLS_DIR,
)
Expand Down Expand Up @@ -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")

Expand Down
1 change: 0 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit cb2321b

Please sign in to comment.