Skip to content
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

Improve process label linting #2227

Merged
merged 10 commits into from
Apr 26, 2023
50 changes: 39 additions & 11 deletions nf_core/modules/lint/main_nf.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,25 +236,53 @@ def check_process_section(self, lines, fix_version, progress_bar):

# Check that process labels are correct
Aratz marked this conversation as resolved.
Show resolved Hide resolved
correct_process_labels = ["process_single", "process_low", "process_medium", "process_high", "process_long"]
process_label = [l for l in lines if l.lstrip().startswith("label")]
if len(process_label) > 0:
try:
process_label = re.search("process_[A-Za-z]+", process_label[0]).group(0)
except AttributeError:
process_label = re.search("'([A-Za-z_-]+)'", process_label[0]).group(0)
finally:
if not process_label in correct_process_labels:
all_labels = [l for l in lines if l.lstrip().startswith("label ")]
Copy link
Contributor

@fabianegli fabianegli Mar 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a good idea to extract this into a function. Something like get_process_label. That would make things more readable and testable. And also have tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole method is now getting quite bloated. If the code here is accepted then I think a next step could be to split out the whole label section rather than just splitting out the list comprehension. Similarly it may be worth considering splitting out the container parsing part.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was then less clear than I hoped. I meant taking out the whole label selection as you propose - not just a list comprehension.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I think it would be ideal to do it as part of this PR.

bad_labels = []
awgymer marked this conversation as resolved.
Show resolved Hide resolved
good_labels = []
if len(all_labels) > 0:
for label in all_labels:
try:
label = re.match("^label\s+([a-zA-Z0-9_-]+)", label).group(1)
except AttributeError:
self.warned.append(
(
"process_standard_label",
f"Process label ({process_label}) is not among standard labels: `{'`,`'.join(correct_process_labels)}`",
f"Specified label appears to contain non-alphanumerics: {label}",
self.main_nf,
)
)
continue
if label not in correct_process_labels:
bad_labels.append(label)
else:
self.passed.append(("process_standard_label", "Correct process label", self.main_nf))
good_labels.append(label)
if len(good_labels) > 1:
self.warned.append(
(
"process_standard_label",
f"Conflicting process labels found: `{'`,`'.join(good_labels)}`",
self.main_nf,
)
)
elif len(good_labels) == 1:
self.passed.append(("process_standard_label", "Correct process label", self.main_nf))
else:
self.warned.append(("process_standard_label", "Standard process label not found", self.main_nf))
if len(bad_labels) > 0:
self.warned.append(
("process_standard_label", f"Non-standard labels found: `{'`,`'.join(good_labels)}`", self.main_nf)
)
if len(all_labels) > len(set(all_labels)):
self.warned.append(
(
"process_standard_label",
f"Duplicate labels found: `{'`,`'.join(sorted(all_labels))}`",
self.main_nf,
)
)

else:
self.warned.append(("process_standard_label", "Process label unspecified", self.main_nf))
self.warned.append(("process_standard_label", "Process label not specified", self.main_nf))
for i, l in enumerate(lines):
url = None
l = l.strip(" '\"")
Expand Down