Skip to content

Commit

Permalink
Merge pull request #804 from ewels/master
Browse files Browse the repository at this point in the history
Catch FileNotFoundError when looking for TODO comments
  • Loading branch information
ewels authored Dec 3, 2020
2 parents 8ae626a + 80e6fdd commit 92fce9d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
32 changes: 20 additions & 12 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 @@ -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)))

Expand Down

0 comments on commit 92fce9d

Please sign in to comment.