Skip to content

Commit

Permalink
fix typing and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
mirpedrol committed Jul 24, 2024
1 parent a79a4f0 commit 2d2be38
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
11 changes: 5 additions & 6 deletions nf_core/components/nfcore_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def _get_included_components_in_chained_tests(self, main_nf_test: Union[Path, st

def get_inputs_from_main_nf(self) -> None:
"""Collect all inputs from the main.nf file."""
inputs = []
inputs: list[list | str] = []
with open(self.main_nf) as f:
data = f.read()
if self.component_type == "modules":
Expand All @@ -173,10 +173,10 @@ def get_inputs_from_main_nf(self) -> None:
# don't match anything inside comments or after "output:"
if "input:" not in data:
log.debug(f"Could not find any inputs in {self.main_nf}")
return inputs
return
input_data = data.split("input:")[1].split("output:")[0]
for line in input_data.split("\n"):
channel_elements = []
channel_elements: list[dict] = []
regex = r"(val|path)\s*(\(([^)]+)\)|\s*([^)\s,]+))"
matches = re.finditer(regex, line)
for _, match in enumerate(matches, start=1):
Expand All @@ -195,15 +195,14 @@ def get_inputs_from_main_nf(self) -> None:
# get input values from main.nf after "take:"
if "take:" not in data:
log.debug(f"Could not find any inputs in {self.main_nf}")
return inputs
return
# get all lines between "take" and "main" or "emit"
input_data = data.split("take:")[1].split("main:")[0].split("emit:")[0]
for line in input_data.split("\n"):
try:
inputs.append(line.split()[0])
except IndexError:
# Empty lines
pass
pass # Empty lines
log.debug(f"Found {len(inputs)} inputs in {self.main_nf}")
self.inputs = inputs

Expand Down
21 changes: 14 additions & 7 deletions nf_core/subworkflows/lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ def lint_subworkflow(self, swf, progress_bar, registry, local=False):

self.failed += [LintResult(swf, *s) for s in swf.failed]


def update_meta_yml_file(self, swf):
"""
Update the meta.yml file with the correct inputs and outputs
Expand All @@ -251,19 +250,29 @@ def update_meta_yml_file(self, swf):
# Compare inputs and add them if missing
if "input" in meta_yaml:
# Delete inputs from meta.yml which are not present in main.nf
meta_yaml_corrected["input"] = [input for input in meta_yaml["input"] if list(input.keys())[0] in swf.inputs]
meta_yaml_corrected["input"] = [
input for input in meta_yaml["input"] if list(input.keys())[0] in swf.inputs
]
# Obtain inputs from main.nf missing in meta.yml
inputs_correct = [list(input.keys())[0] for input in meta_yaml_corrected["input"] if list(input.keys())[0] in swf.inputs]
inputs_correct = [
list(input.keys())[0] for input in meta_yaml_corrected["input"] if list(input.keys())[0] in swf.inputs
]
inputs_missing = [input for input in swf.inputs if input not in inputs_correct]
# Add missing inputs to meta.yml
for missing_input in inputs_missing:
meta_yaml_corrected["input"].append({missing_input: {"description": ""}})

if "output" in meta_yaml:
# Delete outputs from meta.yml which are not present in main.nf
meta_yaml_corrected["output"] = [output for output in meta_yaml["output"] if list(output.keys())[0] in swf.outputs]
meta_yaml_corrected["output"] = [
output for output in meta_yaml["output"] if list(output.keys())[0] in swf.outputs
]
# Obtain output from main.nf missing in meta.yml
outputs_correct = [list(output.keys())[0] for output in meta_yaml_corrected["output"] if list(output.keys())[0] in swf.outputs]
outputs_correct = [
list(output.keys())[0]
for output in meta_yaml_corrected["output"]
if list(output.keys())[0] in swf.outputs
]
outputs_missing = [output for output in swf.outputs if output not in outputs_correct]
# Add missing inputs to meta.yml
for missing_output in outputs_missing:
Expand All @@ -274,5 +283,3 @@ def update_meta_yml_file(self, swf):
log.info(f"Updating {swf.meta_yml}")
yaml.dump(meta_yaml_corrected, fh)
run_prettier_on_file(fh.name)


1 change: 1 addition & 0 deletions nf_core/subworkflows/lint/meta_yml.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

log = logging.getLogger(__name__)


def meta_yml(subworkflow_lint_object, subworkflow):
"""
Lint a ``meta.yml`` file
Expand Down

0 comments on commit 2d2be38

Please sign in to comment.