From cfae735856972c37514407c46442a99ee6c042b2 Mon Sep 17 00:00:00 2001 From: Phil Ewels Date: Thu, 3 Dec 2020 11:06:10 +0100 Subject: [PATCH 1/2] Catch FileNotFoundError when looking for TODO comments Fixes nf-core/tools#796 Also switched the log message from error to critical when halting linting due to failed tests. --- nf_core/lint.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/nf_core/lint.py b/nf_core/lint.py index 74c5b170a..e057bc38b 100755 --- a/nf_core/lint.py +++ b/nf_core/lint.py @@ -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): @@ -1241,17 +1241,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))) From 80e6fddaf271afcb8b86c4d62dd529031ed1f1d2 Mon Sep 17 00:00:00 2001 From: Phil Ewels Date: Thu, 3 Dec 2020 11:27:11 +0100 Subject: [PATCH 2/2] Changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4726acaad..f583d4f5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ ### Linting +* Fix linting crash when a file deleted but not yet staged in git [[#796](https://github.com/nf-core/tools/issues/796)] + ### Other ## [v1.12 - Mercury Weasel](https://github.com/nf-core/tools/releases/tag/1.12) - [2020-11-19]