From 2d2be3877fe04dbc4ddb80cf525be0db13083740 Mon Sep 17 00:00:00 2001 From: mirpedrol Date: Wed, 24 Jul 2024 16:03:33 +0200 Subject: [PATCH] fix typing and linting --- nf_core/components/nfcore_component.py | 11 +++++------ nf_core/subworkflows/lint/__init__.py | 21 ++++++++++++++------- nf_core/subworkflows/lint/meta_yml.py | 1 + 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/nf_core/components/nfcore_component.py b/nf_core/components/nfcore_component.py index db817db905..39a4ba51f4 100644 --- a/nf_core/components/nfcore_component.py +++ b/nf_core/components/nfcore_component.py @@ -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": @@ -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): @@ -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 diff --git a/nf_core/subworkflows/lint/__init__.py b/nf_core/subworkflows/lint/__init__.py index e0911e5bd9..22025d2a07 100644 --- a/nf_core/subworkflows/lint/__init__.py +++ b/nf_core/subworkflows/lint/__init__.py @@ -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 @@ -251,9 +250,13 @@ 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: @@ -261,9 +264,15 @@ def update_meta_yml_file(self, swf): 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: @@ -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) - - diff --git a/nf_core/subworkflows/lint/meta_yml.py b/nf_core/subworkflows/lint/meta_yml.py index 633061e247..be282bc453 100644 --- a/nf_core/subworkflows/lint/meta_yml.py +++ b/nf_core/subworkflows/lint/meta_yml.py @@ -9,6 +9,7 @@ log = logging.getLogger(__name__) + def meta_yml(subworkflow_lint_object, subworkflow): """ Lint a ``meta.yml`` file