Skip to content

Commit

Permalink
Catch FileNotFoundError when looking for TODO comments
Browse files Browse the repository at this point in the history
Fixes #796
Also switched the log message from error to critical when halting linting due to failed tests.
  • Loading branch information
ewels committed Dec 3, 2020
1 parent 8ae626a commit 3be12d4
Showing 1 changed file with 28 additions and 42 deletions.
70 changes: 28 additions & 42 deletions nf_core/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def lint_pipeline(self, release_mode=False):
log.debug("Running lint test: {}".format(fun_name))
getattr(self, fun_name)()
if len(self.failed) > 0:
log.error("Found test failures in `{}`, halting lint run.".format(fun_name))
log.critical("Found test failures in `{}`, halting lint run.".format(fun_name))
break

def check_files_exist(self):
Expand Down Expand Up @@ -610,10 +610,7 @@ def check_nextflow_config(self):
)
else:
self.warned.append(
(
4,
"Config `manifest.version` should end in `dev`: `{}`".format(self.config["manifest.version"]),
)
(4, "Config `manifest.version` should end in `dev`: `{}`".format(self.config["manifest.version"]),)
)
elif "manifest.version" in self.config:
if "dev" in self.config["manifest.version"]:
Expand Down Expand Up @@ -672,19 +669,11 @@ def check_actions_branch_protection(self):
"PIPELINENAME", self.pipeline_name.lower()
)
if has_name and has_if and has_run:
self.passed.append(
(
5,
"GitHub Actions 'branch' workflow looks good: `{}`".format(fn),
)
)
self.passed.append((5, "GitHub Actions 'branch' workflow looks good: `{}`".format(fn),))
break
else:
self.failed.append(
(
5,
"Couldn't find GitHub Actions 'branch' check for PRs to master: `{}`".format(fn),
)
(5, "Couldn't find GitHub Actions 'branch' check for PRs to master: `{}`".format(fn),)
)

def check_actions_ci(self):
Expand All @@ -703,12 +692,7 @@ def check_actions_ci(self):
# NB: YAML dict key 'on' is evaluated to a Python dict key True
assert ciwf[True] == expected
except (AssertionError, KeyError, TypeError):
self.failed.append(
(
5,
"GitHub Actions CI is not triggered on expected events: `{}`".format(fn),
)
)
self.failed.append((5, "GitHub Actions CI is not triggered on expected events: `{}`".format(fn),))
else:
self.passed.append((5, "GitHub Actions CI is triggered on expected events: `{}`".format(fn)))

Expand All @@ -724,10 +708,7 @@ def check_actions_ci(self):
assert any([docker_build_cmd in step["run"] for step in steps if "run" in step.keys()])
except (AssertionError, KeyError, TypeError):
self.failed.append(
(
5,
"CI is not building the correct docker image. Should be: `{}`".format(docker_build_cmd),
)
(5, "CI is not building the correct docker image. Should be: `{}`".format(docker_build_cmd),)
)
else:
self.passed.append((5, "CI is building the correct docker image: `{}`".format(docker_build_cmd)))
Expand Down Expand Up @@ -1241,17 +1222,25 @@ def check_cookiecutter_strings(self):
num_files = 0
for fn in list_of_files:
num_files += 1
with io.open(fn, "r", encoding="latin1") as fh:
lnum = 0
for l in fh:
lnum += 1
cc_matches = re.findall(r"{{\s*cookiecutter[^}]*}}", l)
if len(cc_matches) > 0:
for cc_match in cc_matches:
self.failed.append(
(13, "Found a cookiecutter template string in `{}` L{}: {}".format(fn, lnum, cc_match))
)
num_matches += 1
try:
with io.open(fn, "r", encoding="latin1") as fh:
lnum = 0
for l in fh:
lnum += 1
cc_matches = re.findall(r"{{\s*cookiecutter[^}]*}}", l)
if len(cc_matches) > 0:
for cc_match in cc_matches:
self.failed.append(
(
13,
"Found a cookiecutter template string in `{}` L{}: {}".format(
fn, lnum, cc_match
),
)
)
num_matches += 1
except FileNotFoundError as e:
log.warn("`git ls-files` returned '{}' but could not open it!".format(fn))
if num_matches == 0:
self.passed.append((13, "Did not find any cookiecutter template strings ({} files)".format(num_files)))

Expand Down Expand Up @@ -1332,8 +1321,7 @@ def _s(some_list):
if len(self.passed) > 0 and show_passed:
table = Table(style="green", box=rich.box.ROUNDED)
table.add_column(
r"\[✔] {} Test{} Passed".format(len(self.passed), _s(self.passed)),
no_wrap=True,
r"\[✔] {} Test{} Passed".format(len(self.passed), _s(self.passed)), no_wrap=True,
)
table = format_result(self.passed, table)
console.print(table)
Expand All @@ -1349,8 +1337,7 @@ def _s(some_list):
if len(self.failed) > 0:
table = Table(style="red", box=rich.box.ROUNDED)
table.add_column(
r"\[✗] {} Test{} Failed".format(len(self.failed), _s(self.failed)),
no_wrap=True,
r"\[✗] {} Test{} Failed".format(len(self.failed), _s(self.failed)), no_wrap=True,
)
table = format_result(self.failed, table)
console.print(table)
Expand All @@ -1360,8 +1347,7 @@ def _s(some_list):
table = Table(box=rich.box.ROUNDED)
table.add_column("[bold green]LINT RESULTS SUMMARY".format(len(self.passed)), no_wrap=True)
table.add_row(
r"\[✔] {:>3} Test{} Passed".format(len(self.passed), _s(self.passed)),
style="green",
r"\[✔] {:>3} Test{} Passed".format(len(self.passed), _s(self.passed)), style="green",
)
table.add_row(r"\[!] {:>3} Test Warning{}".format(len(self.warned), _s(self.warned)), style="yellow")
table.add_row(r"\[✗] {:>3} Test{} Failed".format(len(self.failed), _s(self.failed)), style="red")
Expand Down

0 comments on commit 3be12d4

Please sign in to comment.