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

Catch FileNotFoundError when looking for TODO comments #804

Merged
merged 2 commits into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
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