-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option --fix
to update the meta.yml
file of subworkflows.
#3077
base: dev
Are you sure you want to change the base?
Changes from all commits
297735e
a79a4f0
2d2be38
f31e6b5
eb58583
ebfbd98
0447d1a
200ae85
0e3a35b
23c2612
b41e64c
b249b13
a2ffa44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,7 +5,7 @@ | |||||
import logging | ||||||
import re | ||||||
from pathlib import Path | ||||||
from typing import List, Optional, Tuple, Union | ||||||
from typing import Any, List, Optional, Tuple, Union | ||||||
|
||||||
log = logging.getLogger(__name__) | ||||||
|
||||||
|
@@ -41,6 +41,7 @@ def __init__( | |||||
remote_component (bool): Whether the module is to be treated as a | ||||||
nf-core or local component | ||||||
""" | ||||||
self.component_type = component_type | ||||||
self.component_name = component_name | ||||||
self.repo_url = repo_url | ||||||
self.component_dir = component_dir | ||||||
|
@@ -170,65 +171,95 @@ 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: list[list[dict[str, dict[str, str]]]] = [] | ||||||
inputs: Any = [] # Can be 'list[list[dict[str, dict[str, str]]]]' or 'list[str]' | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This wasn't working, because we append one of the types later on :( I learnt about the overload decorator, but in our case it's not a function. |
||||||
with open(self.main_nf) as f: | ||||||
data = f.read() | ||||||
# get input values from main.nf after "input:", which can be formatted as tuple val(foo) path(bar) or val foo or val bar or path bar or path foo | ||||||
# regex matches: | ||||||
# val(foo) | ||||||
# path(bar) | ||||||
# val foo | ||||||
# val bar | ||||||
# path bar | ||||||
# path foo | ||||||
# 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 | ||||||
input_data = data.split("input:")[1].split("output:")[0] | ||||||
for line in input_data.split("\n"): | ||||||
channel_elements: list[dict[str, dict[str, str]]] = [] | ||||||
regex = r"(val|path)\s*(\(([^)]+)\)|\s*([^)\s,]+))" | ||||||
matches = re.finditer(regex, line) | ||||||
for _, match in enumerate(matches, start=1): | ||||||
input_val = None | ||||||
if match.group(3): | ||||||
input_val = match.group(3).split(",")[0] # handle `files, stageAs: "inputs/*"` cases | ||||||
elif match.group(4): | ||||||
input_val = match.group(4).split(",")[0] # handle `files, stageAs: "inputs/*"` cases | ||||||
if input_val: | ||||||
channel_elements.append({input_val: {}}) | ||||||
if len(channel_elements) > 0: | ||||||
inputs.append(channel_elements) | ||||||
log.debug(f"Found {len(inputs)} inputs in {self.main_nf}") | ||||||
self.inputs = inputs | ||||||
if self.component_type == "modules": | ||||||
# get input values from main.nf after "input:", which can be formatted as tuple val(foo) path(bar) or val foo or val bar or path bar or path foo | ||||||
# regex matches: | ||||||
# val(foo) | ||||||
# path(bar) | ||||||
# val foo | ||||||
# val bar | ||||||
# path bar | ||||||
# path foo | ||||||
# 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 | ||||||
input_data = data.split("input:")[1].split("output:")[0] | ||||||
for line in input_data.split("\n"): | ||||||
channel_elements: Any = [] | ||||||
regex = r"(val|path)\s*(\(([^)]+)\)|\s*([^)\s,]+))" | ||||||
matches = re.finditer(regex, line) | ||||||
for _, match in enumerate(matches, start=1): | ||||||
input_val = None | ||||||
if match.group(3): | ||||||
input_val = match.group(3).split(",")[0] # handle `files, stageAs: "inputs/*"` cases | ||||||
elif match.group(4): | ||||||
input_val = match.group(4).split(",")[0] # handle `files, stageAs: "inputs/*"` cases | ||||||
if input_val: | ||||||
channel_elements.append({input_val: {}}) | ||||||
if len(channel_elements) > 0: | ||||||
inputs.append(channel_elements) | ||||||
log.debug(f"Found {len(inputs)} inputs in {self.main_nf}") | ||||||
self.inputs = inputs | ||||||
elif self.component_type == "subworkflows": | ||||||
# 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 | ||||||
# 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: | ||||||
pass # Empty lines | ||||||
log.debug(f"Found {len(inputs)} inputs in {self.main_nf}") | ||||||
self.inputs = inputs | ||||||
|
||||||
def get_outputs_from_main_nf(self): | ||||||
outputs = [] | ||||||
with open(self.main_nf) as f: | ||||||
data = f.read() | ||||||
# get output values from main.nf after "output:". the names are always after "emit:" | ||||||
if "output:" not in data: | ||||||
log.debug(f"Could not find any outputs in {self.main_nf}") | ||||||
return outputs | ||||||
output_data = data.split("output:")[1].split("when:")[0] | ||||||
regex_emit = r"emit:\s*([^)\s,]+)" | ||||||
regex_elements = r"(val|path|env|stdout)\s*(\(([^)]+)\)|\s*([^)\s,]+))" | ||||||
for line in output_data.split("\n"): | ||||||
match_emit = re.search(regex_emit, line) | ||||||
matches_elements = re.finditer(regex_elements, line) | ||||||
if not match_emit: | ||||||
continue | ||||||
output_channel = {match_emit.group(1): []} | ||||||
for _, match_element in enumerate(matches_elements, start=1): | ||||||
output_val = None | ||||||
if match_element.group(3): | ||||||
output_val = match_element.group(3) | ||||||
elif match_element.group(4): | ||||||
output_val = match_element.group(4) | ||||||
if output_val: | ||||||
output_val = output_val.strip("'").strip('"') # remove quotes | ||||||
output_channel[match_emit.group(1)].append({output_val: {}}) | ||||||
outputs.append(output_channel) | ||||||
log.debug(f"Found {len(outputs)} outputs in {self.main_nf}") | ||||||
self.outputs = outputs | ||||||
if self.component_type == "modules": | ||||||
# get output values from main.nf after "output:". the names are always after "emit:" | ||||||
if "output:" not in data: | ||||||
log.debug(f"Could not find any outputs in {self.main_nf}") | ||||||
return outputs | ||||||
output_data = data.split("output:")[1].split("when:")[0] | ||||||
regex_emit = r"emit:\s*([^)\s,]+)" | ||||||
regex_elements = r"(val|path|env|stdout)\s*(\(([^)]+)\)|\s*([^)\s,]+))" | ||||||
for line in output_data.split("\n"): | ||||||
match_emit = re.search(regex_emit, line) | ||||||
matches_elements = re.finditer(regex_elements, line) | ||||||
if not match_emit: | ||||||
continue | ||||||
output_channel = {match_emit.group(1): []} | ||||||
for _, match_element in enumerate(matches_elements, start=1): | ||||||
output_val = None | ||||||
if match_element.group(3): | ||||||
output_val = match_element.group(3) | ||||||
elif match_element.group(4): | ||||||
output_val = match_element.group(4) | ||||||
if output_val: | ||||||
output_val = output_val.strip("'").strip('"') # remove quotes | ||||||
output_channel[match_emit.group(1)].append({output_val: {}}) | ||||||
outputs.append(output_channel) | ||||||
log.debug(f"Found {len(outputs)} outputs in {self.main_nf}") | ||||||
self.outputs = outputs | ||||||
elif self.component_type == "subworkflows": | ||||||
# get output values from main.nf after "emit:". Can be named outputs or not. | ||||||
if "emit:" not in data: | ||||||
log.debug(f"Could not find any outputs in {self.main_nf}") | ||||||
return outputs | ||||||
output_data = data.split("emit:")[1].split("}")[0] | ||||||
for line in output_data.split("\n"): | ||||||
try: | ||||||
outputs.append(line.split("=")[0].split()[0]) | ||||||
except IndexError: | ||||||
# Empty lines | ||||||
pass | ||||||
log.debug(f"Found {len(outputs)} outputs in {self.main_nf}") | ||||||
self.outputs = outputs |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because this in the following is basically the same, like the inputs table, can't we just have a generic
generate_params_table
function to reduce code duplication?