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
Merged

Conversation

awgymer
Copy link
Contributor

@awgymer awgymer commented Mar 29, 2023

Arising from #2205

Current behaviour is to look for label declarations but only lint the first one occuring.
This PR aims to lint each label and check for any conflicts and the presence of 1 standard label.

Non-standard labels are currently not warned about.

PR checklist

  • This comment contains a description of changes (with reason)
  • CHANGELOG.md is updated
  • If you've fixed a bug or added code that should be tested, add tests!
  • Documentation in docs is updated

Aratz
Aratz previously requested changes Mar 29, 2023
Copy link
Contributor

@Aratz Aratz left a comment

Choose a reason for hiding this comment

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

Nice work! I left a few comments. You should probably add a test based on the scenario described in #2205 as well.

nf_core/modules/lint/main_nf.py Outdated Show resolved Hide resolved
nf_core/modules/lint/main_nf.py Outdated Show resolved Hide resolved
nf_core/modules/lint/main_nf.py Outdated Show resolved Hide resolved
nf_core/modules/lint/main_nf.py Outdated Show resolved Hide resolved
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.

@codecov
Copy link

codecov bot commented Apr 4, 2023

Codecov Report

Merging #2227 (18b6d1a) into dev (df60f0c) will increase coverage by 0.09%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##              dev    #2227      +/-   ##
==========================================
+ Coverage   73.09%   73.19%   +0.09%     
==========================================
  Files          77       77              
  Lines        8408     8423      +15     
==========================================
+ Hits         6146     6165      +19     
+ Misses       2262     2258       -4     
Impacted Files Coverage Δ
nf_core/modules/lint/main_nf.py 67.88% <100.00%> (+3.07%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@mirpedrol mirpedrol left a comment

Choose a reason for hiding this comment

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

LGTM! but agree with @fabianegli's comment, it would be good to put this code in a separate function check_labels() for example

@mirpedrol mirpedrol requested a review from Aratz April 20, 2023 07:41
Copy link
Contributor

@Aratz Aratz left a comment

Choose a reason for hiding this comment

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

I still think it would be good to add at least one test based on #2205 and I agree with @fabianegli that it would be good to extract this part of the code into it's own function (would make testing easier too!).

@awgymer
Copy link
Contributor Author

awgymer commented Apr 25, 2023

@mirpedrol I am going to try and write test(s) now but just wondering whether some of the warnings need to be "new" tests?

For example right now all these warnings go under process_standard_label (I've just extracted the parts with the warnings).

self.warned.append(
                    (
                        "process_standard_label",
                        f"Specified label appears to contain non-alphanumerics: {label}",
                        self.main_nf,
                    )
                )
                
 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 not specified", self.

I'm not sure whether non-standard process labels found is something that will break CI if people use them but also use the flag that makes all warnings failures?

@mirpedrol
Copy link
Member

I would say it's the expected behaviour to have get_biocontainer_tag as warnings and failing if someone uses --fail-warned 🤔

@awgymer awgymer requested review from Aratz and mirpedrol April 25, 2023 22:49
@awgymer
Copy link
Contributor Author

awgymer commented Apr 25, 2023

Test added in a kind of unique way as no previous tests check for individual failure/pass cases but this should!

Copy link
Contributor

@Aratz Aratz left a comment

Choose a reason for hiding this comment

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

Thanks for taking the time to add the tests, I only have one comment

nf_core/modules/lint/main_nf.py Show resolved Hide resolved


@pytest.mark.parametrize("lines,passed,warned,failed", PROCESS_LABEL_TEST_CASES)
def test_modules_lint_check_process_labels(self, lines, passed, warned, failed):
Copy link
Member

Choose a reason for hiding this comment

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

I think the test is not executed, should be added to test_modules.py, but I'm not sure how to do this when using the @pytest.mark.parametrize decorator.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So it turns out you were right but also because we use unittest.TestCase I cannot parametrize that function. I've just added the test cases as a loop in the test for now. I think it's OK like this for now (to make the release) but we might want to refactor that in future.

Copy link
Member

Choose a reason for hiding this comment

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

LGTM like this 🙂
#2226 could be the way to refactor this in the future

@awgymer awgymer dismissed Aratz’s stale review April 26, 2023 10:32

Changes made.

@awgymer awgymer merged commit 656e69d into nf-core:dev Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants