Skip to content

Commit

Permalink
[FIX]#838 Lint with missing Dockerfile (#881)
Browse files Browse the repository at this point in the history
- cookietemple does not crash anymore when a Dockerfile is missing
  • Loading branch information
Imipenem committed Feb 20, 2022
1 parent fcc999a commit a55a533
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions cookietemple/lint/template_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,21 @@ def lint_cookietemple_config(self):

def check_docker(self):
"""
Checks that Dockerfile contains the string ``FROM``
Checks that Dockerfile exists and contains the string ``FROM``
"""
fn = os.path.join(self.path, "Dockerfile")
with open(fn, encoding="utf-8") as fh:
content = fh.read()

# Implicitly also checks if empty.
if "FROM " in content:
self.passed.append(("general-2", "Dockerfile check passed"))
self.dockerfile = [line.strip() for line in content.splitlines()]
return

self.failed.append((2, "Dockerfile check failed"))
if os.path.isfile(fn):
with open(fn, encoding="utf-8") as fh:
content = fh.read()
# Implicitly also checks if empty.
if "FROM" in content:
self.passed.append(("general-2", "Dockerfile check passed"))
self.dockerfile = [line.strip() for line in content.splitlines()]
return
else:
self.failed.append(("general-2", "Dockerfile check failed"))
else:
self.failed.append(("general-2", "Dockerfile check failed"))

def check_cookietemple_todos(self) -> None:
"""
Expand Down Expand Up @@ -346,7 +348,7 @@ def files_exist_linting(
for files in files_fail:
if not any([os.path.isfile(pf(self, f)) for f in files]):
all_exists = False
self.failed.append(("{handle}-1", f"File not found: {self._wrap_quotes(files)}"))
self.failed.append((f"{handle}-1", f"File not found: {self._wrap_quotes(files)}"))
# flag that indiactes whether all required files exist or not
if all_exists:
# called linting from a specific template linter
Expand Down

0 comments on commit a55a533

Please sign in to comment.