-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #861 from KevinMenden/merge-markers
Add lint test for merge markers
- Loading branch information
Showing
6 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
merge_markers | ||
============== | ||
|
||
.. automethod:: nf_core.lint.PipelineLint.merge_markers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env python | ||
|
||
import logging | ||
import os | ||
import io | ||
import fnmatch | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def merge_markers(self): | ||
"""Check for remaining merge markers. | ||
This test looks for remaining merge markers in the code, e.g.: | ||
>>>>>>> or <<<<<<< | ||
""" | ||
passed = [] | ||
failed = [] | ||
|
||
ignore = [".git"] | ||
if os.path.isfile(os.path.join(self.wf_path, ".gitignore")): | ||
with io.open(os.path.join(self.wf_path, ".gitignore"), "rt", encoding="latin1") as fh: | ||
for l in fh: | ||
ignore.append(os.path.basename(l.strip().rstrip("/"))) | ||
for root, dirs, files in os.walk(self.wf_path): | ||
# Ignore files | ||
for i in ignore: | ||
dirs = [d for d in dirs if not fnmatch.fnmatch(os.path.join(root, d), i)] | ||
files = [f for f in files if not fnmatch.fnmatch(os.path.join(root, f), i)] | ||
for fname in files: | ||
try: | ||
with io.open(os.path.join(root, fname), "rt", encoding="latin1") as fh: | ||
for l in fh: | ||
if ">>>>>>>" in l: | ||
failed.append(f"Merge marker in `{fname}`: {l}") | ||
if "<<<<<<<" in l: | ||
failed.append(f"Merge marker in `{fname}`: {l}") | ||
except FileNotFoundError: | ||
log.debug(f"Could not open file {fname} in merge_markers lint test") | ||
if len(failed) == 0: | ||
passed.append("No merge markers found in pipeline files") | ||
return {"passed": passed, "failed": failed} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
import yaml | ||
import nf_core.lint | ||
|
||
|
||
def test_merge_markers_found(self): | ||
"""Missing 'jobs' field should result in failure""" | ||
new_pipeline = self._make_pipeline_copy() | ||
|
||
with open(os.path.join(new_pipeline, "main.nf"), "r") as fh: | ||
main_nf_content = fh.read() | ||
main_nf_content = ">>>>>>>\n" + main_nf_content | ||
with open(os.path.join(new_pipeline, "main.nf"), "w") as fh: | ||
fh.write(main_nf_content) | ||
|
||
lint_obj = nf_core.lint.PipelineLint(new_pipeline) | ||
lint_obj._load() | ||
|
||
results = lint_obj.merge_markers() | ||
assert len(results["failed"]) > 0 | ||
assert len(results["passed"]) == 0 | ||
assert "Merge marker in `main.nf`: >>>>>>>\n" == results["failed"][0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters