Skip to content

Commit

Permalink
Differentiate between empty and missing files.
Browse files Browse the repository at this point in the history
  • Loading branch information
jendrikseipp authored Dec 30, 2023
1 parent 4fb5b77 commit b4d89ae
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions lab/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,22 +176,21 @@ def get_content(path):
try:
content_cache[path] = path.read_text()
except FileNotFoundError:
content_cache[path] = ""
content_cache[path] = None
return content_cache[path]

for filename, file_parser in self.file_parsers.items():
# If filename is absolute, path is set to filename.
path = run_dir / filename
content = get_content(path)
if not content and any(
pattern.required for pattern in file_parser.patterns
):
logging.error(
f'File "{path}", required by some pattern(s), is missing.'
)
file_parser.search_patterns(str(path), content, props)
if content is None:
if any(pattern.required for pattern in file_parser.patterns):
logging.error(f'Required file "{path}" is missing.')
else:
file_parser.search_patterns(str(path), content, props)

for function in self.functions:
path = run_dir / function.filename
content = get_content(path)
# Call function with empty string if file is missing.
content = get_content(path) or ""
function.function(content, props)

0 comments on commit b4d89ae

Please sign in to comment.