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

Add lint test to check existence of test profile #2478

Merged
merged 6 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions nf_core/lint/nextflow_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import os
import re
import subprocess
fa2k marked this conversation as resolved.
Show resolved Hide resolved

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -108,6 +109,11 @@ def nextflow_config(self):

lint:
nextflow_config: False

**The configuration should contain the following or the test will fail:**

* A ``test`` configuration profile should exist.

"""
passed = []
warned = []
Expand Down Expand Up @@ -312,4 +318,32 @@ def nextflow_config(self):
)
)

# Check for the availability of the "test" configuration profile by parsing nextflow.config
with open(os.path.join(self.wf_path, "nextflow.config"), "r") as f:
content = f.read()

# Remove comments
cleaned_content = re.sub(r"//.*", "", content)
cleaned_content = re.sub(r"/\*.*?\*/", "", content, flags=re.DOTALL)

match = re.search(r"\bprofiles\s*{", cleaned_content)
if not match:
failed.append("nextflow.config does not contain `profiles` scope, but `test` profile is required")
else:
# Extract profiles scope content and check for test profile
start = match.end()
end = start
brace_count = 1
while brace_count > 0 and end < len(content):
if cleaned_content[end] == "{":
brace_count += 1
elif cleaned_content[end] == "}":
brace_count -= 1
end += 1
profiles_content = cleaned_content[start : end - 1].strip()
if re.search(r"\btest\s*{", profiles_content):
passed.append("nextflow.config contains configuration profile `test`")
else:
failed.append("nextflow.config does not contain configuration profile `test`")

return {"passed": passed, "warned": warned, "failed": failed, "ignored": ignored}
20 changes: 20 additions & 0 deletions tests/lint/nextflow_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import os
import re

import nf_core.create
import nf_core.lint

Expand Down Expand Up @@ -33,3 +36,20 @@ def test_nextflow_config_dev_in_release_mode_failed(self):
result = lint_obj.nextflow_config()
assert len(result["failed"]) > 0
assert len(result["warned"]) == 0


def test_nextflow_config_missing_test_profile_failed(self):
"""Test failure if config file does not contain `test` profile."""
new_pipeline = self._make_pipeline_copy()
# Change the name of the test profile so there is no such profile
nf_conf_file = os.path.join(new_pipeline, "nextflow.config")
with open(nf_conf_file, "r") as f:
content = f.read()
fail_content = re.sub(r"\btest\b", "testfail", content)
with open(nf_conf_file, "w") as f:
f.write(fail_content)
lint_obj = nf_core.lint.PipelineLint(new_pipeline)
lint_obj._load_pipeline_config()
result = lint_obj.nextflow_config()
assert len(result["failed"]) > 0
assert len(result["warned"]) == 0
1 change: 1 addition & 0 deletions tests/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ def test_sphinx_md_files(self):
test_nextflow_config_bad_name_fail,
test_nextflow_config_dev_in_release_mode_failed,
test_nextflow_config_example_pass,
test_nextflow_config_missing_test_profile_failed,
)
from .lint.version_consistency import test_version_consistency

Expand Down
Loading