Skip to content

Commit

Permalink
Merge pull request #2546 from mashehu/fix-swf-linting-error
Browse files Browse the repository at this point in the history
Fix swf test error
  • Loading branch information
mashehu authored Nov 29, 2023
2 parents ead61f4 + 4356351 commit 7f869b1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
1 change: 0 additions & 1 deletion nf_core/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,6 @@ def create_subworkflow(ctx, subworkflow, dir, author, force):
@click.pass_context
@click.argument("subworkflow", type=str, required=False, metavar="subworkflow name")
@click.option("-d", "--dir", type=click.Path(exists=True), default=".", metavar="<nf-core/modules directory>")
@click.option("-t", "--run-tests", is_flag=True, default=False, help="Run the test workflows")
@click.option("-p", "--no-prompts", is_flag=True, default=False, help="Use defaults without prompting")
@click.option("-u", "--update", is_flag=True, default=False, help="Update existing snapshots")
@click.option("-o", "--once", is_flag=True, default=False, help="Run tests only once. Don't check snapshot stability")
Expand Down
17 changes: 12 additions & 5 deletions nf_core/components/lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import os
from pathlib import Path

import rich
import rich.box
import rich.console
import rich.panel
from rich.markdown import Markdown
from rich.table import Table

Expand Down Expand Up @@ -209,7 +211,7 @@ def _print_results(self, show_passed=False, sort_by="test"):
self.failed.sort(key=operator.attrgetter(*sort_order))

# Find maximum module name length
max_name_len = 40
max_name_len = len(self.component_type[:-1] + " name")
for tests in [self.passed, self.warned, self.failed]:
try:
for lint_result in tests:
Expand Down Expand Up @@ -264,7 +266,7 @@ def format_result(test_results, table):
table = Table(style="yellow", box=rich.box.MINIMAL, pad_edge=False, border_style="dim")
table.add_column(f"{self.component_type[:-1].title()} name", width=max_name_len)
table.add_column("File path")
table.add_column("Test message")
table.add_column("Test message", overflow="fold")
table = format_result(self.warned, table)
console.print(
rich.panel.Panel(
Expand All @@ -278,10 +280,15 @@ def format_result(test_results, table):

# Table of failing tests
if len(self.failed) > 0:
table = Table(style="red", box=rich.box.MINIMAL, pad_edge=False, border_style="dim")
table = Table(
style="red",
box=rich.box.MINIMAL,
pad_edge=False,
border_style="dim",
)
table.add_column(f"{self.component_type[:-1].title()} name", width=max_name_len)
table.add_column("File path")
table.add_column("Test message")
table.add_column("Test message", overflow="fold")
table = format_result(self.failed, table)
console.print(
rich.panel.Panel(
Expand Down
13 changes: 10 additions & 3 deletions nf_core/components/nfcore_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import re
from pathlib import Path
from typing import Union

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -77,7 +78,7 @@ def __init__(
self.test_yml = None
self.test_main_nf = None

def _get_main_nf_tags(self, test_main_nf: str):
def _get_main_nf_tags(self, test_main_nf: Union[Path, str]):
"""Collect all tags from the main.nf.test file."""
tags = []
with open(test_main_nf, "r") as fh:
Expand All @@ -86,13 +87,19 @@ def _get_main_nf_tags(self, test_main_nf: str):
tags.append(line.strip().split()[1].strip('"'))
return tags

def _get_included_components(self, main_nf: str):
def _get_included_components(self, main_nf: Union[Path, str]):
"""Collect all included components from the main.nf file."""
included_components = []
with open(main_nf, "r") as fh:
for line in fh:
if line.strip().startswith("include"):
included_components.append(line.strip().split()[-1].split(self.org)[-1].split("main")[0].strip("/"))
# get tool/subtool or subworkflow name from include statement, can be in the form
#'../../../modules/nf-core/hisat2/align/main'
#'../bam_sort_stats_samtools/main'
#'../subworkflows/nf-core/bam_sort_stats_samtools/main'
component = line.strip().split()[-1].split(self.org)[-1].split("main")[0].strip("/")
component = component.replace("'../", "subworkflows/")
included_components.append(component)
return included_components

def get_inputs_from_main_nf(self):
Expand Down
1 change: 1 addition & 0 deletions nf_core/subworkflows/lint/subworkflow_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def subworkflow_tests(_, subworkflow: NFCoreComponent):
included_components = []
if subworkflow.main_nf.is_file():
included_components = subworkflow._get_included_components(subworkflow.main_nf)
log.debug(f"Required tags: {required_tags}")
missing_tags = []
for tag in required_tags + included_components:
if tag not in main_nf_tags:
Expand Down

0 comments on commit 7f869b1

Please sign in to comment.